c--------( PFRAME : plot framework of coordinates )--------
      character*80 wdr, flog, fnam
      character area*8, aval*8, yn*1, spl*3, sdtm*20
      character*8 scd1, scd2, scd3, scd4, scd
      external cviken
c
      call premsg('PFRAME : plot framework of coordinates')
      call opnpin()
      ldr = lwkdir(50,wdr) + 1
      flog = wdr
      fnam = wdr
      call gparma('Enter LOG filename ==> ', 81-ldr, flog(ldr:80))
      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.' ') call abendm('too long filename')
      call gparma('Areaname (8 chrs max) : ', 8, area)
      call gparmi('Select Coordinate Number (+200 for WGS) ==> ', ncc)
      nc = ncc
      if(ncc.ge.200) nc = ncc - 200
      ispa = 0
      ispb = 0
      if(nc.ge.1.and.nc.le.62) then
        iorg = 0
        korg = (nc-30)*360 - 180
        if(nc.gt.60) korg = 0
        if(nc.eq.61) iorg = +5400
        if(nc.eq.62) iorg = -5400
      else
        call gparmi2('    Origin Lat. & Long. in minutes : ',
     *               iorg, korg)
        if(nc.eq.72) then
          call gparmi2('    Latitudes of two std.parallels : ',
     *                 ispa, ispb)
        endif
      endif
      call gparmf2('  South bound Lat. ?  (Deg., Min.) ==> ', deg, fun)
      lats = nint(deg*60. + fun)
      if (lats.lt.1200.or.lats.ge.3000) call abendm('invalid value')
      ideg = lats / 60
      imin = lats - ideg*60
      write(scd1,'(i3,1h.,i2.2,2h''N)') ideg, imin
      call gparmf2('  North bound Lat. ?  (Deg., Min.) ==> ', deg, fun)
      latn = nint(deg*60. + fun)
      if (latn.le.lats.or.latn.gt.3000) call abendm('invalid value')
      ideg = latn / 60
      imin = latn - ideg*60
      write(scd2,'(i3,1h.,i2.2,2h''N)') ideg, imin
      call gparmf2('  West bound Long. ?  (Deg., Min.) ==> ', deg, fun)
      lonw = nint(deg*60. + fun)
      if (lonw.lt.7200.or.lonw.ge.9000) call abendm('invalid value')
      ideg = lonw / 60
      imin = lonw - ideg*60
      write(scd3,'(i3,1h.,i2.2,2h''E)') ideg, imin
      call gparmf2('  East bound Long. ?  (Deg., Min.) ==> ', deg, fun)
      lone = nint(deg*60. + fun)
      if (lone.le.lonw.or.lone.gt.9000) call abendm('invalid value')
      ideg = lone / 60
      imin = lone - ideg*60
      write(scd4,'(i3,1h.,i2.2,2h''E)') ideg, imin
      call cvinit(ncc,float(iorg),float(korg),float(ispa),float(ispb))
      call cviken(float(lats), float(lonw), y1, x1)
      call cviken(float(lats), float(lone), y2, x2)
      call cviken(float(latn), float(lone), y3, x3)
      call cviken(float(latn), float(lonw), y4, x4)
      xs = amin1(x1, x2, x3, x4)
      xt = amax1(x1, x2, x3, x4)
      ys = amin1(y1, y2, y3, y4)
      yt = amax1(y1, y2, y3, y4)
      r = amin1(xt-xs, yt-ys)
      if (r.ge.100.) then
        if (r.ge.500.) then
          if (r.ge.1000.) then
            iunit = 500
          else
            iunit = 200
          endif
        else
          if (r.ge.250.) then
            iunit = 100
          else
            iunit = 50
          endif
        endif
      else
        if (r.ge.25.) then
          if (r.ge.50.) then
            iunit = 20
          else
            iunit = 10
          endif
        else
          if (r.ge.10.) then
            iunit = 5
          else
            if (r.ge.5.) then
              iunit = 2
            else
              iunit = 1
            endif
          endif
        endif
      endif
      ixs = ifix(xs/float(iunit))
      if (xs.lt.0.) ixs = ixs-1
      xs = float(ixs*iunit)
      ixt = ifix(xt/float(iunit))
      if (xs.gt.0.) ixt = ixt+1
      xt = float(ixt*iunit)
      iys = ifix(ys/float(iunit))
      if (ys.lt.0.) iys = iys-1
      ys = float(iys*iunit)
      iyt = ifix(yt/float(iunit))
      if (yt.gt.0.) iyt = iyt+1
      yt = float(iyt*iunit)
      if ((xt-xs).ge.(yt-ys)) then
        kpl = 1
        fscl = amax1((yt-ys)/15., (xt-xs)/25.)
      else
        kpl = 2
        fscl = amax1((yt-ys)/25., (xt-xs)/15.)
      endif
      high = (xt-xs)/fscl
      wide = (yt-ys)/fscl
      if(kpl.eq.1) spl = 'A4P'
      if(kpl.eq.2) spl = 'A4L'
      call psopn(fnam, spl)
      inc = nint(fscl*100000.)/25000
      if(inc.eq.0) inc = 1
      if(inc.gt.2.and.inc.lt.5) inc = 2
      if(inc.gt.5.and.inc.lt.10) inc = 5
      if(inc.gt.10.and.inc.lt.20) inc = 10
      if(inc.gt.20.and.inc.lt.60) inc = 20
      if(inc.gt.60.and.inc.lt.120) inc = 60
      if(inc.gt.120.and.inc.lt.300) inc = 120
      if(inc.gt.300.and.inc.lt.600) inc = 300
      if(inc.gt.600) inc = 600
      kshl = 2
    1 call prompt(' Draw  Rivers  ?      ')
      call gparma('  "y" (Yes) or "n" (No) ==> ', 1, yn)
      if(yn.ne.'y'.and.yn.ne.'n') goto 1
      if(yn.eq.'y') kshl = 12
    2 call prompt('       Pref.Boundary ?')
      call gparma('  "y" (Yes) or "n" (No) ==> ', 1, yn)
      if(yn.ne.'y'.and.yn.ne.'n') goto 2
      if(yn.eq.'y') then
        kshl = kshl + 200
        if(kshl.eq.202) kshl = 102
      endif
      call clspin()
      write(6,'(a)') '----------------------------------------'
      write(6,'(a)') 'PFRAME : plot framework of coordinates'
      write(6,'(a,a)') ' Output PS filename  : ', fnam(1:lrtrim(fnam))
      write(6,'(a,a8,a,i4,4x,4i8)')
     *     'Areaname : ', area, '   Coord.', ncc, iorg,korg, ispa,ispb
      write(6,'(15x,4a)') 'Lat. range :   ', scd1, ' - ', scd2
      write(6,'(15x,4a)') 'Lon. range :   ', scd3, ' - ', scd4
      write(6,'(15x,a,f6.0,a,f6.0)')
     *     'SW corner :      x =', xs, '   y =', ys
      write(6,'(15x,a,f6.0,a,f6.0)')
     *     'NE corner :      x =', xt, '   y =', yt
      write(6,'(6x,a,f9.0,3x,a3,f8.1,a1,f8.1,a1)')
     *     'scale  1 /', fscl*100000., spl, high, 'H', wide, 'W'
      if(kscl.ne.0.or.klll.ne.0.or.kshl.ne.0) then
        write(6,'(a,$)') '      with   Coast'
        if(mod(kshl,100)/10.ne.0) write(6,'(a,$)') '+River'
        if(kshl/100.ne.0) write(6,'(a,$)') '+PrefB'
        write(6,'(a)') '  LatLonLines'
      endif
c
      call plots(3., 2.)
      call lstyle('T', 0.4, 0., 0, -999)
      call penatr(0, 255, 2, 0.01)
      do 3 ix=ixs,ixt
        x = float((ix-ixs)*iunit) / fscl
        call plot(-0.15, x, 3)
        call plot(wide, x, 2)
        write(aval,'(i8)') ix*iunit
        call ptext(aval, 8, -0.2, x-0.1, 1)
    3 continue
      do 4 iy=iys,iyt
        y = float((iy-iys)*iunit) / fscl
        call plot(y, -0.15, 3)
        call plot(y, high, 2)
        write(aval,'(i8)') iy*iunit
        call ptext(aval, 8, y, -0.4, 2)
    4 continue
      call newpen(1)
      do 6 i=lats,latn
        if (i.ne.lats .and. i.ne.latn .and. i.ne.(i/inc*inc)) goto 6
        call cviken(float(i), float(lonw), y, x)
        call plot((y-ys)/fscl, (x-xs)/fscl, 3)
        do 5 k=lonw+1,lone
          call cviken(float(i), float(k), y, x)
          call plot((y-ys)/fscl, (x-xs)/fscl, 2)
    5   continue
        ideg = i / 60
        imin = i - ideg*60
        write(scd,'(i2,1h.,i2.2,2h''N)') ideg, imin
        call ptext(scd, 7, (y-ys)/fscl+0.1, (x-xs)/fscl-0.1, 0)
    6 continue
      call lstyle('T', 0.4, 90., 0, -999)
      do 8 k=lonw,lone
        if (k.ne.lonw .and. k.ne.lone .and. k.ne.(k/inc*inc)) goto 8
        call cviken(float(lats), float(k), y, x)
        call plot((y-ys)/fscl, (x-xs)/fscl, 3)
        do 7 i=lats+1,latn
          call cviken(float(i), float(k), y, x)
          call plot((y-ys)/fscl, (x-xs)/fscl, 2)
    7   continue
        ideg = k / 60
        imin = k - ideg*60
        write(scd,'(i3,1h.,i2.2,2h''E)') ideg, imin
        call ptext(scd, 8, (y-ys)/fscl+0.1, (x-xs)/fscl+0.1, 0)
    8 continue
      call scisor(0., 0., wide, high)
      if(kshl.ne.0) then
        call rshore(nc/200, is/60, (it+59)/60, ks/60, (kt+59)/60)
        call pshore(-ys/fscl, -xs/fscl, kshl, fscl, cviken)
      endif
      call scisor(0., 0., 0., 0.)
      call lstyle('T', 0.4, 0., 0, -999)
      call ptext(area, 8, -1., -1.5, 0)
      write(aval,'(4hnc =,i4)') ncc
      call ptext(aval, 8, 1., -1.5, 0)
      call plote()
      call pscls()
c
      if(flog(ldr:ldr).ne.' ') then
        open(99,file=flog,access='append')
        write(99,'(//a,$)') 'PFRAME :'
        write(99,'(a)')   ' plot framework of coordinates'
        write(99,'(a,a)')
     *       ' Output PS filename  : ', fnam(1:lrtrim(fnam))
        write(99,'(a,a8,a,i4,4x,4i8)')
     *       'Areaname : ', area, '   Coord.', ncc, iorg,korg,ispa,ispb
        write(99,'(15x,4a)') 'Lat. range :   ', scd1, ' - ', scd2
        write(99,'(15x,4a)') 'Lon. range :   ', scd3, ' - ', scd4
        write(99,'(15x,a,f6.0,a,f6.0)')
     *       'SW corner :      x =', xs, '   y =', ys
        write(99,'(15x,a,f6.0,a,f6.0)')
     *       'NE corner :      x =', xt, '   y =', yt
        write(99,'(6x,a,f9.0,3x,a3,f8.1,a1,f8.1,a1)')
     *       'scale  1 /', fscl*100000., spl, high, 'H', wide, 'W'
        if(kscl.ne.0.or.klll.ne.0.or.kshl.ne.0) then
          write(99,'(a,$)') '      with   Coast'
          if(mod(kshl,100)/10.ne.0) write(99,'(a,$)') '+River'
          if(kshl/100.ne.0) write(99,'(a,$)') '+PrefB'
          write(99,'(a)') '  LatLonLines'
        endif
        call strdtm(sdtm)
        write(99,'(a,a,a)') '=============== ', sdtm, '==============='
        close(99)
      endif
      stop
      end
