c--------( XPLMAP : Extended plotting of contour map )--------
c
c-------- This program should be linked with C-subroutine "xplgobj.o"
c
      parameter (MAXSZ=3001*3001, MXPT=150)
      parameter (RAD=180./3.14159)
c
      dimension g(MAXSZ), kobj(6), robj(8), xp(MXPT), yp(MXPT)
      character*80 wdr, flog, fnin, fnobj, fncap, fnam
      character area*8, s4*4, yn*1, sht*4, fnt*3, slbl*40
      character buf*80, out*72
      external cviken
c
      parameter (LBUF=256)
      character*256 sbf
c
      call premsg('XPLMAP : Extended plotting of contour map')
      call opnpin()
      ldr = lwkdir(50,wdr) + 1
      flog = wdr
      fnin = wdr
      fnobj = wdr
      fncap = 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(10,file=fnin,status='old')
      call gparmi(' dataset sequence number  ==> ', nseq)
      if(nseq.le.0) call abendm('invalid value')
      ns = 0
    1 read(10,'(a)') buf
      if(buf(1:1).eq.'#') goto 1
      read(10,*) ixs, iys, mszx, mszy, nmx, nmy, vnul
      ns = ns + 1
      if(nseq.eq.ns) goto 2
      read(10,*) ((dmy,i=1,nmx),j=1,nmy)
      goto 1
    2 call gparma('Specify Overlay Obj. file ==> ',
     *            81-ldr, fnobj(ldr:80))
      if(fnobj(ldr:ldr).ne.' ') open(11,file=fnobj,status='old')
      call gparma('Specify Caption data file ==> ',
     *            81-ldr, fncap(ldr:80))
      if(fncap(ldr:ldr).ne.' ') open(12,file=fncap,status='old')
      call gparma('Enter Output PS filename  ==> ',
     *            81-ldr, fnam(ldr:80))
      if(fnam(ldr:ldr).eq.' ') fnam(1:1) = char(0)
      if (fnam(80:80).ne.' ') then
        call abendm('too long filename')
      endif
c
      read(buf,'(a8,i4,4x,4i8)') area, ncc, iorg, korg, ispa, ispb
      if(ncc.ge.200) then
        mc = 1
        nc = ncc - 200
      else
        mc = 0
        nc = ncc
      endif
      if(nc.ge.1.and.nc.le.62) then
        iorg = 0
        ispa = 0
        ispb = 0
        korg = (nc-30)*360 - 180
        if(nc.gt.60) korg = 0
        if(nc.eq.61) iorg = +5400
        if(nc.eq.62) iorg = -5400
      endif
      xs = float(ixs)/1000.
      ys = float(iys)/1000.
      call premsg(' ')
      write(out,'(a,a8,a,i4,4x,4i8)')
     *     '--- Area : ', area, '   Coord.', ncc, iorg,korg, ispa,ispb
      call premsg(out)
      write(out,'(14x,2a10,2x,2a8,2a6)')
     *     'xs', 'ys', 'msz-x', 'msz-y', 'mx', 'my'
      call premsg(out)
      write(out,'(16x,2f10.2,2i8,2i6)') xs, ys, mszx, mszy, nmx, nmy
      call premsg(out)
      if((nmx*nmy).gt.MAXSZ) then
        call abendm('too many grids')
      endif
	  read(10,*) ((g(i+j),i=0,(nmx-1)*nmy,nmy),j=1,nmy)
      close(10)
      do 61 i=1,nmx*nmy
        if(g(i).ne.vnul) goto 5
   61 continue
      call abendm('no valid data')
    5 n = 1
      gsum = g(i)
      gmin = g(i)
      gmax = g(i)
      do 62 j=i+1,nmx*nmy
        if(g(j).eq.vnul) goto 62
        n = n + 1
        gsum = gsum + g(j)
        if(g(j).lt.gmin) gmin = g(j)
        if(g(j).gt.gmax) gmax = g(j)
   62 continue
      gsum = gsum / float(n)
      write(out,'(4x,a,f7.1,a,f7.1,a,f7.1)')
     *     'Data Range : [', gmin, ' ,', gmax, ' ]    Average :', gsum
      call premsg(out)
c
      call gparma(' Sheet Size ?  (A4P, B4L, A1L, B0P, etc.) : ',
     *            4, sht)
      if(sht(1:1).eq.'a') sht(1:1) = 'A'
      if(sht(1:1).eq.'b') sht(1:1) = 'B'
      if(sht(1:2).eq.'A4') then
        szx = 19.7
        szy = 27.9
      else if(sht(1:2).eq.'B4') then
        szx = 24.1
        szy = 34.3
      else if(sht(1:2).eq.'A3') then
        szx = 27.9
        szy = 39.4
      else if(sht(1:2).eq.'B3') then
        szx = 34.3
        szy = 48.3
      else if(sht(1:2).eq.'A2') then
        szx = 39.4
        szy = 55.9
      else if(sht(1:2).eq.'B2') then
        szx = 48.3
        szy = 68.6
      else if(sht(1:2).eq.'A1') then
        szx = 55.9
        szy = 78.7
      else if(sht(1:2).eq.'B1') then
        szx = 68.6
        szy = 96.5
      else if(sht(1:2).eq.'A0') then
        szx = 78.7
        szy =111.8
      else if(sht(1:2).eq.'B0') then
        szx = 96.5
        szy =137.2
      else
        call abendm('unknown sheet size')
      endif
      if(sht(3:3).eq.'p') sht(3:3) = 'P'
      if(sht(3:3).eq.'l') sht(3:3) = 'L'
      if(sht(3:3).eq.'P') then
        swd = szx
        shi = szy
      else if(sht(3:3).eq.'L') then
        swd = szy
        shi = szx
      else
        call abendm('unknown sheet orientation')
      endif
      if(sht(4:4).eq.'e') sht(4:4) = 'E'
      if(sht(4:4).ne.'E') sht(4:4) = ' '
      call gparmf(' Left Margin ?  (in cm)   : ', am)
      call gparmf(' Bottom Margin ?  (in cm) : ', bm)
      call gparmi(' Contour interval ?       : ', istep)
      call premsg(' Char.Size of Contour Values ?')
      call gparmf('   (in cm) [ 0. to write no values ] : ', csiz)
      call gparmf(' Scale ?  (in reciprocal) : ', fscl)
      istp = iabs(istep)
      lcapt = 5
      if(istp.eq.25.or.istp.eq.50.or.istp.eq.250) lcapt = 4
      high = float((nmx-1)*mszx)*100. / fscl
      wide = float((nmy-1)*mszy)*100. / fscl
      rs = swd - wide - am
      ts = shi - high - bm
      write(out,'(a,i4,4x,a,f8.0,4x,a4)')
     *      '---   step=', istep, 'scale  1 /', fscl, sht
      call premsg(out)
      write(out,'(8x,a,f5.1,a,f5.1)')
     *      'Drawing   Width:', wide, '   Height:', high
      call premsg(out)
      write(out,'(8x,a,f5.1,a,f5.1)')
     *      'Margin    Left :', am, '   Bottom:', bm
      call premsg(out)
      write(out,'(8x,a,f5.1,a,f5.1)')
     *      'Rspace    Right:', rs, '   Top   :', ts
      call premsg(out)
c
      ccm = fscl/100000.
      km = nint(fscl)/25000
      if(km.lt.1) km = 1
      if(km.gt.2.and.km.lt.5) km = 2
      if(km.gt.5.and.km.lt.10) km = 5
      if(km.gt.10.and.km.lt.20) km = 10
      if(km.gt.20.and.km.lt.50) km = 20
      if(km.ge.50.and.km.lt.120) km = 60
      if(km.gt.120.and.km.lt.300) km = 120
      if(km.gt.300.and.km.lt.600) km = 300
      if(km.gt.600) km = 600
      iinc = km
      kinc = km + km/2
      if(km.gt.50) km = 50
      if(km.eq.5.or.km.eq.50) kinc = iinc
      dscl = float(km)/ccm
c
      kscl = 0
      sclr = 0.
      sclu = 0.
   11 call prompt('  Draw  Scale Bar  ?  ')
      call gparma('  "y" (Yes) or "n" (No) ==> ', 1, yn)
      if(yn.ne.'y'.and.yn.ne.'n'.and.yn.ne.'Y'.and.yn.ne.'N') goto 11
      if(yn.eq.'y'.or.yn.eq.'Y') then
        kscl = 1
        write(out,'(a,f4.1,a)')
     *        '      size :', dscl, 'cm Wide, 0.8cm High'
        call premsg(out)
        call prompt('    Lower-Left Pos. ? (right and up)')
        call gparmf2(' in cm ==> ', sclr, sclu)
      endif
      klll = 0
   12 call prompt('  Draw Lat.Lon.Lines ?')
      call gparma('  "y" (Yes) or "n" (No) ==> ', 1, yn)
      if(yn.ne.'y'.and.yn.ne.'n'.and.yn.ne.'Y'.and.yn.ne.'N') goto 12
      if(yn.eq.'y'.or.yn.eq.'Y') klll = 1
      kshl = 0
   13 call prompt('  Draw Coastlines ?   ')
      call gparma('  "y" (Yes) or "n" (No) ==> ', 1, yn)
      if(yn.ne.'y'.and.yn.ne.'n'.and.yn.ne.'Y'.and.yn.ne.'N') goto 13
      if(yn.eq.'y'.or.yn.eq.'Y') then
        kshl = 2
   14   call prompt('       Rivers  ?      ')
        call gparma('  "y" (Yes) or "n" (No) ==> ', 1, yn)
        if(yn.ne.'y'.and.yn.ne.'n'.and.yn.ne.'Y'.and.yn.ne.'N') goto 14
        if(yn.eq.'y'.or.yn.eq.'Y') kshl = 12
   15   call prompt('       Pref.Boundary ?')
        call gparma('  "y" (Yes) or "n" (No) ==> ', 1, yn)
        if(yn.ne.'y'.and.yn.ne.'n'.and.yn.ne.'Y'.and.yn.ne.'N') goto 15
        if(yn.eq.'y'.or.yn.eq.'Y') then
          kshl = kshl + 200
          if(kshl.eq.202) kshl = 102
        endif
      endif
c
    6 call gparma('Enter "y" to continue.   O.K. ?  ==> ', 1, yn)
      if(yn.eq.'n'.or.yn.eq.'N') call abendm('invalid parameter')
      if(yn.ne.'y'.and.yn.ne.'Y') goto 6
      klbl = 0
    7 call prompt('  Write Identifier-Label ?  ')
      call gparma('  "y" (Yes) or "n" (No) ==> ', 1, yn)
      if(yn.ne.'y'.and.yn.ne.'Y'.and.yn.ne.'n'.and.yn.ne.'N') goto 7
      if(yn.eq.'y'.or.yn.eq.'Y') then
        klbl = 1
        call gparma('    Label ?  (max. 40 chars) : ', 40, slbl)
      endif
      call clspin()
c
      write(6,'(a)') '----------------------------------------'
      write(6,'(a)') 'XPLMAP: plot contour map for Grid data'
      write(6,'(a,a)') ' Input data filename   : ', fnin(1:lrtrim(fnin))
      write(6,'(a,i2)') '   dataset seq. number : ', nseq
      write(6,'(a,a8,a,i4,4x,4i8)')
     *     'Areaname : ', area, '   Coord.', ncc, iorg,korg, ispa,ispb
      write(6,'(14x,2a10,2x,2a8,2a6)')
     *     'xs', 'ys', 'msz-x', 'msz-y', 'mx', 'my'
      write(6,'(16x,2f10.2,2i8,2i6)') xs, ys, mszx, mszy, nmx, nmy
      write(6,'(a,a)') ' Output PS filename  : ', fnam(1:lrtrim(fnam))
      write(6,'(6x,a,i4,4x,a,f8.0,4x,a4)')
     *      'step=', istep, 'scale  1 /', fscl, sht
      write(6,'(8x,a,f5.1,a,f5.1)')
     *      'Drawing   Width:', wide, '   Height:', high
      write(6,'(8x,a,f5.1,a,f5.1)')
     *      'Margin    Left :', am, '   Bottom:', bm
      write(6,'(8x,a,f5.1,a,f5.1)')
     *      'Rspace    Right:', rs, '   Top   :', ts
      if(kscl.ne.0.or.klll.ne.0.or.kshl.ne.0) then
        write(6,'(a,$)') '      with '
        if(kshl.ne.0) write(6,'(a,$)') '  Coast'
        if(mod(kshl,100)/10.ne.0) write(6,'(a,$)') '+River'
        if(kshl/100.ne.0) write(6,'(a,$)') '+PrefB'
        if(klll.ne.0) write(6,'(a,$)') '  LatLonLines'
        if(kscl.ne.0) then
          write(6,'(a,f5.1,$)') '  ScaleBar [', sclr
          write(6,'(a,f5.1,a,$)') ',', sclu, ' ]'
        endif
        write(6,'(a)')
      endif
      if (klbl.ne.0) write(6,'(a,a)') '      Identifier : ', slbl
      if (fnobj(ldr:ldr).ne.' ') write(6,'(a,a)')
     *      ' Overlay obj. filename : ', fnobj(1:lrtrim(fnobj))
      if (fncap(ldr:ldr).ne.' ') write(6,'(a,a)')
     *      ' Caption data filename : ', fncap(1:lrtrim(fncap))
c
      call cvinit(ncc,float(iorg),float(korg),float(ispa),float(ispb))
      call psopn(fnam, sht)
      call plots(am, bm)
      call premsg('--- Drawing Contour Lines')
      call wrect(0., 0., wide, high)
      call conts(0., 0., wide, high, nmy, nmx, csiz/6.*7.)
      call contx(g, vnul, istp, lcapt, -99999, 99999, 10)
      if(klbl.ne.0) then
        call lstyle('CFN', 0.3, 0., 0, -999)
        call ptext(slbl, 40, -am, -bm, 0)
      endif
c
      if(fnobj(ldr:ldr).ne.' ') then
        call premsg('--- Drawing Overlay Obj.')
        ns = 0
c
   20   ns = ns + 1
        read(11,'(a)',end=38) sbf(1:LBUF-1)
        if(sbf(1:1).eq.'#') goto 20
        j = LBUF
   21   j = j-1
        if(j.eq.0) goto 20
        if(sbf(j:j).eq.' ') goto 21
        sbf(j+1:j+1) = char(0)
        call getobj(sbf, kobj, robj)
        k = kobj(1)
        nct = kobj(2)
        if(nct.ne.-1.and.nct.ne.ncc) goto 37
        if(k.le.0.or.k.gt.12) goto 37
c
        if(k.le.7.or.k.eq.9) then
          if(nct.eq.-1) then
            call cviken(robj(1), robj(2), y, x)
            robj(1) = (x-xs)/ccm
            robj(2) = (y-ys)/ccm
            if(k.ge.3.and.k.le.6) then
              call cviken(robj(3), robj(4), y, x)
              robj(3) = (x-xs)/ccm
              robj(4) = (y-ys)/ccm
            endif
          else
            robj(1) = (robj(1) - xs) / ccm
            robj(2) = (robj(2) - ys) / ccm
            if(k.ge.3.and.k.le.6) then
              robj(3) = (robj(3) - xs) / ccm
              robj(4) = (robj(4) - ys) / ccm
            endif
          endif
        else if(k.eq.12.and.nct.ne.-1) then
          call cvenik(robj(2), robj(1), robj(1), robj(2))
          call cvenik(robj(4), robj(3), robj(3), robj(4))
        endif
c
        if(k.eq.10.or.k.eq.11) then
          if(kobj(3).lt.3.or.kobj(3).gt.MXPT) then
            call abendm('too many corners (polygon)')
          endif
          i = 1
          m = 1
   31     ns = ns + 1
          read(11,'(a)',end=37) sbf(1:LBUF-1)
          if(sbf(1:1).eq.'#') goto 31
          j = LBUF
   32     j = j-1
          if(j.eq.0) goto 31
          if(sbf(j:j).eq.' ') goto 32
          sbf(j+1:j+1) = char(0)
          j = 1
   33     if(m.eq.1) then
            if(nct.eq.-1) then
                call scandm(j, sbf, xp(i))
            else
                call scanfv(j, sbf, xp(i))
            endif
          else if(m.eq.2) then
            if(nct.eq.-1) then
                call scandm(j, sbf, yp(i))
            else
                call scanfv(j, sbf, yp(i))
            endif
          else
              if(k.eq.11) call scanfv(j, sbf, dmy)
          endif
          if(j.lt.0) goto 37
          if(j.eq.0) goto 31
          m = m + 1
          if(m.le.3) goto 33
          m = 1
          i = i + 1
          if(i.le.kobj(3)) goto 33
          if(nct.eq.-1) then
            do 34 i=1,kobj(3)
              call cviken(xp(i), yp(i), y, x)
              xp(i) = (x-xs)/ccm
              yp(i) = (y-ys)/ccm
   34       continue
          else
            do 35 i=1,kobj(3)
              xp(i) = (xp(i) - xs) / ccm
              yp(i) = (yp(i) - ys) / ccm
   35       continue
          endif
        endif
c
        if(k.eq.1) then
          i = kobj(5)
          if(i.lt.-255.or.i.gt.4095) i = 0
          call dfpcol(1, i)
          call paintc(robj(2), robj(1), robj(7)/2.)
        else if(k.eq.2) then
          call penatr(0, kobj(5), kobj(6), robj(8))
          call wcirc(robj(2), robj(1), robj(6)/ccm, 0., 360.)
        else if(k.eq.3.or.k.eq.4) then
          call penatr(0, kobj(5), kobj(6), robj(8))
          call plot(robj(2), robj(1), 3)
          call plot(robj(4), robj(3), 2)
        else if(k.eq.5.or.k.eq.6) then
          wd = robj(4)-robj(2)
          hi = robj(3)-robj(1)
          call penatr(0, kobj(5), kobj(6), robj(8))
          call wrect(robj(2), robj(1), wd, hi)
        else if(k.eq.7) then
          mark = kobj(3)
          call pmark(mark, robj(2), robj(1), robj(7), robj(8), kobj(5))
        else if(k.eq.8) then
          fnt = sbf(kobj(3)+1:kobj(4))
          call lstyle(fnt, robj(7), robj(6), kobj(5), kobj(6))
        else if(k.eq.9) then
          i = kobj(3)+1
          j = kobj(4)
          if((sbf(i:i).eq.''''.and.sbf(j:j).eq.'''').or.
     *       (sbf(i:i).eq.'"' .and.sbf(j:j).eq.'"' )) then
            i = i + 1
            j = j - 1
          endif
          call ptext(sbf(i:j), j-i+1, robj(2), robj(1), kobj(6))
        else if(k.eq.10.or.k.eq.11) then
          call penatr(0, kobj(5), kobj(6), robj(8))
          call wpolyg(yp, xp, kobj(3), 1)
        else if(k.eq.12) then
          call penatr(0, kobj(5), kobj(6), robj(8))
          call cviken(robj(1), robj(2), y, x)
          call plot((y-ys)/ccm, (x-xs)/ccm, 3)
          call cviken(robj(3), robj(2), y, x)
          call plot((y-ys)/ccm, (x-xs)/ccm, 2)
          call cviken(robj(3), robj(4), y, x)
          call plot((y-ys)/ccm, (x-xs)/ccm, 2)
          call cviken(robj(1), robj(4), y, x)
          call plot((y-ys)/ccm, (x-xs)/ccm, 2)
          call cviken(robj(1), robj(2), y, x)
          call plot((y-ys)/ccm, (x-xs)/ccm, 2)
        endif
        goto 20
c
   37   write (buf,'(a17,i5,a8)') '  (Obj.) Error at', ns, '-th Line'
        call premsg(buf(1:30))
   38   close(11)
        call newpen(1)
      endif
c
      if(kscl.ne.0) then
        call premsg('--- Drawing Scale-Bar')
        write(s4,'(i2,a2)') km, 'km'
        call lstyle('TB ', 0.7, 0., 0, -999)
        call ptext(s4, 4, sclr+dscl/2., sclu+0.5, 2)
        call newpen(2)
        call plot(sclr,      sclu+0.1, 3)
        call plot(sclr+dscl, sclu+0.1, 2)
        call newpen(3)
        call plot(sclr+dscl, sclu+0.3, 3)
        call plot(sclr+dscl, sclu,     2)
        call plot(sclr,      sclu,     2)
        call plot(sclr,      sclu+0.3, 2)
        call newpen(1)
      endif
      call scisor(0., 0., wide, high)
      if(klll.ne.0.or.kshl.ne.0) then
        xt = xs + float((nmx-1)*mszx)/1000.
        yt = ys + float((nmy-1)*mszy)/1000.
        call cviken(float(iorg), float(korg), yo, xo)
        call cvenik(yo, xs, fi0, fk0)
        call cvenik(ys, xs, fi1, fk1)
        call cvenik(yt, xs, fi2, fk2)
        call cvenik(ys, xt, fi3, fk3)
        call cvenik(yt, xt, fi4, fk4)
        call cvenik(yo, xt, fi5, fk5)
        isf = nint(amin1(fi0,fi1,fi2) - 0.5)
        itf = nint(amax1(fi3,fi4,fi5) + 0.5)
        ksf = nint(amin1(fk1,fk3) - 0.5)
        ktf = nint(amax1(fk2,fk4) + 0.5)
      endif
      if(klll.ne.0) then
        call premsg('--- Drawing LatLonLines')
        do 42 i=isf/iinc,itf/iinc
          idf = i * iinc
          if(idf.lt.isf.or.idf.gt.itf) goto 42
          call cviken(float(idf), float(ksf), y, x)
          call plot((y-ys)/ccm, (x-xs)/ccm, 3)
          do 41 kdf=ksf+1,ktf
            call cviken(float(idf), float(kdf), y, x)
            call plot((y-ys)/ccm, (x-xs)/ccm, 2)
   41     continue
   42   continue
        do 44 k=ksf/kinc,ktf/kinc
          kdf = k * kinc
          if(kdf.lt.ksf.or.kdf.gt.ktf) goto 44
          call cviken(float(isf), float(kdf), y, x)
          call plot((y-ys)/ccm, (x-xs)/ccm, 3)
          do 43 idf=isf+1,itf
            call cviken(float(idf), float(kdf), y, x)
            call plot((y-ys)/ccm, (x-xs)/ccm, 2)
   43     continue
   44   continue
      endif
      if(kshl.ne.0) then
        call premsg('--- Drawing ShoreLines etc.')
        call rshore(mc, isf/60, (itf+59)/60, ksf/60, (ktf+59)/60)
        call pshore(-ys/ccm, -xs/ccm, kshl, ccm, cviken)
      endif
      call scisor(0., 0., 0., 0.)
c
      if(fncap(ldr:ldr).ne.' ') then
        call premsg('--- Drawing Captions')
        xs = 0.
        ys = 0.
        ca = 1.
        sa = 0.
        ksp = 0
        ns = 0
   50   ns = ns + 1
        read(12,'(a)',end=58) sbf(1:LBUF-1)
        if(sbf(1:1).eq.'#') goto 50
        j = LBUF
   51   j = j - 1
        if(j.eq.1) goto 52
        if(sbf(j:j).eq.' ') goto 51
   52   sbf(j+1:j+1) = char(0)
        if(sbf(1:1).eq.' ') then
          i = 1
   53     i = i + 1
          if(sbf(i:i).eq.' ') goto 53
          if((sbf(i:i).eq.''''.and.sbf(j:j).eq.'''').or.
     *       (sbf(i:i).eq.'"' .and.sbf(j:j).eq.'"' )) then
            i = i + 1
            j = j - 1
          endif
          if(ksp.eq.0) then
            xs = xs + sa*size*1.2
            ys = ys - ca*size*1.2
          endif
          call ptext(sbf(i:j), j-i+1, xs, ys, 0)
          ksp = 0
        else if(sbf(1:1).eq.'=') then
          j = 2
          call scanfv(j, sbf, xs)
          if(j.le.0) goto 57
          call scanfv(j, sbf, ys)
          if(j.le.0) goto 57
          ksp = 1
        else
          j = 1
   54     j = j + 1
          if(sbf(j:j).eq.char(0)) goto 57
          if(sbf(j:j).ne.' ') goto 54
          fnt = sbf(1:j-1)
          call scanfv(j, sbf, size)
          if(j.le.0) goto 57
          angle = 0.
          itcol = 0
          ibcol = 9999
          call scanfv(j, sbf, angle)
          if(j.lt.0) goto 57
          if(j.eq.0) goto 55
          call scaniv(j, sbf, itcol)
          if(j.lt.0) goto 57
          if(j.eq.0) goto 55
          call scaniv(j, sbf, ibcol)
          if(j.lt.0) goto 57
          if(j.eq.0) goto 55
   55     call lstyle(fnt, size, angle, itcol, ibcol)
          ca = cos(angle/RAD)
          sa = sin(angle/RAD)
        endif
        goto 50
   57   write(buf,'(a17,i5,a8)') '  (Cap.) Error at', ns, '-th Line'
        call premsg(buf(1:30))
   58   close(12)
      endif
c
      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)') 'XPLMAP: plot contour map for Grid data'
        write(99,'(a,a)')
     *        ' Input data filename   : ', fnin(1:lrtrim(fnin))
        write(99,'(a,i2)') '   dataset seq. number : ', nseq
        write(99,'(a,a8,a,i4,4x,4i8)')
     *       'Areaname : ', area, '   Coord.', ncc, iorg,korg,ispa,ispb
        write(99,'(14x,2a10,2x,2a8,2a6)')
     *       'xs', 'ys', 'msz-x', 'msz-y', 'mx', 'my'
        write(99,'(16x,2f10.2,2i8,2i6)') xs, ys, mszx, mszy, nmx, nmy
        write(99,'(a,a)')
     *        ' Output PS filename  : ', fnam(1:lrtrim(fnam))
        write(99,'(6x,a,i4,4x,a,f8.0,4x,a4)')
     *        'step=', istep, 'scale  1 /', fscl, sht
        write(99,'(8x,a,f5.1,a,f5.1)')
     *        'Drawing   Width:', wide, '   Height:', high
        write(99,'(8x,a,f5.1,a,f5.1)')
     *        'Margin    Left :', am, '   Bottom:', bm
        write(99,'(8x,a,f5.1,a,f5.1)')
     *        'Rspace    Right:', rs, '   Top   :', ts
        if(kscl.ne.0.or.klll.ne.0.or.kshl.ne.0) then
          write(99,'(a,$)') '      with '
          if(kshl.ne.0) write(99,'(a,$)') '  Coast'
          if(mod(kshl,100)/10.ne.0) write(99,'(a,$)') '+River'
          if(kshl/100.ne.0) write(99,'(a,$)') '+PrefB'
          if(klll.ne.0) write(99,'(a,$)') '  LatLonLines'
          if(kscl.ne.0) then
            write(99,'(a,f5.1,$)') '  ScaleBar [', sclr
            write(99,'(a,f5.1,a,$)') ',', sclu, ' ]'
          endif
          write(99,'(a)')
        endif
        if (klbl.ne.0) write(99,'(a,a)') '      Identifier : ', slbl
        if (fnobj(ldr:ldr).ne.' ') write(99,'(a,a)')
     *        ' Overlay obj. filename : ', fnobj(1:lrtrim(fnobj))
        if (fncap(ldr:ldr).ne.' ') write(99,'(a,a)')
     *        ' Caption data filename : ', fncap(1:lrtrim(fncap))
      endif
c
      call premsg('    completed')
      stop
      end
