RE: Question about scale of vector plot

From: NCAR G Talk (ncargt@XXXXXX)
Date: Wed Nov 12 1997 - 09:26:10 MST


>
> Hi there,
>
> This may sound like a stupid question. I am using
> VVECTR to plot cross-sectional vectors. The
> vertical axis is in pressure (1000 to 100 hPa),
> and the horizontal axis is in distance (0 to x km,
> it varies).
>
> The vertical component of the vector is in Pa/s,
> while the horizontal component is in m/s.
>
> I used the SET call to define the user and
> real coordinates.
>
> The problem is that I need to include a scale inset
> for the vectors like:
>
>
> ^
> 0.5 Pa/s |
> |_______>
>
> 30 m/s
>
> This, I can construct easily with another program.
> The problem is knowing what the scales are. NCAR
> graphics gives the magnitude of the maximum vector
> in "mixed" units.
>
> Of course, the appearence of the vectors
> depends on the aspect ratio, but here the aspect
> ratio is kind of meaningless since they're
> in different coordinates.
>
> If anybody has a solution, I appreciate your help.
>
> Thanks in advance for your help.
>
> Will

Dear Will,

We're enclosing a program below that shows how to create separate
legends for the U and V components of a VVECTR plot. Note that it uses
a couple of undocumented entry points. We should also point out that
the HLU VectorPlot object supports this feature in a well-documented
and relatively straight-forward manner. For some examples of creating
VectorPlots using HLUs and NCL, you can go to the URL:

http://ngwww.ucar.edu/ngdoc/ng/qsg/vector/vctrpltoview.html

For information on the HLUs in general, go to the URL:

http://ngwww.ucar.edu/ngdoc/ng/ngdochome.html

--NCAR Graphics Support

---------beginning of program----------------
C
C Example illustrating how to draw legends for a vector plot that
C show the horizontal and vertical vector components separately.
C Uses currently undocumented entry points, VVDRAW and VVTXLN.
C
C Enter the desired horizontal and vertical scaling factors on the
C same line at the prompt, decimal point required, e.g.:
C 1. 2.
C
C Open GKS, open workstation of type 1, activate workstation
C
      CALL GOPKS (6,IDUM)
      CALL GOPWK (1, 2, 1)
      CALL GACWK (1)
C
C Invoke demo driver
C
      CALL IRREX(IERR)
C
C Deactivate and close workstation, close GKS.
C
      CALL GDAWK (1)
      CALL GCLWK (1)
      CALL GCLKS
      STOP
      END
C
      SUBROUTINE IRREX (IERROR)
C
C
      PARAMETER (M=25,N=25)
      DIMENSION U(M,N), V(M,N)
C
C User-defined differential scaling factor common block
C
      COMMON /VVUSER/ USCALE, VSCALE
      SAVE /VVUSER/
C
      character *80 NUMSTR
C
C
C Specify the NDC coordinates for a plot title.
C
        DATA FX / 0.090909 /, FY / 0.976540 /
C
C Specify VELVCT arguments.
C
      DATA FLO/0./,HI/0./,NSET/0/,LENGTH/0/,ISPV/0/,SPV/0./
C
C Initialize scale factors
C
      YSCALE = 1.0
      WRITE (*,*) 'Enter U and V scale factors (use a decimal point):'
      READ (*,*) USCALE,VSCALE
C
C Initialize the error parameter.
C
      IERROR = 1
C
C Define a functionally specified test velocity field.
C
c
c find the maximum U and V component values with the array
C
      umax = 0.0
      vmax = 0.0
c
      DO 20 I=1,M
         X = .1*FLOAT(I-13)
         DO 10 J=1,N
            Y = .1*FLOAT(J-13)
            DZDX = 1.-2.*(X-.10)/((X-.10)**2+Y**2+.09)**2+
     1 2.*(X+.10)/((X+.10)**2+Y**2+.09)**2
            DZDY = 1.-2.*Y/((X-.10)**2+Y**2+.09)**2+
     1 2.*Y/((X+.10)**2+Y**2+.09)**2
            UVMAG = ALOG(SQRT(DZDX*DZDX+DZDY*DZDY))
            UVDIR = ATAN2(DZDY,DZDX)
            U(I,J) = UVMAG*COS(UVDIR)
            V(I,J) = UVMAG*SIN(UVDIR)
c
c find max u and v components
c
            if (umax .lt. abs(u(i,j))) umax = abs(u(i,j))
            if (vmax .lt. abs(v(i,j))) vmax = abs(v(i,j))
c
   10 CONTINUE
   20 CONTINUE
C
         CALL SET(0.1,0.8,0.1,0.8,1.0,100.0,1.0,100.0,1)
         CALL VVSETI('SET - Do-SET-Call Flag', 0)
         CALL VVSETR('XC1 -- Lower X Bound', 1.0)
         CALL VVSETR('XCM -- Upper X Bound', 100.0)
         CALL VVSETR('YC1 -- Lower X Bound', 1.0)
         CALL VVSETR('YCN -- Upper Y Bound', 100.0)
         CALL VVSETI('MAP - user-scaled mapping', 11)
c
c Don't display the normal maximum and minimum text blocks
c
         call vvsetc('mnt - turn off minimum text block',' ')
         call vvsetc('mxt - turn off maximum text block',' ')
         IDM=0
         RDM=0
         CALL GSPLCI(3)
         CALL VVINIT(U,M,V,M,RDM,IDM,M,N,RDM,IDM)
         CALL VVECTR(U,V,RDM,IDM,IDM,RDM)
c
         CALL GSPLCI(7)
C ====================================================================
C
c
c Get the magnitude and the NDC length of the maximum vector drawn
c
         call vvgetr('vmx - maximum vector magnitude', vmx)
         call vvgetr('dmx - ndc length of maximum vector',dmx)
c
c Set the vector positioning method so the vector tail is at the
c position specified by 'xb','yb'
c
         call vvseti('vpo - vector tail at specified point',1)
c
c Determine ndc length of umax and vmax based on ratio of vmx to dmx
c Note that you could use any desired reference magnitudes in place
c of umax and vmax. Also if your code pre-scales the U and V arrays
c you would of course not multiple by the scaling factors 'uscale' and
c 'vscale'
c
         ulen = (dmx / vmx) * umax * uscale
         vlen = (dmx / vmx) * vmax * vscale
C
C Set the User/NDC transformation to an identity
C

         call set(0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,1)
c
c Position the vertical max vector info above and left of center of the
c plot. The characters are drawn at size 'txthgt' as a fraction of the
c viewport width. You only need to worry about the first 5 parameters
c to VVDRAW. VVTXLN is a convenience routine that finds the first and
c last non-blank characters in a text string. It makes positioning
c text quite a bit easier. You can read about PLCHHQ in the man pages
c (you probably already know about it).
c
         txhgt=0.008
         yb = .85 - vlen / 2.0
         ye = .85 + vlen / 2.0
         xb = .4
         xe = .4
         call vvdraw(xb,yb,xe,ye,vlen,' ',0,0,0,0)
         write(numstr,'(f6.3,1x,a)') vmax,'V units'
         call vvtxln(numstr,80,ib,ie)
         call plchhq(.38,.857,numstr(ib:ie),txhgt,0,1.0)
         call plchhq(.38,.843,'Maximum Vertical Component',txhgt,0,1.0)
c
c Position the horizontal max vector info above and right of center of
c the plot.
C
         yb = .85
         ye = .85
         xb = .5 - ulen
         xe = .5
         call vvdraw(xb,yb,xe,ye,ulen,' ',0,0,0,0)
         write(numstr,'(f6.3,1x,a)') umax,'H units'
         call vvtxln(numstr,80,ib,ie)
         call plchhq(.52,.857,numstr(ib:ie),txhgt,0,-1.0)
         call plchhq(.52,.843,'Maximum Horizontal Component',
     + txhgt,0,-1.0)
C
         CALL FRAME
C
 100 CONTINUE
C
      IERROR = 0
      RETURN
C
      END
C
C-----------------------------------------------------------------------
C
      SUBROUTINE VVUMXY (X,Y,U,V,UVM,XB,YB,XE,YE,IST)
C
C This is a user modifiable routine that allows custom projections of
C the vector space. X and Y give the vector position within the domain
C of the data space. By default, this space is coincident with the
C grid space (i.e. 1 through dimension lengths of the U and V arrays).
C The vector endpoints are output in fractional coordinates (NDC space).
C Note that this is different from the old MXF and MYF routines, which
C output in 'plotter coordinate' space. It also differs from the
C Conpack routine CPMPXY, which returns values in user space.
C
C VVUMXY (Velocity Vector -- User Map X,Y) is called whenever
C the internal parameter MAP is set to a value other than 0, 1, or 2.
C
C Based on the magnitude and direction of the vector the start and
C ending points of the vector are returned in NDC space.
C
C Input parameters:
C
C X,Y -- vector position in the user coordinate system
C U,V -- vector components from the U,V arrays for this position
C UVM -- magnitude of the U,V components (supplied for convenience
C and efficiency - but note that many mappings do not need
C this value)
C
C Output parameters:
C
C XB,YB -- starting point of the vector in fractional coordinates
C (NDC space), before offset based on the value of the
C vector positioning parameter, VPO.
C XE,YE -- ending point of the vector in fractional coordinates
C (NDC space), before offset based on the value of the
C vector positioning parameter, VPO.
C IST -- status results of the mapping: 0 indicates success -- any
C non-zero value causes VVECTR to discard the vector at this
C location.
C
C The mapping common block: made available to user mapping routines
C
      COMMON /VVMAP/
     + IMAP ,
     + XVPL ,XVPR ,YVPB ,YVPT ,
     + WXMN ,WXMX ,WYMN ,WYMX ,
     + XLOV ,XHIV ,YLOV ,YHIV ,
     + SXDC ,SYDC ,NXCT ,NYCT ,
     + RLEN ,LNLG ,INVX ,INVY ,
     + ITRT ,IWCT ,FW2W ,FH2H ,
     + DVMN ,DVMX ,RBIG ,IBIG
C
      SAVE /VVMAP/
C
C Math constants
C
      PARAMETER (PDTOR = 0.017453292519943,
     + PRTOD = 57.2957795130823,
     + P1XPI = 3.14159265358979,
     + P2XPI = 6.28318530717959,
     + P1D2PI = 1.57079632679489,
     + P5D2PI = 7.85398163397448)
C
C --------------------------------------------------------------------
C
C Description of VVMAP contents:
C
C IMAP - value of the internal parameter 'MAP'
C XVPL,XVPR,YVPB,YVPT - the currently set viewport values. (GETSET
C arguments 1, 2, 3, and 4)
C WXMN,WXMX,WYMN,WYMX - the min and max boundaries of user coordinate
C space, (usually but not always equivalent to
C window coordinates). WXMN and WYMN are true
C minimum values even one or both axes is
C inverted. (i.e. WXMN = MIN of GETSET args 5,6;
C WYMN = MIN of GETSET args 7,8)
C XLOV,XHIV,YLOV,YHIV - min and max boundaries of the data space, by
C default equivalent to the array grid space.
C XLOV and YLOV are not necessarily less than
C XHIV and YHIV respectively.
C SXDC,SYDC - Scaling factors for converting vector component
C values into lengths in NDC space.
C NXCT,NYCT - Length of each dimension of the U and V
C component arrays.
C RLEN - Length of the maximum vector in user
C coordinates.
C LNLG - The linear/log mode (GETSET argument 9)
C INVX,INVY - User coordinates inversion flags:
C 0 - not inverted, 1 - inverted
C ITRT - value of the internal parameter TRT
C IWCT - not currently used
C FW2W,FH2H - scale factors for converting from fraction of
C viewport width/height to NDC width/height
C DVMN,DVMX - min/max vector lengths in NDC
C RBIG,IBIG - machine dependent maximum REAL/INTEGER values
C
C --------------------------------------------------------------------
C User-defined differential scaling factor common block
C
      COMMON /VVUSER/ USCALE, VSCALE
      SAVE /VVUSER/
C --------------------------------------------------------------------
C
C User scaled transformation
C
      IF (IMAP .EQ. 11) THEN

         IF (X .LT. WXMN .OR. X .GT. WXMX .OR.
     + Y .LT. WYMN .OR. Y .GT. WYMX) THEN
            IST=-5
            RETURN
         ENDIF
C IF (USCALE .EQ. 0.0 .AND. VSCALE .EQ. 0.0) THEN
c IST=-4
c RETURN
c ENDIF
         XB=CUFX(X)
         YB=CUFY(Y)
         XE=XB+U*SXDC*USCALE
         YE=YB+V*SYDC*VSCALE

      ELSE

         XB=CUFX(X)
         YB=CUFY(Y)
         XE=XB+U*SXDC
         YE=YB+V*SYDC

      END IF
C
C Done.
C
      RETURN
C
      END
---------end of program----------------



This archive was generated by hypermail 2b29 : Wed Jun 28 2000 - 09:45:40 MDT