c--------( PCHKDV : plot GS Mag. Diurnal Var. for check )--------
      parameter (ras=(2.54/300.))
      character*80 wdr, flog, fgst, fnam
      character label*28, str*40
c
      call premsg('PCHKDV : plot GS Mag. Diurnal Var. for check')
      call opnpin()
      ldr = lwkdir(50,wdr) + 1
      flog = wdr
      fgst = wdr
      fnam = wdr
      call gparma('Enter LOG filename ==> ', 81-ldr, flog(ldr:80))
      call gparma('Enter GS Mag. data filename ==> ',
     *            81-ldr, fgst(ldr:80))
      open(1,file=fgst,status='old')
      call gparma('Enter Output PS filename    ==> ',
     *            81-ldr, fnam(ldr:80))
      call clspin()
      if(fnam(ldr:ldr).eq.' ') fnam(1:1) = char(0)
      if (fnam(80:80).ne.' ') call abendm('too long filename')
      write(6,'(a)') '----------------------------------------'
      write(6,'(a)') 'PCHKDV : plot GS Mag. Diurnal Var. for check'
      write(6,'(a,a)') ' GSmag data filename : ', fgst(1:lrtrim(fgst))
      write(6,'(a,a)') ' Output PS filename  : ', fnam(1:lrtrim(fnam))
      call psopn(fnam, 'A4L')
c
      kend = 0
      mbase = 0
      jymd = 0
      kst = 0
      call plots(2.0, 1.5)
      call lstyle('T', 0.4, 0., 0, -999)
      irow = 5
    1 read(1,'(a)',end=4) str
      if (str(1:1).ne.'/') goto 3
      if (str(1:5).ne.'/base' .and.  str(1:5).ne.'/Base') goto 2
      read(str(7:40),*) base
      if (base.lt.2000000.) base = base * 10.
      mbase = ifix(base)
      goto 5
    2 if (str(1:5).ne.'/date' .and. str(1:5).ne.'/Date') goto 1
      read(str(7:40),*) jymd
      goto 5
    3 read(str,'(3i2,1x,i6)') jh,jm,js, mg
      jn = jh*3600 + jm*60 + js
      mv = mg - mbase
      m2 = mv / 250
      m1 = mv - m2*250
      if (mv.lt.0) then
        m2 = m2 - 1
        m1 = m1 + 249
      endif
      if (kst.eq.0) then
        irow = irow - 1
        if (irow.lt.0) then
          call ptext(fgst, 80, 0., -1., 0)
          call plote()
          call plots(2.0, 1.5)
          call lstyle('T', 0.4, 0., 0, -999)
          irow = 4
        endif
        iymd = jymd
        x = ras * float(jn/30)
        yo = ras * float(irow*420)
        call plot(x, yo+2.35, 3)
        y = yo + ras*float(m1)
        m2r = m2
        kor = 0
        if (m1.gt.137) kor = 1
        call plot(x, y, 2)
        mvmin = mv
        mvmax = mv
        kst = 1
      else
        if (jn.lt.jp) call premsg('time going back')
        if ((jn-jp).gt.180) then
          y = yo+2.35
          call plot(x, y, 2)
        endif
        x = ras * float(jn/30)
        call plot(x, y, 2)
        if (m1.lt.30.and.kor.eq.1.and.m2.eq.(m2r+1)) then
          y = yo + ras*float(m1+250)
        else
          y = yo + ras*float(m1)
          m2r = m2
          kor = 0
          if (m1.gt.137) kor = 1
        endif
        call plot(x, y, 2)
        if (mv.gt.mvmax) mvmax = mv
        if (mv.lt.mvmin) mvmin = mv
      endif
      jp = jn
      goto 1
c
    4 kend = 1
    5 if (kst.ne.0) then
        call plot(x, yo+2.35, 2)
        write(label,'(i8,a2,2f8.1)')
     *        iymd, '  ', float(mvmin)/10., float(mvmax)/10.
        call ptext(label, 28, 0., yo+2.35, 0)
        call plot(0., yo-0.05, 3)
        call plot(ras*2880., yo-0.01, 2)
        do 10 i=0,24
          x = ras*float(i*120)
          y = yo - 0.13
          if (mod(i,6).eq.0) y = yo - 0.25
          call plot(x, y, 3)
          call plot(x, yo-0.05, 2)
   10   continue
        kst = 0
      endif
      if (kend.eq.0) goto 1
c
      call ptext(fgst, 80, 0., -1., 0)
      call plote()
      call pscls()
c
      if(flog(ldr:ldr).ne.' ') then
        open(99,file=flog,status='old',iostat=ios)
        if(ios.eq.0) then
   90     read(99,*,end=91)
          goto 90
   91     backspace(99)
        else
          open(99,file=flog,status='new')
        endif
        write(99,'(//a)')
     *       'PCHKDV : plot GS Mag. Diurnal Var. for check'
        write(99,'(a,a)')
     *       ' GSmag data filename : ', fgst(1:lrtrim(fgst))
        write(99,'(a,a)')
     *       ' Output PS filename  : ', fnam(1:lrtrim(fnam))
        close(99)
      endif
      stop
      end
