c cplot1.f c c
      program plotit
c
c    Program to provide plots of Sin(x)
c    Ascii Character plots go to terminal and file 'pplot.out'
c
c    John Mahaffy 1/25/95
c
      implicit none
      character line*72
      real x
      integer ip,i
      character xlabel*32,ylabel*32,title*32
      real fx
c
c   line    -   Character string loaded with a line of output
c   ip      -   Position in line for a function value
c   xlabel  -   Contains a label for the x-axis
c   ylabel  -   Contains a label for the y-axis
c   title   -   Contains a title for the plot
c
      open (11,file='pplot.out')
c
c   Label values of the y axis
c
      line=' '
      line(14:15)='-1'
      line(65:65)='1'
      write(*,*) line
      write(11,*) line
      line=' '
      line(11:13)='0.0'
c
c   Draw the y axis
c
      line(15:40)='+----+----+----+----+----+'
      line(41:65)=line(16:40)
c
c   Plot the value at x=0
c     
      ip= nint(25*sin(0.0))+40
c     
      line(ip:ip)='*'
      write(*,*) line
      write(11,*) line
      line=' '
c
c    Loop through and plot points for other x values
c
      do 50 i=1,60
         x=.1*i
c     
         ip=nint(25*sin(x))+40
c     
c     
         if(mod(i,10).eq.0) then
c     
            write(line(10:13),'(f4.1)') x
            line(40:40)='+'
         else
            line(10:13)=' '
            line(40:40)='|'
         endif
         line(ip:ip)='*'
         write(*,*) line
         write(11,*) line
 50      line(ip:ip)=' '
      close (11)
c
c   Drive a separate true graphics program (gnuplot)
c
c   First set up the command file for gnuplot
c
      xlabel='''x'''
      ylabel='''y'''
      title='''sin(x)'''
      open (12,file='gnuxy')
c
c   UnComment the next line if you are on an NCSA/BYU Telnet Session
c
c     write(12,*) 'set terminal tek40xx'
c
      write(12,*) 'set data style lines'
      line='set xlabel '//xlabel
      write(12,*)line
      line='set ylabel '//ylabel
      write(12,*)line
      line='set title '//title
      write(12,*)line
      write(12,*)'set nokey'
      write(12,*)'set xrange [0:6]'
      write(12,*) 'plot ''dataxy'' using 1:2'
      write (12,*) 'pause -1'
      close(12)
c
c   Generate x-y pairs for the graph
c
      open (12,file='dataxy')
      do 100 i=0,60
         x=.1*i
         fx=sin(x)
         write(12,*) x,fx
  100 continue
      close(12)
c
      print *, ' Hit the Return (Enter) key to continue'
c
c   Tell the system to run the program gnuplot
c   This call works on either IBM RS6000 or Sun, but is not part of
c   the Fortran standard.
c   Comment out the line if you aren't at a terminal with graphics
c
      call system ('gnuplot gnuxy')

      stop

      end
c
c c