forlatlon0.f


c     read gh##0
C      cut data during course change dhead>10
c
C      iflg:changing course=1, first data of one line=2, on line=0
c      no:changing course = 0
c
c      data read gh##0
c
c     **** data ****
c     iyr:Year, jdy:Julian day, min:time(GMT in minutes),
c     alat(latitude TKY deg), alon(longitude TKY deg),
c     spd:speed, hg:course(clockwise from North), 
c     idpc:corrected depth, mgt:total magnetic force,
c     mga:magnetic anomaly, gr:gravity reading, gt1:absolute gravity value,
c     ga:free-air anomaly
c
      common /data2/iflg(30000),jdy(30000),min(30000)
      common /data3/hdg(30000),spd(30000)
      common /data4/gto(30000),alt(30000),ga(30000)
      common /data9/jnum
c
      dimension iyr(30000),aln(30000),idp(30000),mgt(30000)
      dimension mga(30000),gr(30000)
c
      open(10,file='H:\Myhome\gh90a.datam0',status='old')
      open(20,file='H:\Myhome\gh90a.datas01')
c
      theta=10
      i=0
    1 continue
         i=i+1
         read(10,*,end=99) iyr(i),jdy(i),min(i),alt(i),aln(i),
     +   spd(i),hdg(i),idp(i),mgt(i),mga(i),
     +   gr(i),gto(i),ga(i)
         go to 1
   99 close(10)
      jnum=i
c
      min00=jdy(1)*1440+min(1)
      iflg(1)=2
      do 11 j=2, jnum
       min1=jdy(j)*1440+min(j)
       jd=min1-min00
          if(jd.eq.1) then
           iflg(j)=0
          else
           iflg(j)=2
          end if
       min00=min1
   11 continue
      write(6,*) j,iflg(j)
c
      call hensin(theta)
c
      no=0
      mo=0
      do 10 k=1, jnum
         if(iflg(k).eq.1) then
          no=0
          write(20,207) no,iyr(k),jdy(k),min(k),alt(k),aln(k),
     +                spd(k),hdg(k),idp(k),mgt(k),mga(k),
     +                gr(k),gto(k),ga(k),iflg(k)
         go to 10
         end if
         no=mo+1
         write(20,207) no,iyr(k),jdy(k),min(k),alt(k),aln(k),
     +         spd(k),hdg(k),idp(k),mgt(k),mga(k),
     +         gr(k),gto(k),ga(k),iflg(k)
         mo=no
   10 continue
      close(20)
c     for gh90
c 205 format(i3,i4,i5,f10.5,f10.5,f6.2,f6.1,i6,i6,i6,f7.1,f9.1,f7.1)
  205 format(i2,i4,i5,f10.5,f11.5,f6.2,f6.1,i6,i6,i6,f8.1,f10.1,f8.1)
c     for gh894
c 205 format(i3,i4,i5,f9.5,f10.5,f6.2,f6.1,i6,i6,i6,f7.1,f9.1,f7.1)
  206 format(i3,i4,i5,f10.5,f10.5,f6.2,f6.1,i6,i6,i6,f8.1,f10.1,f8.1,i2)
  207 format(i7,i3,i4,i5,f10.5,f10.5,f6.2,f6.1,i6,i6,i6,f8.1,
     +   f10.1,f8.1,i2)
      stop
      end
c--------------------------------------------------------
      subroutine hensin(theta)
c                                    hensin check
c--------------------------------------------------------
      common /data2/iflg(30000),jdy(30000),min(30000)
      common /data3/hdg(30000),spd(30000)
      common /data9/jnum
c
      do 10 j=2, jnum
       dhg0=hdg(j)-hdg(j-1)
       dhg=abs(dhg0)
c
       if(dhg0.ge.300 .or. dhg0.le.-300) then
          if(dhg0.lt.0) then
             head=hdg(j)+360
          else
             head=hdg(j)-360
          end if
           dhg0=head-hdg(j-1)
           dhg=abs(dhg0)
       end if
c
          if(iflg(j).eq.0 .and. dhg.ge.theta) iflg(j)=1
   10 continue
c
      return
      end