c  XYZ2GRF - written by Jeff Phillips
        character ifile*80,sym*4,ans*1,ansp*1,fmt1*6,fmt*40,G(50,50)*1
        character prompt*80,ofile*80
        real xyz(3)
        data irows/3/,icols/3/,ircent/1/,iccent/1/
        data G(1,1),G(1,2),G(1,3)/'*','*','*'/
        data G(2,1),G(2,2),G(2,3)/'*','*','*'/
        data G(3,1),G(3,2),G(3,3)/'*','*','*'/
        print*
        print*,'Binary xyz to grf conversion for plotting point data'
        print*,'on PDS images using IMVIS.  The xyz data must be'
        print*,'in km or meters for "None" projection, in lat/lon'
        print*,'for other projections.'
        print*
        call askin
c        print'(a\)',' Enter input xyz file:'
c        read(5,100) ifile
c  100   format(a)
c        open(10,file=ifile,form='unformatted',status='old')
        ifile=' '
400     prompt='Enter input xyz file'
        call askc(prompt,ifile,ierr)
        if(ierr.lt.0) stop
        call xopen(10,ifile,'old','read',itype,ierr)
        if(ierr.ne.0) go to 400
        if(itype.ne.0) stop 'not an xyz file'
c        print'(a\)',' Enter output grf file:'
c        read(5,100) ifile
c        ifile=' '
          ofile=ifile(1:index(ifile,'.'))//'grf'
401     prompt='Enter output grf file'
        call askc(prompt,ofile,ierr)
        if(ierr.eq.-2) then
          close(10)
          go to 400
        endif
        open(11,file=ofile,form='formatted',status='new')
c        print'(a\)',' Do you want to post the z-value?:'
c        read(5,100) ansp
        ians=0
402     prompt='Do you want to post the z-value?'
        call aski4l(prompt,iansp,ierr)
        if(ierr.eq.-2) then
          close(11)
          go to 401
        endif
        if(iansp.eq.1) then
c          print'(a\)',' Enter format (6 characters max, eg. f3.1):'
c          read(5,100) fmt1
          fmt1=' '
403       prompt='Enter format (6 characters max, eg. f3.1)'
          call askc(prompt,fmt1,ierr)
          if(ierr.eq.-2) go to 402
          write(fmt,105)fmt1,fmt1
c          print'(a\)',' Enter posting color (1=241,2=242,...15=255):'
c          read(5,*) icolor
          icolor=15
404       prompt='Enter posting color (1=241,2=242,...15=255)'
          call aski4(prompt,icolor,ierr)
          if(ierr.eq.-2) go to 403
          if(icolor.lt.1.or.icolor.gt.15) go to 402
c          print'(a\)',' Enter posting size (1=large, 2=medium, 3=small):
c     1'
c          read(5,*) isize
          isize=3
405       prompt='Enter posting size (1=large, 2=medium, 3=small)'
          call aski4(prompt,isize,ierr)
          if(ierr.eq.-2) go to 404
          if(isize.lt.1.or.isize.gt.3) go to 405
        else
          sym='@'
          icolor=15
          isize=3
c          print'(a\)',' Do you want to post text?:'
c          read(5,100) ans
c          if(ans.eq.'y'.or.ans.eq.'Y') then
          ians=0
406       prompt='Do you want to post text?'
          call aski4l(prompt,ians,ierr)
          if(ierr.eq.-2) go to 402
          if(ians.eq.1) then
c            print'(a\)',' Enter text (4 characters max):'
c            read(5,100) sym
            sym='+'
407         prompt='Enter text (4 characters max)'
            call askc(prompt,sym,ierr)
            if(ierr.eq.-2) go to 406
c            print'(a\)',' Enter text color (1=241,2=242,...15=255):'
c            read(5,*) icolor
            icolor=15
408         prompt='Enter text color (1=241,2=242,...15=255)'
            call aski4(prompt,icolor,ierr)
            if(ierr.eq.-2) go to 407
            if(icolor.lt.1.or.icolor.gt.15) go to 408
c            print'(a\)',' Enter text size (1=large, 2=medium, 3=small):'
c            read(5,*) isize
            isize=3
409         prompt='Enter text size (1=large, 2=medium, 3=small)'
            call aski4(prompt,isize,ierr)
            if(ierr.eq.-2) go to 408
            if(isize.lt.1.or.isize.gt.3) go to 409
          endif
        endif
c        print'(a\)',' Do you want to design a graphic symbol?'
c        read(5,100) ans
c        if(ans.eq.'y'.or.ans.eq.'Y') then
        ians=0
410     prompt='Do you want to design a graphic symbol?'
        call aski4l(prompt,ians,ierr)
        if(ierr.eq.-2) go to 402
        if(ians.eq.1) then
c    7     print'(a\)',' Enter the number of rows in the symbol:'
c          read(5,*) irows
c          print'(a\)',' Enter the number of columns in the symbol:'
c          read(5,*) icols
           irows=1
411        prompt='Enter the number of rows in the symbol'
           call aski4(prompt,irows,ierr)
           if(ierr.eq.-2) go to 410
           icols=1
412        prompt='Enter the number of columns in the symbol'
           call aski4(prompt,icols,ierr)
           if(ierr.eq.-2) go to 411
           if(irows*icols.gt.50) then
            print*,'Error: rows * columns must be less than 50.'
c            go to 7
            go to 411
          endif
c          print'(a\)',' Enter the row number for the center of the symbo
c     1l:'
c          read(5,*) ircent
          ircent=(irows+1)/2
413       prompt='Enter the row number for the center of the symbol'
          call aski4(prompt,ircent,ierr)
          if(ierr.eq.-2) go to 410
c          print'(a\)',' Enter the column number for the center of the sy
c     1mbol:'
c          read(5,*) iccent
          iccent=(icols+1)/2
414       prompt='Enter the column number for the center of the symbol'
          call aski4(prompt,iccent,ierr)
          if(ierr.eq.-2) go to 413
          print*
          print*,'Row values 0-f map to colors 240-255;'
          print*,'* maps to background.  Enter top row first.'
          print*
          do 8 j=1,irows
          print'(a\)',' Enter a row:'
          read(5,103) (G(i,j),i=1,icols)
    8     continue
        endif
        write(11,102) icolor,isize,irows,ircent,icols,iccent
        do 9 j=1,irows
        write(11,103) (G(i,j),i=1,icols)
    9   continue
        write(11,104)
c        print'(a\)',' Convert km to meters (for "None" projection)?:'
c        read(5,100) ans
        ians=0
415     prompt='Convert km to meters (for "None" projection)?'
        call aski4l(prompt,ians,ierr)
        if(ierr.eq.-2) go to 410
   10   continue
c        read(10,end=99) x,y,z
        call xioxyz('r',10,xyz,3,ierr)
        if(ierr.ne.0) go to 99
        if(ians.eq.1) then
c          x=1000.0*x
c          y=1000.0*y
          xyz(1)=1000.0*xyz(1)
          xyz(2)=1000.0*xyz(2)
        endif
        if(iansp.eq.1) then
c          write(11,fmt) z,y,x,z
          write(11,fmt) xyz(3),xyz(2),xyz(1),xyz(3)
        else
c          write(11,101) sym,y,x,sym
          write(11,101) sym,xyz(2),xyz(1),sym
        endif
        go to 10
  101   format(a5,2f16.6,1x,a5)
c  101   format(f3.1,2f16.6,1x,f3.1)
  102   format(43hTYPE = RECTANGLE+TEXT   ['*' does not plot],/,
     1  'PIXEL_RANGE = 1000.0 0.0 km',/,'COLORS = 1',/,
     2  '  9 = yellow',/,'TEXT_COLOR = ',i2,/,
     3  'TEXT_SIZE  = ',i2,/,'SYMBOL_ROWS = ',i2,'   HOT_SPOT  ',i2,/,
     4  'SYMBOL_COLS = ',i2,'   HOT_SPOT  ',i2,/,'BEGIN_SYMBOL')
  103   format(100(a1,1x))
  104   format('END')
  105   format('(',a6,',2f16.6,1x,',a6,')')
   99   stop
        end
