TEMPLOTE

Version 1.1, December 1996, R.E. Ghosh


This program has the typical logical blocks of a program for
- preparing data
- asking the user to set/modify scale limits
- plotting data in a terminal window using two colours
- asking the user if he wishes a hardcopy output
- then looping back to request more data

Typical environment setup includes:

% setenv PGPLOT_DIR /usr/ill/lib
% setenv PGPLOT_FONT /usr/ill/lib/grfont.dat
% setenv PGPLOT_ILL_DEV_1 /XSERV
% setenv PGPLOT_ILL_DEV_2 /VPS
% setenv PGPLOT_ILL_PPAGE 2
% ln -s /usr/ill/lib/libpgplot511.a libpgplot.a
% ln -s /usr/ill/lib/librlib.a librlib.a


      program templote
c***** a template program using RLIB and PGPLOT libraries
c     program source is /usr/ill/doc/templote.f
c      to perform simple X,Y plots at ILL
c
c      PGPLOT A Scientific Graphics Library
c      copyright T.G. Pearson, California Institute of Technology
c      available for use freely for non-commercial use
c      with extensions (R. Ghosh, ILL) for keeping several
c      output devices open simultaneously PGNOPN, PGNSEL, PGNEND
c      reference   http://www.ill.fr/Computing/pgplotSS.html
c
c      RLIB A general utility library (R.Ghosh, ILL)
c      reference   http://www.ill.fr/data_treat/rlib.html
cUnix
c      in current directory 
c      ln -s /usr/ill/lib/libpgplot.a libpgplot.a
c      ln -s /usr/ill/lib/librlib.a librlib.a
c      f77 -o templote templote.f librlib.a libpgplot.a -lX11
c
cOpenVMS
c    $ @ILLCOM:pgplot5_logical
c    $ for templote.f  
c    $ link templote,illlib:rlib/lib,illlib:grpshr.olb/lib
c
      dimension x(101), y1(101), y2(101)
      dimension xlim(2), ylim(2), yy(202)
      character*50 text
      character*4 pnam
      equivalence(yy(1),y1(1)),(y2(1),yy(102))
c***** this program plots f(x) and f(x') vs x, on the same axes
c      in different colours, and then asks user if he
c      wants a hardcopy plot; the whole then repeats for another
c      set of function values
      pnam='tplt'
      text=' '
      xlim(1)=0.
      xlim(2)=10
      ylim(1)=0.
      ylim(2)=10.
      write(6,1)
1     format('Simple plotting test using PGPLOT and RLIB')
c***** prepare for plotting by opening output devices
      call pgnopn(1,' ',ier)
      if(ier.ne.0) stop 'Couldn''t open PGPLOT_ILL_DEV_1 device'
c***** this will use unit 1 for screen typically
      call pgnopn(2,pnam//'#',ier)
      if(ier.ne.0) stop 'Couldn''t open PGPLOT_ILL_DEV_2 device'
c***** this will be hardcopy, with a filename pnamnnn.xxx
c***** where nnn is a 3 digit number
c***** open devices defined by
c      environment variables (logical names) PGPLOT_ILL_DEV_1
c      environment variables (logical names) PGPLOT_ILL_DEV_2
c      typically PGPLOT_ILL_DEV_1 is set to /XSERV   X-window screen
c                PGPLOT_ILL_DEV_2 is set to /VPS     PostScript file
c***** prepare to plot data on screen
      call pgnsel(1,last,ier)
      if(ier.ne.0) stop 'PGNSEL_1'
100   write(6,2)
2     format(
     1' Give q for plotting sin(qx) and sin(qx)/qx (0 to stop  : ',$)
      read(5,*) q
      if(q.le.0) go to 999
c***** set up data for superposed curves
      npt=101
      do 10 i=1,101
      x(i)=(i-1)/2. +.00001
      y1(i)=sin(q*x(i))
      y2(i)=sin(q*x(i))/(q*x(i))
10    continue
      write(text,6) q
6     format(' Y(green)=sin(qx) Y(red)=sin(qx)/qx q=',f5.1)
c***** let user set scale limits in general case
      call lims('X',xlim,x,101)
      call lims('Y',ylim,yy,202)
c***** plot data on screen
      call myplot(x,y1,y2,npt,text,xlim,ylim)
      write(6,3)
3     format(' Hardcopy (y) :',$)
      read(5,4) ans
4     format(a)
      if(ans.eq.'y'.or.ans.eq.'Y') go to 5
      go to 100
5     call pgnsel(2,last,ier)
      if(ier.ne.0) stop 'PGNSEL_2'
      call myplot(x,y1,y2,npt,text,xlim,ylim)
c
c***** if autometic output of hardcopy has been defined
c      by defining an environment variable for the print command
c      PGPLOT_ILL_PRINT_CMD
c      then calling pgend(2,ier) here will close file and print
c
c  e.g. % setenv PGPLOT_ILL_PRINT_CMD "lpr -Plpps"
c  or   $ DEFINE PGPLOT_ILL_PRINT_CMD "PRINT/QUE=LRP1_ILL4"
c
c     call pgnend(2)
c
c     call pgnopn(2,pnam//'#',ier)
c***** to reopen new output file...for next picture
c
      call pgnsel(last,llast,ier)
      if(ier.ne.0) stop 'PGNSEL_3'
      go to 100
c***** reset to screen output
999   continue
c***** close all output devices
      call pgnend(1)
      call pgnend(2)
      end
      subroutine myplot(x,y1,y2,npt,text,xlim,ylim)
c      simple routine to superpose line plots of y1,y2 versus x
c      input x,y1,y2,npt,text
c      xlim min and max x-scale, ylim  min and max of y-scale 
      dimension x(npt),y1(npt),y2(npt),xlim(2),ylim(2)
      character*(*) text,xtxt*20,ytxt*20
      xtxt='  x values '
      ytxt='  y values '
c***** plot scales and titles
      call rsplt(xlim,ylim,ylim,2,0,0,xtxt,ytxt,text)
c***** set to green (3)
      call pgqci(isave)
      call pgsci(3)
c***** continuous line added
      call rsplt(x,y1,y1,npt,-100,0,xtxt,ytxt,text)
c***** second curve in red (2) added
      call pgsci(2)
      call rsplt(x,y2,y2,npt,-100,0,xtxt,ytxt,text)
      call pgsci(isave)
c***** reset default colours
      return
      end
      subroutine lims(str,xy,val,npt)
c      displays and sets limits for scales
c      input str  (character) title
c      val real array length npt data values
c      xy real array 2 input as scale limits, returned as new
c      values or unchanged
      dimension xy(2),val(npt)
      character*(*) str
      xmax= -1e30
      xmin= 1e30
      do 1 i=1,npt
      if(val(i).gt.xmax) xmax=val(i)
      if(val(i).lt.xmin) xmin=val(i)
1     continue
10    write(6,2) str,xy,xmin,xmax
2     format(1x,a/' Scale limits : ',g12.4,'  to  ',g12.4/
     1            ' Data  range  : ',g12.4,'  to  ',g12.4//
     1' Give new scale limits or type / to continue : ',$)
      read(5,*) xy
      if(xy(2).gt.xy(1)) return
      write(6,3) xy
3     format(' Minimum value ',g12.4,' is not less than maximum',g12.4)
      go to 10
      end