cr80selmag.f


c     read CR80
c     **** Header ****
c     line-1
c     j1:record type, j2:"1" for No.1 record, cname:Cruise identifer
c     iy:Survey departure year, iday:survey departure day(Julian day)
c     ports:port of departure, jy:Survey arrival year, 
c     jday:survey arrival day(Julian day),datid:Available data identifer
c     line-2
c     j3:record type, j4:"2" for No.2 record, magref:Magnetic reference field(e.g., IGRF90)
c     gref1:gravity reference field(e.g., IAG1967), gref2:gravity reference system(e.g., IGSN71)
c     ky:year at gravity base station, kday:Julian day at gravity base station, 
c     kgbase:absolute gravity base(*0.1mgal),kgread:gravity reading,kgrate:drift rate(*0.01/day)
c     line-3 & 4
c     j5:record type, j6:"2" for No.2 record, magref:Magnetic reference field(e.g., IGRF90)
c     gref1:gravity reference field(e.g., IAG1967), gref2:gravity reference system(e.g., IGSN71)
c     ky:year at gravity base station, kday:Julian day at gravity base station, 
c     kgbase:absolute gravity base(*0.1mgal),kgread:gravity reading,kgrate:drift rate(*0.01/day)
c
      character cname*8,ports*28,porta*28,datid*4,magref*38,gref1*9
      character gref2*8
      character mflg*1,kf
      open(10,file='GH802.DATA',status='old')
      open(20,file='gh802.data0')
      open(25,file='gh802.head')
c
      read(10,200) j1,j2,cname,iy,iday,ports,jy,jday,porta,datid
  200  format(i1,i1,a8,i2,i3,a28,i2,i3,a28,a4)    
      read(10,201) j3,j4,magref,gref1,gref2,ky,kday,kgbase,kgread,kgrate
  201  format(i1,i1,a38,a9,a8,i2,i3,i7,i6,i5)    
      read(10,202) j5,j6,j7,k1,kf,k2,kf,k3,kf,k4,kf,k5,kf,
     + k6,kf,k7,kf,k8,kf,k9,kf,
     + k10,kf,k11,kf,k12,kf,k13,kf,k14,kf,k15,kf
      read(10,202) j5,j6,j7,k1,kf,k2,kf,k3,kf,k4,kf,k5,kf,
     + k6,kf,k7,kf,k8,kf,k9,kf,
     + k10,kf,k11,kf,k12,kf,k13,kf,k14,kf,k15,kf
  202  format(i2,i1,i2,1x,i4,a1,i4,a1,i4,a1,i4,a1,
     +  i4,a1,i4,a1,i4,a1,i4,a1,i4,a1,i4,a1,i4,a1,i4,a1,i4,a1,
     +  i4,a1,i4,a1)
      write(25,203) cname,iy,iday,jy,jday,gref1,gref2
      write(6,203) cname,iy,iday,jy,jday,gref1,gref2
  203  format(a8,1x,i2,i3,1x,i2,i3,a9,a8)
c
c      data read CR80-2
c
c     **** data ****
c     idum:record type, iyr:Year, jdy:Julian day, min:time(GMT in minutes)
c     ispd:speed, icrs:course(clockwise from North), idpu:uncorrected depth,
c     idpc:corrected depth, idcc:mathews zone code, mgt:total magnetic force,
c     mga:magnetic anomaly, igrr:gravity reading, igrt:absolute gravity value,
c     igra:free-air anomaly
c
    1 continue
      read(10,120,end=99) idum,iyr,jdy,min,mflg,lat,lon,mflg,ispd,icrs,
     + mflg,idpu,idpc,idcc,mflg,mgt,mga,mflg,igrr,igrt,igra
  120  format(i1,i2,i3,i4,a1,i8,i9,a1,2i4,a1,2i5,i2,a1,2i5,a1,i6,i7,i5)
       write(6,*) iyr,jdy,min
c
      if(lat.eq.99999999 .or. lon.eq.999999999) go to 1
      if(mgt.eq.99999) go to 1
c     emag=abs(mga)
c     if(emag.ge.2500) then
c        mga=99999
c        mgt=99999
c     end if
c
      ga=float(igra)/10
      gr=float(igrr)/10
      gt1=float(igrt)/10
      hg=float(icrs)/10
      spd=float(ispd)/100
      alat=float(lat)/100000
      alon=float(lon)/100000
c
      write(20,205) iyr,jdy,min,alat,alon,spd,hg,idpc,mgt,mga,gr,gt1,ga
c
      go to 1
   99 continue
      close(10)
      close(20)
      close(25)
  205 format(i2,i4,i5,f10.5,f11.5,f6.2,f6.1,i6,i6,i6,f8.1,f10.1,f8.1)
      stop
      end