ECN No Name Newsletter: May, 1989

The ECN No Name Newsletter is no longer being published. This is an archived issue.

[previous article] [next article]

CONTOUR Plots With NCAR

Dan Goldstein and Dave Dippon

NCAR Graphics is your answer to doing contour plots. Its capabilities range from a simple routine that plots a contour of a 2 dimensional array to a routine that does a contour of sparse irregular data. Below is an example of the simplest NCAR contouring routine. It takes only three arguments: the name of a two dimensional real array and the dimensions of the array. In this example I have written out a data file that is compatible with the CRC plot3d command. This way I can show a comparison between the contour plot and the 3D plot. The script follows to show the whole process.

(illustration shown here)

helios.ecn.purdue.edu% cat contour1.f
c data needs to be in 1D arrays
      real z(20,20)
      integer i,j
      real xx,yy,r
      open(unit=9,file='zfile')
C Generate and Z array..
     do 100 i=1,20
         xx = i - 20/2
         do 200 j=1,20
             yy = j - 20/2
             r = sqrt(xx*xx+yy*yy)
             if ( r .lt. .0001) then
                 z(i,j)  = 1.0
             else
                 z(i,j)  = sin(r)/r
                    endif
                    write (9,*)  z(i,j)
 200       continue
 100   continue
C OPEN GKS, OPEN WORKSTATION OF TYPE 1,
C ACTIVATE WORKSTATION
        CALL OPNGKS
C Call ezcntr to make a simple contour plot.
        CALL ezcntr(z,20,20)
C    DEACTIVATE AND CLOSE WORKSTATION, CLOSE GKS.
      CALL CLSGKS
        stop
        end
helios.ecn.purdue.edu% NCARgf77  contour1.f
f77  contour1.f /usr/ecn/NCAR.dir/lib/libncarg.a  \
  /usr/ecn/ncar.dir/lib/libncarg_gks.a  \
  /usr/ecn/ncar.dir/lib/libncarg.a -lm
contour1.f:
 MAIN:
helios.ecn.purdue.edu% ls a.out
a.out*
helios.ecn.purdue.edu% a.out
helios.ecn.purdue.edu% ls gmeta zfile
gmeta   zfile
helios.ecn.purdue.edu%ctrans -d ps.mono\
   gmeta>contour1.ps
helios.ecn.purdue.edu% lpr -Pna -l contour1.ps
OUTPUT = "goldsted" in NUC 140D (Apple LaserWriter)
helios.ecn.purdue.edu% plot3d size=20 z=zfile,a  \
    scfac=.5 -P | lpr -Pna -g
OUTPUT = "goldsted" in NUC 140D (Apple LaserWriter)
helios.ecn.purdue.edu% exit
helios.ecn.purdue.edu%
The routine for doing contour plots of sparse irregularly spaced data is called "conran". The data must be placed in three 1D real arrays. There are several parameters that can be set to modify how the contour is made. Four subroutines are available for changing parameters. They are "conop1", "conop2", "conop3" and "conop4". The number in the subroutine name corresponds to the number of arguments passed to that routine. The first argument is a character string that identifies which option is being changed. In the conran example below, the resolution was changed. So a call to "conop2" is made, where the first argument is "SSZ=ON" and the second argument is an integer number. A complete list of options is given in ECN #735 NCAR Graphics User's Guide or by typing "help NCAR" and selecting "conran".

(illustration shown here)

helios.ecn.purdue.edu% cat contour2.f
C This is an example of the NCAR routine conran
C The data to be plotted is read out of a file.
C The user is prompted for the data file name.
C  x y and z data needs to be in 1D arrays
      real xd(5000), yd(5000),fd(5000)
C stuff needed for conran workspace arrays
C wk space has to be 13*number of points.
C (5000 is max number of points)
      real wk(13*5000)
C scrarr work area needs to be resolution**2
C (see below: CALL conop2('SSZ=ON',resolution)
      real scrarr(30**2 )
C iwk (integer work space) has to be 31 * max number
C of data points
      integer iwk(31 * 5000)
      character *23 gfilen
C read grid data: the mesh file must contain first an
C integer specifying the number of points in the file
C and then x y and z data points in three columns
      write(6,*) 'Mesh file name:'
      read(5,1) gfilen
 1    format(a20)
      idev = 8
      open(idev,file=gfilen,status='old')
      rewind idev
      read(idev,*) ni
C the data is then put in three 1D arrays
        do 11 i = 1,ni
          read(idev,*) xd(i),yd(i),fd(i)
 11     continue
      close (idev)
C plot x y z using NCAR routine conran
C OPEN GKS, OPEN WORKSTATION OF TYPE 1,
C ACTIVATE WORKSTATION
        CALL OPNGKS
C set resolution default is 40 for a dense data set
        CALL conop2('SSZ=ON',30 )
C set contour increment by default NCAR calculates
        CALL conop3('CIL=ON',.01,1)
C title for plot
        CALL conop4('TLE=ON','Conran Example',14,0)
C Call the routine conran to make the contour plot
        CALL conran(xd,yd,fd,ni,wk,iwk,scrarr)
C frame in the plot
        CALL frame
C DEACTIVATE AND CLOSE WORKSTATION, CLOSE GKS.
        CALL CLSGKS
        stop
        end
helios.ecn.purdue.edu% nrargf77 contour2.f
f77 contour2.f  /usr/ecn/ncarg.dir/lib/libncarg.a  \
  /usr/ecn/ncar.dir/lib/libncarg_gks.a  \
  /usr/ecn/ncar.dir/lib/libncarg.a
contour2.f:
 MAIN:
helios.ecn.purdue.edu% ls a.out
a.out*
helios.ecn.purdue.edu% a.out
Mesh file name:
mesh
helios.ecn.purdue.edu% ls gmeta
gmeta
helios.ecn.purdue.edu% ctrans -d ps.mono \
   gmeta > contour2.ps
helios.ecn.purdue.edu% lpr -Pna -l contour2.ps
OUTPUT = "goldsted" in NUC 140D (Apple LaserWriter)
helios.ecn.purdue.edu% exit
helios.ecn.purdue.edu%
Hints for getting started with NCAR routines.
  1. All the manual pages can be accessed by typing "help ncar" from any Sun or Gould computer
  2. To compile a FORTRAN NCAR program use the command: ncargf77 file.f To compile a C NCAR program use the command: ncargcc For more info on these commands, type: "help ncar" and select ncargf77 or ncargcc
  3. Before using any NCAR routines you must always call the routine OPNGKS

    Before exiting you must always call the routine CLSGKS If you fail to call either of these, the plot will fail.

  4. To translate a meta file you use the command: ctrans -d device gmeta For more information on specific devices type: "help ncar" and select ctrans.


webmaster@ecn.purdue.edu
Last modified: Wednesday, 04-Mar-98 18:17:24 EST

[HTML Check] HTML