c      PROGRAM 

            
      parameter (maxlevel=30000, 
     *maxnumcast=10000000)

      
      character*2  cc

      character*4 typdata

      dimension tem(maxlevel),sal(maxlevel)
      dimension den(maxlevel),z(maxlevel)

      integer*4 icrudet(maxlevel),icrudes(maxlevel)

      dimension stdt1(maxlevel),stds1(maxlevel)
      dimension stdt2(maxlevel),stds2(maxlevel)

      character*100 platname


      integer*4 ifladen(maxlevel)
      integer*4 iflagrat(maxlevel)
      integer*4 iflagras(maxlevel)

c##############################################     

 
C// description of the variables

c nwrite 	 profile sequential number
c typdata 	 data type (CTD, OSD, PFL)
c nodcid 	 a unique profile ID# 
c cc 		 NODC country code
c icruise 	 NODC cruise code
c iyear 	 year of the observation
c month 	 month of the observation
c iday 	 	 day of the observation
c time 	 	 time of the observation
c rlat 	 	 Latitude [-90 90]
c rlon 	 	 Longitude [-180 180]
c levels 	 number of observed levels
c zfirst 	 uppermost observed level
c zlast 	 deepest observed level
c gebcodepth 	 Ocean bottom depth from GEBCO digital bathymetry

c platname 	 platform(ship) name

c z(k)		sampled depths
c tem(k)	observed temperatures
c sal(k)	observed salinities
c den(k)	potential densities (reference pressure 0 dbar)

c icrudet(k)	crude range flags for temperature
c icrudes(k)	crude range flags for salinity
c iflagratk)	flags for acceptable temperature veritical gradient check
c iflagras(k)	flags for acceptable salinity    vertical gradient check
c ifladen(k)	flags for acceptable density inversion

c!!! (for ALL flags: 0 - good value; 1 - bad/suspicious value) !!!

c stdt1(k)	temperature deviation from the mean (in standard deviations) in the depth layer
c stdt2(k)	temperature deviation from the mean (in standard deviations) in the density layer
c stds1(k)	salinity deviation from the mean (in standard deviations) in the depth layer
c stds2(k)	salinity deviation from the mean (in standard deviations) in the density layer



      nall=0     

      open(21,file='001_CTDOSDPFLfl5',status='old')

      do 50 ij=1,maxnumcast

      
c//////////// HEADER_1     
      read(21,100,end=4) nwrite,typdata,
     *nodcid,cc,icruise,iyear,month,iday,time,
     *rlat,rlon,
     *levels,
     *zfirst,zlast,gebcodepth

c//////////// HEADER_2
      read(21,101)platname

  
c//////////// DATA on observed levels
      do k=1,levels

      read(21,102)
     *z(k),tem(k),sal(k),den(k),
     *icrudet(k),icrudes(k),
     *iflagrat(k),iflagras(k),ifladen(k),
     *stdt1(k),stdt2(k),stds1(k),stds2(k)

      end do

      nall=nall+1

50    continue !- End of MAIN LOOP
            
 4    continue !- EXIT 

      close(21)

      write(6,*)'Read completed: Number of profiles is ',nall


C///////////////////////////////////////////// data formats

100   format(i10,1x,a4,1x,
     *i8,1x,a2,i8,1x,i4,1x,i2,1x,i2,1x,f6.2,
     *2f10.3,
     *1x,i5,3f8.1,i5)

101   format(a100)

102   format(f8.1,3f9.4,5(1x,i1),4f7.1)

      stop
      end



