#!/bin/csh
#-----------------------------------------------------------
#version: 3 April 1996
#
#             READ ME FIRST
#     This beta-test code is provided by R. Grotjahn.  It is a
#     shell program to illustrate use of ncar graphics by
#       creating an executable file; hence the program is run
#       while in a UNIX environment by typing the file name followed
#       by hitting "return."
#     shell script changes are needed to make the program run.
#       Look for UNIX script changes between successive lines 
#       starting with: # chg
#     you will also want to modify the FORTRAN code, see
#       READ ME SECOND.
#
#----------------------------------------

cat >! template.for << 'EOF'
c
c             READ ME SECOND
c      This is a script & fortran file to run a basic template of a
c       program to make contour plots of RANDOMLY LOCATED DATA.
c      Users of this script need to modify the unix commands at the
c       end of this file:  several cp commands in order to
c       direct program input and output to their own directory under
c       a name of their preference.  
c
c     
c      This program also illustrates a simple written output procedure
c       (commented out) as well as contour plotting.  See READ ME THIRD
c
c      Other notes:
c       don't forget to make your file executable: chmod u+x random.for
c
c
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c          READ ME THIRD
c          
c      your source code to plot a 2-d array of data goes here.
c        This routine uses CONRAN which needs 3 separate 1-d 
c        arrays for the data: separate arrays of the x & y locations 
c        of each data point and a corresponding array of the data values.
c        Most of your code goes between the first pair of lines 
c         that contain c repeated many times.  To
c        change the calls to the plot generation, make mods between
c        the next pair of lines containing c repeated many times.
c       
c      For the purpose of this shell example, arrays PSIP and PSI are created.
      PROGRAM Contour
c
      PARAMETER (Nx=30)
C      NX data points
      DIMENSION Y(Nx),X(NX), PS(nx)
      dimension iwk(31*nx),wk(13*nx)
C
      CHARACTER*11 CHRS
      PI=acos(-1.)
c      generate some scattered locations & data values using functions
      DO 1 I=1,NX
      X(I)=sin(pi*0.37*(i-1))
      y(i)=cos(pi*0.82*i)
      ps(i)=10.*(x(i)**2+exp(1.-y(i)**2))
    1 CONTINUE
c
c
c      FYI:
c
c    The next few lines are commented out and can be ignored, these lines
c         show an example set up for writing to a file called numric.dat
c      open(9,file='./numric.dat',
c     1    form='formatted',status='unknown')
c
c      some example output forms
c      write(9,*)'This is a test program'
c      ba=2.
c      write(9,19)ba
19      format(//,'The value of ba is',f5.1)
c      close(9)
c
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
C
C      NOW PLOT PSIP and PSI
C
c      start plot commands
      CALL OPNGKS
c
c      create a plot title 8 characters long
      WRITE(CHRs,'(11hrandom test)')
c      cint is the contour interval
c      using cint=0. tells ncar graphics to choose the contour interval
      cint=3.
c      cint=0.
      call RANPLOT(X,Y,ps,Nx,WK,IWK,CHRS,CINT)
c      end plot commands
      CALL CLSGKS
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
      stop
      end
c
c------------------------------------------------------------------
      SUBROUTINE RANPLOT(XD,YD,ZD,NDP,WK,IWK,CHRS,CINT)
      dimension xd(ndp),yd(ndp),zd(ndp),iwk(31*ndp)
      dimension wk(13*ndp),scarr(2000)
c      sub to make contour plot from data (zd) at variable locations
c         specified by xd,yd.   scarr, iwk & wk are work arrays.
c      sub calls frame and places a title passed through in
c         character variable chrs
c      ndp must be .ge. 4
      CHARACTER*11 CHRS
      CHARACTER*13 CHR
      CHARACTER*6 CHRd
c
C      ADD GRAPH TITLE
C      THE SET CALL IS FOR PLACEMENT OF THESE LABELS
      CALL SET(.1,.9,.1,0.9,0.,1.,0.,1.,1)
C      GRAPH TITLE CHRS PASSED THROUGH 
      CALL PLCHHQ(.5,.9,CHRS,12.,0.,0.)
C      CHR: EXAMPLE FOR ENCODING A VARIABLE USED IN A GRAPH LABEL (OPT.)
      WRITE(CHR,'(i4,9h data pts)')ndp
C      PLOT ANOTHER GRAPH LABEL CHR (OPT.)
      CALL PLCHHQ(.9,0.9,CHR,12.,0.,1.)
c
      call set(.3,.9,.1,.7,0.,1.,0.,1.,1)
c
c      set some options for conran
      if(cint.le.0.) call conop3('CIL=OFF',0.,0) !conran chooses contour int
      if(cint.gt.0.) call conop3('CIL=ON',cint,1) !user specifies contour int
c
      call conop3('DBP=ON',0.,1) ! contour break at data values =0.
      call conop4('DAS=LSS','$$$"""$$""',0,0) !dash values less than break
c
      call conop4('FMT=ON','(f8.2)',6,8) !format for data values plotted
c      call conop1('PDV=ON')  !turn on plotting of data values
      call conop1('PDV=OFF')  !turn on plotting of data values
c
      call conop2('SPD=ON',12) ! set size of data pt labels, default is 8
c
      call conop1('SCA=PRI') ! fit plot into last prior set call ranges
c
      call conran(xd,yd,zd,ndp,wk,iwk,scarr)
c
c      plot a symbol at each data point w/ data value above
      ymi=yd(1)
      yma=yd(1)
      do 2 i=2,ndp
      if(ymi.gt.yd(i)) ymi=yd(i)
      if(yma.lt.yd(i)) yma=yd(i)
    2 continue
c      next line allows plotting labels extending outside set call range
      call gsclip(0)
      ydel=0.03*(yma-ymi)
      do 1 i=1,ndp
      ylab=yd(i)+ydel
c       recommend that character declaration above for chrd be same
c            size as the number of characters to be plotted
      WRITE(CHRd,'(f6.2)')zd(i)  !format for printing data value
      call plchhq(xd(i),ylab,chrd,12.,0.,0.)    ! plot data pt value
      call plchhq(xd(i),yd(i),':KRL1:-',13.,0.,0.)  ! plot start symbol
    1 continue
      call frame
      return
      end
c------------------------------------------------------------------
c
'EOF'
#
ncargf77 template.for 
echo 'run job and create output file'
# nice sets a lower priority for background jobs
# adding a trailing (second) "&" says execute in a "background" type mode 
nice a.out >& output   # std out + std err to file output
# copy output to a specified file name
echo ' write output data to disk '
# chg: change next line to file name to your choice
cp output ./random.out
# chg-------^^^^^^^^^^^----------------------------------------
# write output data to a temp disk
echo ' write plot data to disk '
# next write any metafile that was created to a specified file
# chg: change next line to file name to your choice
cp gmeta  ./random.plt
# chg-------^^^^^^^^^^^---------------------------------------
# chg: change file name to your choice (default: not implemented)
#cp ./numric.dat ./random.dat
# chg--------------^^^^^^^^^^^---------------------------------
# remove exe file when done in case next time have compilatn errs
rm a.out
rm gmeta
# error exits to here
exit
# chg: change file name to your choice
cp log ./random.log
# chg--^^^^^^^^^^^^^--------------------------------------------








