ECN No Name Newsletter: September, 1989

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

[previous article] [next article]

NCAR Graphics

Dave Dippon

NCAR graphics is a collection of routines that display scientific data. NCAR graphics routines are available on the Gould NP1, as well as the Sun 3 and 4. FORTRAN and C programs can be written to call these routines.

Capabilities of NCAR include:

  1. contour plots
  2. background grids
  3. histograms
  4. 2-d velocity fields
  5. 2-d and 3-d plots
  6. ezmaps (draws world and national maps)
  7. color and halftone plots.

A handy features of NCAR are the shell scripts, ncargf77 and ncargcc, that compile FORTRAN or C programs using NCAR graphics. These shell scripts free the user from having to include the executable libraries needed to use NCAR routines.

NCAR routines produce output in the form of a Computer Graphics Meta-file (CGM) that can be translated into a format for various devices. This translator, called ctrans, can produce PostScript, UNIX plot standard, and Tektronix output.

NCAR provides a group of routines called autograph that do a variety of 2-d plots. A simple example is below.

            autograph example shown here (ps.autograph)

% cat autograph.ex.f
C define data arrays
C
   real xdra(201), ydra(201,12)
C
C initialize gks.
C
  call opngks
C
C fill the data arrays.
C
   do 103 i=1,201
     xdra(i)= -1.+.02*float(i-1)
     if( i .gt. 101) xdra(i)=2. - xdra(i)
   do 101 j=1,10
     ydra(i,j)=float(j)*
 +  (sin(1.00000001-xdra(i)**2) \
     +cos(1.00001-xdra(i)**2))/10.
     if(i .gt. 101) ydra(i,j)= -ydra(i,j)
     ydra(i,11)= xdra(i)
     ydra(i,12)= xdra(i)*xdra(i)
 101    continue
 102   continue
C
C  draw the graph, using EZMXY.

   call ezmxy \
   (xdra,ydra,201,12,201,'Autograph Example$')
C    |    |    |  |   |      |
C    |    |    |  |   |      _plot title
C    |    |    |  |   |       (must end in $)
C    |    |    |  |   |_length of y array
C    |    |    |  |_number of curves
C    |    |    |_length of x array
C    |    |_y array
C    |_x array
C  close GKS
C
   call clsgks
C
   stop
C
   end
% ncargf77 autograph.ex.f -o autograph.ex
f77 autograph.ex.f -o autograph.ex \
/usr/ecn/ncar.dir/lib/libncarg.a  \
/usr/ecn/ncar.dir/lib/libncarg_gks.a  \
/usr/ecn/ncar.dir/lib/libncarg.a
Gould Common FORTRAN       UTX/32 Release 1.2A
Copyright (c) 1987 EPCL.  All Rights Reserved.
autograph.ex.f
   main program

   31 Lines Compiled
% autograph.ex
% ls gmeta
gmeta
% ctrans -d ps.mono gmeta > ps.autograph

% lpr -Pna -l ps.autograph
OUTPUT = "dippon" in NUC 140D (Apple LaserWriter)
%


NCAR also provides for routines to do various types of contour plots. This contour example was written by Scott Hucker.

                   Hucker example contour plot
                     shown here (ps.hucker)

% cat hucker.f
   dimension q(201,201)
   data tx/.3955/, ty/.9765/

C must call opngks before calling any other
C NCAR routine
   call opngks

   P=1.
   alpha=1.
   nu=.3

   xmin=0.
   xmax=10.
   zmin=0.
   zmax=10.
   xd=.1
   zd=0.1

   imax=ifix((xmax-xmin)/xd) + 1
   jmax=ifix((zmax-zmin)/zd) + 1
   print*,'imax is ',imax,'    jmax is ',jmax

   do 10 i=1,imax
   do 10 j=1,jmax

   x=xmin+xd*(i-1.)
   z=zmin+zd*(j-1.)
   q(i,j)=-P .br
    *( (   alpha*z*sin(alpha*x)*exp(-alpha*z)

%   + nu*cos(alpha*x)*(1.-alpha*z)*exp(-alpha*z)+nu))
 10  continue
   print*,'data array is finished'
   call gselnt(1)
C tick4 controls tick mark length and direction
   call tick4(-12,-8,-12,-8)
C              |   |   |  |_length minor ticks Y axis
C              |   |   |_length major ticks Y axis
C              |   |_length minor ticks X axis
C              |_length major ticks X axis
C
   call gselnt(0)
C conrec makes contours
C from a rectangular array
   call conrec .br
   (q,201,imax,jmax,0.,0.,0,0,0,0)
C   |  |  |     |   |  |  | | | |_indicates desired
C   |  |  |     |   |  |  | | |  dashed line pattern
C   |  |  |     |   |  |  | | |_extra info on plot
C   |  |  |     |   |  |  | |    (see manual)
C   |  |  |     |   |  |  | |_scaling factor
C   |  |  |     |   |  |  |_contour levels parameter
C   |  |  |     |   |  |_highest contour level
C   |  |  |     |   |_lowest contour level
C   |  |  |     |_number data values Y direction
C   |  |  |_number data values X direction
C   |  |_first dimension of q
C   |_array to be contoured
C
    call frame

C  must call clsgks before ending
C  program that call NCAR routines
    call clsgks

    end

% ncargf77 hucker.f -o hucker
f77 hucker.f -o hucker \
/usr/ecn/ncar.dir/lib/libncarg.a \
/usr/ecn/ncar.dir/lib/libncarg_gks.a \
/usr/ecn/ncar.dir/lib/libncarg.a
Gould Common FORTRAN       UTX/32 Release 1.2A
Copyright (c) 1987 EPCL.  All Rights Reserved.
hucker.f
   main program

   46 Lines Compiled
% hucker
 imax is    100    jmax is    100
 data array is finished
% ctrans -d ps.mono gmeta > ps.hucker

% lpr -Pna -l ps.hucker
OUTPUT = "dippon" in NUC 140D (Apple LaserWriter)
%

The next contour example shows how a sparse, irregularly spaced data set can be contoured. Also the sample program reads its data from a file.

                   contour2 example shown here

% 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
%
% ncargf77 contour2.f -o contour2
f77 contour2.f -o contour2 \
/usr/ecn/ncar.dir/lib/libncarg.a \
/usr/ecn/ncar.dir/lib/libncarg_gks.a \
/usr/ecn/ncar.dir/lib/libncarg.a
Gould Common FORTRAN       UTX/32 Release 1.2A
Copyright (c) 1987 EPCL.  All Rights Reserved.
contour2.f
   main program

   49 Lines Compiled
%
% contour2
 Mesh file name:
contour2.data
%
%
% ctrans -d ps.mono gmeta > ps.contour2

% lpr -Pna -l ps.contour2
OUTPUT = "dippon" in NUC 140D (Apple LaserWriter)
%

NCAR manuals are for sale in the Armory bookstore. ECN #734 NCAR--Autograph, A Graphics Utility sells for $5.95 and ECN #735 NCAR, User's Guide is $17.75. Questions concerning the use of NCAR or problems that arise with usage can be E-mailed to "ncar".

NOTE: In this article the postscript file was sized using the scale factor .13 or .15 to fit in a two column format.


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

[HTML Check] HTML