#!/bin/csh
#-----------------------------------------------------------
#version: 3 January 1997
#
#             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 can be 
#       as a UNIX command by typing the file name and 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 line plots of 1- & 2-d arrays.
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      Solid lines are illustrated
c     
c      This program also illustrates a simple written output procedure
c       as well line plotting.  See READ ME THIRD
c
c      Other notes:
c       don't forget to make your file executable: chmod u+x line.for
c
c
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
c         READ ME THIRD
c
c      your source code to generate the arrays goes between the 
c        first pair of lines 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 LINEPLOT
c
      PARAMETER (NY=5,Nx=41)
C      NY=GRID PTS IN Y, NX GRID PTS IN X, 
      DIMENSION F(NX),X(NX),PSI(NX,Ny)
C
      CHARACTER*8 CHRS
      COMMON /DOMAIN/ XWd,XEd,YSd,YNd
      PI=acos(-1.)
      FMIN=1.E36
      FMAX=-1.E36
      DO 1 I=1,NX
      X(I)=FLOAT(I-1)*0.1-2.
      F(I)=COS(PI*X(I))
      IF(F(I).GT.FMAX) FMAX=F(I)
      IF(F(I).LT.FMIN) FMIN=F(I)
      DO 1 J=1,NY
      PSI(I,J)=1.5*SIN(0.5*PI*X(I))*COS(PI*FLOAT(J)/3.-X(I)/3.)
    1 CONTINUE
C      DEFINE RANGES
      XW=X(1)
      XE=X(NX)
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 F and PSI
C
c      start plot commands
      CALL OPNGKS
C      FIRST, HERE ARE SOME SIMPLE PLOT ROUTINES THAT ARE EASY TO CALL
C    
C      NXP IS THE NUMBER OF POINTS TO BE PLOTTED: NXP IS .LE. NX
      NXP=NX
C      JUST PLOT F VS IT'S INTEGER INDEX
      CALL EZY(F,NXP,'F USING EZY$')
C      NOW PLOT F VS THE INDEPENDENT VARIABLE (=X)
      CALL EZXY(X,F,NXP,'F USING EZXY$')
C      NOW PLOT SEVERAL CURVES ON THE SAME PLOT, E.G. PSI ARRAY
C      MANY IS NUMBER OF CURVES TO BE PLOTTED: MANY IS .LE. NY
      MANY=NY
      CALL EZMY(PSI,NX,MANY,NXP,'PSI USING EZMY$')
C      AND FINALLY:
      CALL EZMXY(X,PSI,NX,MANY,NXP,'PSI USING EZMXY$')
C      BELOW ARE SOME SLIGHTLY BETTER PLOT PROCEDURES, USING "MANUAL" CALLS 
C      IN SUPPLIED ROUTINE PLOTLNS.  THERE ARE OTHER WAYS TO IMPROVE 
C       THE AESTHETICS OF YOUR PLOTS.
      g=1.
c      input ranges, neg values may be needed due to constraints of the
c        call to subroutine set in subroutine ploty (see note below)
c      these ranges are also used to label axes.
c      left & right edges of "x" range
      XWd=Xw
      XEd=Xe
c      note: the set call requires: xwd<xed
c
c      create a plot title 8 characters long
      WRITE(CHRs,'(8hF  GRAPH)')
c      create a plot and advance to the next page when done
      NYP=1     ! F IS 1-DIMENSIONAL
c      bottom & top edges of "f" range
      YSD=FMIN
      YND=FMAX
      CALL PLOTLN(F,NX,NXP,NYP,G,CHRS,X)
c      start creation of second plot, etc.
      WRITE(CHRs,'(8hPSI PLOT)')
c      bottom & top edges of "f" range
      YSd=-2.
      YNd=2.
      CALL PLOTLN(PSI,NX,NXP,NY,G,CHRS,X)
c
c      end plot commands
      CALL CLSGKS
c
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
      stop
      end
c
c------------------------------------------------------------------
c
      SUBROUTINE PLOTLN(PLTA,NDIM,NX,NY,G,CHRS,X)
c      While this sub can be used as is, you may wish to improve the
c       appearance of your plots by modifying it as you become 
c       familiar with ncar graphics.
c      This Sub plots array plta.  
c      Plot the first nx columns of the array plta which
c       is dimensioned to have ndim columns.  plot the first ny rows
c       which must be less than or equal to the dimensioned size of
c       plta in the main program.
c      g is an optional variable numeric label which could be encoded
c        using a write statement and plotted using a plchhq call.
c      chrs contains a short label that is passed through
C      X IS ARRAY OF INDEPENDENT VARIABLE 
C
      DIMENSION PLTA(NDIM,NY),X(NDIM)
      CHARACTER*8 CHRS
      CHARACTER*8 CHR
      CHARACTER*2 CHRLB
      COMMON /DOMAIN/ XW,XE,YS,YN
C      SET SPECIAL VALUE FOR CONTOURING TO AVOID GRID PTS WITH SPV VALUE
      CALL CPSETR('SPV',1.E36)
C      GSCLIP(0) CALL SO THAT WHAT IS OUTSIDE SET CALL RANGE IS ALLOWED
      CALL GSCLIP(0)
C      SET CALL USED TO DEFINE THE LOCATION OF PLOT ON MONITOR SCREEN
C      CALL SET(.2,.8,.25,.75,0.,1.,0.,1.,1)
C      NEXT 6 LINES NEEDED TO GET CNTR PLT TO FIT INSIDE SET RANGES
C      CALL SET(.2,.7,.25,.75,XW,XE,YS,YN,1)
      CALL SET(.1,.9,.35,.75,XW,XE,YS,YN,1)
C      NEXT LINE FINALLY DRAWS THE CONTOUR LINES
      DO 10 J=1,NY
C      NEXT CALL PUTS A NUMBER LABEL AT THE 10TH DATA POINT ON THE CURVE
C      CHR: EXAMPLE FOR ENCODING A VARIABLE USED IN A GRAPH LABEL (OPT.)
      IF(NX.LT.10) STOP 'PLOTLN LINE LABEL'
      WRITE(CHRLB,'(I2)')J
      CALL PLCHHQ(X(10),PLTA(10,J),CHRLB,12.,0.,0.)
      DO 11 I=2,NX
      CALL LINE(X(I-1),PLTA(I-1,J),X(I),PLTA(I,J))
   11 CONTINUE
   10 CONTINUE
C
C      NOW ADD VARIOUS LABELS AND TICK MARKS
C      AXES/PERIMETER LABELS
C      IF IX OR JY =1 USE RT EDGE OR TOP EDGE FOR LABELS
      IX=0
      JY=1
C      BORDER LABELS LETTER SIZE
      ISIZ=12
      JSIZ=12
C      IOR=0 FOR HORZ LABLS,  =1 FOR VERTICAL ORIENTED LABELS,
C      LABMOD ALSO SPECIFIES FORMAT OF LABELS, SIZE, ETC.
      CALL LABMOD('(F5.1)','(F5.1)',0,0,ISIZ,JSIZ,IX,JY,IOR)
c      CALL LABMOD('(F5.3)','(F5.3)',0,0,ISIZ,JSIZ,IX,JY,IOR)
C      NOW DETERMINE TYPE OF BORDER AROUND CONTOURS, E.G. A GRID, A BOX
C       WITH TICK MARKS, ETC.  SPECIFY IF TICK MARKS HAVE LABELS, ETC.
C      PLOT BORDER/LABELS,  1ST 4 ARGS OF GRIDAL LIKE OLD SUB PERIM
C      IG,JG =0 THEN LIKE PERIM, =1 THEN LIKE PERIML
      IG=0
      JG=0
      IF(G.GE.1.) THEN
      IG=1
      JG=1
      END IF
C      IGTYP =0 FOR GRID, =5 PERIMETR, =10 AXES, OTHER COMBS POSS.
      IGTYP=5
C      LAST 2 ARGS GRIDAL ARE INTERSECTN OF AXES IN X,Y VALUES
C      CALL GRIDAL(NX-1,0,NY-1,0,IG,JG,IGTYP,0.,0.)
      NX3=(NX-1)/3
      NY3=(NY-1)/3
C      CALL GRIDAL(NX3,3,NY3,3,IG,JG,IGTYP,0.,0.)
      XDIF=(XE-XW)/5.
      YDIF=(YN-YS)/5.
      NX3=IFIX(XDIF)+1
      NY3=IFIX(YDIF)+1
      CALL GRIDAL(NX3,5,NY3,5,IG,JG,IGTYP,0.,0.)
C      NOW ADD GRAPH TITLE AND OTHER LABELS
C      THE SET CALL IS FOR PLACEMENT OF THESE LABELS
      CALL SET(.05,.9,.05,.9,0.,1.,0.,1.,1)
C      GRAPH TITLE CHRS PASSED THROUGH 
      CALL PLCHHQ(.5,0.05,CHRS,12.,0.,0.)
C      PLOT ANOTHER GRAPH LABEL CHR (OPT.)
C      CHR: EXAMPLE FOR ENCODING A VARIABLE USED IN A GRAPH LABEL (OPT.)
      WRITE(CHR,'(5htime=,F3.1)')G
      CALL PLCHHQ(.5,0.1,CHR,12.,0.,0.)
      CALL FRAME
       RETURN
      END
c
c
'EOF'
#
ncargf77 -V -extend_source -show xref 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 ./line.out
# chg-------^^^^^^^^^^^----------------------------------------
# -V option on f77 creates compiled listing .l file copied next to .lst
cp template.l ./line.lst
# 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  ./line.plt
# chg-------^^^^^^^^^^^---------------------------------------
# chg: change file name to your choice (default: not implemented)
#cp ./numric.dat ./line.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 ./line.log
# chg--^^^^^^^^^^^^^--------------------------------------------








