c--------( PCHKCOMP : plot res.prof. before/after compensation )--------
      parameter (ras=(2.54/300.))
      dimension f(2,2100), mc(2100), icol(2)
      character*80 wdr, flog, fnin, fnam
      character lnam*8, label*27, buf*150
      real*8 tms
c
      icol(1) = 255
      icol(2) = 255*256*256
      call premsg('PCHKCOMP : plot mag.prof. before/after compensation')
      call opnpin()
      ldr = lwkdir(50,wdr) + 1
      flog = wdr
      fnin = wdr
      fnam = wdr
      call gparma('Enter LOG filename ==> ', 81-ldr, flog(ldr:80))
      call gparma('Enter Input data filename ==> ',
     *            81-ldr, fnin(ldr:80))
      open(1,file=fnin,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)')
     *     'PCHKCOMP : plot res.prof. before/after compensation'
      write(6,'(a,a)') ' Input data filename : ', fnin(1:lrtrim(fnin))
      write(6,'(a,a)') ' Output PS filename  : ', fnam(1:lrtrim(fnam))
      call psopn(fnam, 'A4P')
c
      kend = 0
      lnam = '        '
      call plots(1.5, 2.0)
      call lstyle('T', 0.4, 0., 0, -999)
      irow = 10
    1 read(1,'(a)',end=5) buf
      if (buf(1:1).eq.'&'.or.buf(1:1).eq.'%') then
        read(buf,'(1x,a8)') lnam
        goto 1
      endif
      read(buf,*) fid,iymd,tms,km,flat,flon,falt,tmag,tcor,
     *            fx,fy,fz,utc,tres,corr,rand,trend
      write(label,'(a8,1x,i8,1x,f9.2)') lnam,iymd,tms
      n = 1
      f(1,n) = tres
      f(2,n) = tcor
    2 read(1,'(a)',end=3) buf
      if (buf(1:1).eq.'&'.or.buf(1:1).eq.'%') then
        read(buf,'(1x,a8)') lnam
        goto 4
      endif
      read(buf,*) fid,iymd,tms,km,flat,flon,falt,tmag,tcor,
     *            fx,fy,fz,utc,tres,corr,rand,trend
      n = n+1
      f(1,n) = tres
      f(2,n) = tcor
      if (n.eq.2100) goto 4
      goto 2
    3 kend = 1
    4 irow = irow - 1
      if (irow.lt.0) then
        call ptext(fnin, 80, 0., -1., 0)
        call plote()
        call plots(1.5, 2.0)
        call lstyle('T', 0.4, 0., 0, -999)
        irow = 9
      endif
      yo = ras * float(irow*300)
      x = 0.
      call ptext(label, 27, 0., yo+1.85, 0)
      do 300 k=1,2
        call penatr(0, icol(k), 0, 0.01)
        call plot(x, yo+1.1, 3)
        kor = 0
        do 100 i=1,n
          mv = nint(f(k,i)/25.*120.)
          m2 = mv/120
          m1 = mv - m2*120
          if (m1.lt.0) then
            m2 = m2 - 1
            m1 = m1 + 120
          endif
          if (m1.lt.12 .and. kor.eq.1 .and. m2.eq.(m2r+1)) then
            m2 = m2-1
            m1 = m1+120
          else if (m1.lt.66) then
            kor = 0
          else
            kor = 1
          endif
          m2r = m2
          m2 = m2 - m2/40*40
          if (m2.lt.0) m2 = m2 + 40
          mc(i) = m2
          y = yo + ras*float(m1)
          call plot(x, y, 2)
          x = ras*float(i)
          call plot(x, y, 2)
  100   continue
        do 200 i=n,1,-1
          y = yo + ras*float(mc(i)*2+135)
          call plot(x, y, 2)
          x = ras*float(i-1)
          call plot(x, y, 2)
  200   continue
        call plot(x, yo+1.1, 2)
  300 continue
      if (kend.eq.0) goto 1
    5 call ptext(fnin, 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)')
     *       'PCHKCOMP : plot res.prof. before/after compensation'
        write(99,'(a,a)')
     *       ' Input data filename : ', fnin(1:lrtrim(fnin))
        write(99,'(a,a)')
     *       ' Output PS filename  : ', fnam(1:lrtrim(fnam))
        close(99)
      endif
      stop
      end
