Previous Chapter Tutorial Home Next ChapterThe contour line basics section covers drawing lines and setting contour line attributes (like line pattern, color, thickness, and level values) for simple line contour drawings and for contour drawings with filled contour levels.
In the Conpack functional outline, note that setting contour line attributes and drawing the lines may require you to set parameters in two places, and then call a contour drawing routine.
----------------------------------------------------------
1. Open GKS
2. Set window and viewport
3. Put in titles and other labels
* 4. Set up general parameters
5. Set up area maps
6. Initialize Conpack
* 7. Force Conpack to choose contour levels if necessary
* 8. Modify Conpack-chosen parameters
9. Draw labels
10. Draw background
* 11. Draw contour lines
12. Call FRAME
13. Close GKS
----------------------------------------------------------
* Steps discussed in this section.

To change a single contour line attribute, it is necessary to specify the contour line you want to modify, then set the appropriate Conpack parameters using the CPSETx routines.
This module discusses the routine CPCLDR; it draws contour lines across the entire contour rectangle.
CPCLDM (the other routine) is discussed in the masking areas modules Cp 5.5 and Cp 5.6. CPCLDM is used with the Areas utility to draw contours over a specified region of the contour rectangle; it should be used with non-default contour line labels.

1 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK) 2 CALL CPCLDR (Z, RWRK, IWRK)
CALL CPCLDR (Z, RWRK, IWRK)
If you are using irregularly spaced data or sparse data, it is extremely important to pass your regularly spaced data array to CPCLDR. Otherwise, you will get incorrect results.
If your data all have the same values, in other words, if you have a constant data field, CPCLDR writes out a constant field message on your CGM and does not draw any contours.

After Conpack chooses the contour level values, then you can change their values or even add new contour levels. You must first force Conpack to choose contour levels using CPPKCL, and then retrieve the number of contour levels before modifying the levels using the same parameters Conpack uses by default. Information about modifying the contour level values chosen by Conpack appears in the modifying Conpack-chosen levels modules Cp 4.7 and Cp 4.8.
The third method you can use to decide how many contour levels are drawn is to set CLS to the negative of the number of contour levels that you want. When this method is used, the minimum and maximum data values are located, and contours are drawn at n equal intervals over the range of the data. This method may produce contours at inconvenient or "ugly" values; this is discussed in module "Cp 4.9 Setting n equally spaced contour levels."
The most reliable way to get contours where you want them is to set all of them yourself, using the CLS, NCL, PAI, CLV, and CLU parameters. This method is discussed in module "Cp 4.10 Choosing your own contour levels."

CALL CPSETI ('CLS', icls)

1 DATA CIT /1., 2., 3., 4., 5., 6., 7., 8., 9., 0./
2 DATA LIT /2, 2, 2, 2, 2, 2, 2, 2, 2, 0/
3 CALL OPNGKS
4 DO 101, I=1, 10
5 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
6 CALL CPSETR ('CIT - CONTOUR INTERVAL TABLE', CIT(I))
7 CALL CPSETI ('LIT - LABEL INTERVAL TABLE', LIT(I))
8 101 CONTINUE
9 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
10 CALL CPBACK (Z, RWRK, IWRK)
11 CALL CPCLDR (Z, RWRK, IWRK)
CPSETI ('PAI', n)
CPSETR ('CIT', cit)
CPSETI ('LIT', lit)
----------------------- PAI CIT(PAI) LIT(PAI) ----------------------- 1 1.0 5 2 2.0 5 3 2.5 4 4 4.0 5 5 5.0 5 6 0.0 0 7 0.0 0 8 0.0 0 9 0.0 0 10 0.0 0 -----------------------
Line labels are discussed further in sections "Cp 7. General labels" and "Cp 6. Contour line labels."

1 CALL CPSETR ('CIS - CONTOUR INTERVAL SPECIFIER', 15.)
2 CALL CPSETI ('LIS - LABEL INTERVAL SPECIFIER', 2)
3 CALL CPSETR ('CMN - CONTOUR MINIMUM', -5.)
4 CALL CPSETR ('CMX - CONTOUR MAXIMUM', 75.)
5 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
6 CALL CPBACK (Z, RWRK, IWRK)
7 CALL CPCLDR (Z, RWRK, IWRK)
CALL CPSETR ('CIS', cis)
CALL CPSETI ('LIS', lis)
CALL CPSETR ('CMN', cmn)
CALL CPSETR ('CMX', cmx)
Line 1 sets CIS to 15., then line 2 specifies labels on every other line. Lines 3 and 4 set the low and high contour levels to -5. and 75. Contours are set to n*CIS+CMN (in this case -5., 10., 25., ...).
If you set CIS, you must also specify LIS to get contour line labels.

1 CALL CPRECT (ZREG, K, M, N, RWRK, LRWK, IWRK, LIWK)
2 CALL CPPKCL (ZREG, RWRK, IWRK)
3 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NOCL)
4 CALL CPSETI ('NCL - NUMBER OF CONTOUR LEVELS', NOCL+1)
5 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', NOCL+1)
6 CALL CPSETR ('CLV - CONTOUR LEVEL VALUES', 0.0)
CALL CPPKCL (ZREG, RWRK, IWRK)
If the contour level selection parameter CLS is zero, CPPKCL does nothing. If the data field is found to be essentially constant by the initialization routines, (the constant field flag CFF<>0), then CPPKCL does nothing.
Calling CPPKCL sets the number of contour levels parameter NCL to the number of contour levels picked. Elements 1 through NCL of the parameter array CLV (contour level values) are set to the levels themselves. The Ith elements of the associated parameter arrays are set as follows:
------------------------------------------------- CLU=1 or 3 Contour level use flag LLT=' ' (single blank) Contour line label text CLD='$$$$$$$$$$$$$$$$' Contour line dash pattern CLC=-1 Contour line color LLC=-1 Contour line label color CLL = 0. Contour line line width -------------------------------------------------Thus, after CPPKCL is called, the situation for each contour level is as follows:

1 CALL CPRECT (ZREG, K, M, N, RWRK, LRWK, IWRK, LIWK)
2 CALL CPPKCL (ZREG, RWRK, IWRK)
3 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NOCL)
4 CALL CPSETI ('NCL - NUMBER OF CONTOUR LEVELS', NOCL+1)
5 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', NOCL+1)
6 CALL CPSETR ('CLV - CONTOUR LEVEL VALUES', 0.0)
CALL CPSETI ('NCL', ncl)
CALL CPSETI ('PAI', ipai)
CALL CPSETR ('CLV', clv)

1 CALL CPSETI ('CLS - CONTOUR LEVEL SELECTION FLAG', -10)
2 CALL CPRECT (Z, M, M, N, RWRK, LRWK, IWRK, LIWK)
3 CALL CPBACK (Z, RWRK, IWRK)
4 CALL CPCLDR (Z, RWRK, IWRK)
CALL CPSETI ('CLS', icls)
Line 1 of the ccpncls.f code segment sets the CLS parameter; the value 10 tells Conpack to use exactly ten contour lines at equally spaced intervals. Contours are then initialized and drawn normally.
Notice that in this case, contour line labels are not drawn. The only way to get contour labels drawn using this technique is to set the CLU parameter for the specific lines that you want labeled. This option is discussed in section "Cp 6. Contour line labels."

1 DATA RLEVEL /-20., -10., -5., -4., -3., -2., -1., 0., 1., 2., 3., 4.,
+ 5., 10., 20., 30., 40., 50., 100. /
2 CALL CPSETI ('CLS - CONTOUR LEVEL SELECTION FLAG', 0)
3 CALL CPSETI ('NCL - NUMBER OF CONTOUR LEVELS', INCL)
4 DO 10, I=1, INCL
5 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
6 CALL CPSETR ('CLV - CONTOUR LEVEL VALUES', RLEVEL(I))
7 IF (AMOD (RLEVEL(I), 5.) .EQ. 0)
+ CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
8 10 CONTINUE
9 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
10 CALL CPBACK (Z, RWRK, IWRK)
11 CALL CPCLDR (Z, RWRK, IWRK)
CALL CPSETI ('CLS', cls)
CALL CPSETI ('NCL', ncl)
CALL CPSETI ('PAI', i)
CALL CPSETR ('CLV', clv)

1 DATA IBTS / 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
2 1 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
3 2 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0,
4 3 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0,
5 4 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,
6 5 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1,
7 6 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 /
8
9 CALL CPSETI ('CLS - CONTOUR LEVEL SELECTION FLAG', -7)
10 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
11 CALL CPPKCL (Z, RWRK, IWRK)
12 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NOCL)
13 DO 11, I=1, NOCL
14 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
15 CALL CPSETI ('CLD - CONTOUR LINE DASH PATTERN', IPAT (IBTS (1, I)))
16 11 CONTINUE
17 CALL CPBACK (Z, RWRK, IWRK)
18 CALL CPCLDR (Z, RWRK, IWRK)
CALL CPSETI ('PAI', i)
CALL CPSETI ('CLD', icld)
CALL CPSETC ('CLD', 'string')
When CLD is an integer array, the dash pattern relies on a 16-bit binary number where each 1 produces a dash and each 0 produces a space. You need to choose a dash pattern in binary, like "1111000011110000", then convert it to decimal:
CALL CPSETI ('CLD', 61680)
In this scenario, a solid line has the value 65535. Note that CLD is set with the CPSETI routine in this case. When CLD is a character expression array, the dash pattern allows you to make patterns of nearly any Fortran character. Dollar signs ($) are used to specify dashes, and single quotation marks (') are used to specify blanks. So, to get the same dash pattern as in the DASHDB example:
CALL CPSETC ('CLD',
+ '$$$$''''''''$$$$''''''''')
Note that when you set CLD with a character string, you need to call CPSETC. Also, since CLD is an array, you must use PAI with CLD and set a dash pattern for each contour line to be drawn. Three elements of CLD, with negative array indices, allow you to modify some lines that are not contour lines:
------------------------------------------------------
PAI CLD
------------------------------------------------------
-1 Specifies a dash pattern for the edge of the grid
-2 Specifies a dash pattern for the edge of any area
filled with special values (SPV)
-3 Specifies a dash pattern for the edge of any area
in which CPMPXY returns an out-of-range
value (ORV)
------------------------------------------------------
Dash patterns are assigned to contour levels in the order of the CLD array, not contour level value. For example, if you assign:
---------------------------------- CLD[1] = short dashes CLV[1] = 6. CLD[2] = long dashes CLV[2] = 4. CLD[3] = solid CLV[3] = 5. ----------------------------------your lowest contour line (4.0), has a long dash pattern, your middle contour line (5.0) is solid, and your highest contour line (6.0) has a short dash pattern.
Lines 1 through 7 of the ccpcld.f code segment declare the binary bit patterns that we want to convert into decimal for use as dash patterns. Line 9 forces Conpack to use only seven contour lines since we'll only define seven dash patterns. Line 10 initializes Conpack, and line 11 picks the contour levels so that we can change their dash patterns. Line 12 retrieves the number of contour levels so that the code is more flexible, and lines 13 through 16 set a different dash pattern for each contour line.
Line 15, the heart of this process, first retrieves one of the dash patterns, then converts it to a decimal number using a function discussed later in this module. Then the contour line dash pattern is set using Conpack parameter CLD as an integer array. Line 17 draws a background, and line 18 draws contours.
In many cases, it can be cumbersome to convert from a 16-bit binary number to a decimal number. You can make this conversion with the UNIX command dc if you want to hard-wire your dash patterns. Or you can use this Fortran function to construct dash patterns inside your program:
INTEGER FUNCTION IPAT (IBTS)
INTEGER IBTS (16)
IPAT = 0
DO 101, I=1, 16
IPAT=IOR(ISHIFT(IPAT,1),IBTS(I))
101 CONTINUE
RETURN
END
IBTS is an integer array in which you store each element of your 16-bit binary pattern. ISHIFT(M,N) is a function supplied with NCAR Graphics that shifts M left by N bits. IOR(K,L) is an NCAR Graphics-supplied function that does a logical "or" of K and L. The function IPAT is included in the ccpcld example.

1 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
2 CALL CPPKCL (Z, RWRK, IWRK)
3 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCON)
4 DO 11, I=1, NCON
5 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
6 CALL CPSETR ('CLL - CONTOUR LINE LINE WIDTH', REAL (I) / 3.)
7 11 CONTINUE
8 CALL CPBACK (Z, RWRK, IWRK)
9 CALL CPCLDR (Z, RWRK, IWRK)
CALL CPSETI ('PAI', i)
CALL CPSETR ('CLL', cll)
--------------------------------------------
CLL(-1) Specifies a line width for the edge
of the grid.
CLL(-2) Specifies a line width for the edge
of any area filled with special
values.
CLL(-3) Specifies a line width for the edge
of any area in which CPMPXY
returns an out-of-range value.
--------------------------------------------
---------------------------- CLL[1] = thin CLV[1] = 6. CLL[2] = thick CLV[2] = 4. CLL[3] = medium CLV[3] = 5. ----------------------------

1 CALL COLOR
2 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
3 CALL CPPKCL (Z, RWRK, IWRK)
4 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCON)
5 DO 11, I=1, NCON
6 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
7 CALL CPGETR ('CLV - CONTOUR LEVEL VALUES', CVAL)
8 IF (CVAL .LT. 0.0) THEN
9 CALL CPSETI ('CLC - CONTOUR LINE COLOR INDEX', 1)
10 ELSE IF (CVAL .EQ. 0.0) THEN
11 CALL CPSETI ('CLC - CONTOUR LINE COLOR INDEX', 2)
12 ELSE
13 CALL CPSETI ('CLC - CONTOUR LINE COLOR INDEX', 3)
14 ENDIF
15 11 CONTINUE
16
17 SUBROUTINE COLOR
18 CALL GSCR (1, 0, 0., 0., 0.)
19 CALL GSCR (1, 1, 1., 0., 0.)
20 CALL GSCR (1, 2, 0., 1., 0.)
21 CALL GSCR (1, 3, 0., 0., 1.)
CALL CPSETI ('PAI', i)
CALL CPSETI ('CLC', iclc)
---------------------------------------
CLC(-1) Specifies a line color for the
edge of the grid.
CLC(-2) Specifies a line color for the
edge of any area filled with
special values.
CLC(-3) Specifies a line color for the
edge of any area in which
CPMPXY returns an out-of
-range value.
---------------------------------------
Line 2 initializes Conpack, and line 3 forces contour lines to be chosen so they can be modified. Line 4 gets the number of contour levels, so that we can choose a color for each contour line using the DO loop beginning in line 5. Since in this case we want to be sure that line color is correlated to contour level value, we get the contour level value in line 7, and use it in the if block to assign red to lines with negative values, green to the zero line, and blue to lines above zero. After setting contour line colors, we draw contours normally.

1 CALL CPSETI ('CLS - CONTOUR LEVEL SELECTION FLAG', 0)
2 CALL CPSETI ('NCL - NUMBER OF CONTOUR LEVELS', 40)
3 DO 11, I=1, 40
4 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
5 CALL CPSETR ('CLV - CONTOUR LEVEL VALUES', 5.0 * REAL(I) - 15.)
6 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', MOD (I, 4))
7 11 CONTINUE
8 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
9 CALL CPBACK (Z, RWRK, IWRK)
10 CALL CPCLDR (Z, RWRK, IWRK)
CALL CPSETI ('CLU', iclu)
---------------------------------------------
CLU(-1) Specifies a flag for the edge of the
grid.
CLU(-2) Specifies a flag for the edge of any
area filled with special values.
CLU(-3) Specifies a flag for the edge of any
area in which CPMPXY returns an
out-of-range value.
---------------------------------------------
----------------------- PAI CLV(PAI) CLU(PAI) ----------------------- 1 -10.0 1 2 -5.0 2 3 0.0 3 4 5.0 0 5 10.0 1 6 15.0 2 -----------------------Also notice that contour level 10.0 is a solid line, contour level -5.0 is labeled but not drawn, contour level 0.0 is drawn and labeled, and contour level 5.0 is neither drawn nor labeled, in accordance with the CLU parameter.
Hence, line 1 of the ccpclu.f code segment tells Conpack that we will choose the contour levels. Line 2 sets the number of contour levels to 40, and lines 3 through 7 assign contour level values and set the CLU parameter to cycle through each of its four options. Lines 8 through 10 draw contours normally.
Before you fill areas using Ezmap, you need to initialize Areas with the Areas initialization routine. You then initialize Ezmap with some special Ezmap initialization routines. Finally, you can fill regions you defined with Ezmap by calling the Areas routine ARSCAM. You fill contour levels with Conpack and Areas in exactly the same way.
----------------------------------------------------------
1. Open GKS
2. Set window and viewport
3. Put in titles and other labels
* 4. Set up general parameters
* 5. Set up area maps
* 6. Initialize Conpack
* 7. Force Conpack to choose contour levels if necessary
* 8. Modify Conpack-chosen parameters
* 9. Draw labels
10. Draw background
* 11. Draw contour lines
12. Call FRAME
13. Close GKS
----------------------------------------------------------
* Steps discussed in this section.

CALL CPSETI ('AIA', iaia)
CALL CPSETI ('AIB', iaib)
-----------------------------------------------
PAI AIA
-----------------------------------------------
-1 Specifies the area identifier for the area
outside the edge of the grid
-2 Specifies an area identifier for any
region filled with special values
-3 Specifies an area identifier for any area
in which CPMPXY returns the out-of
-range-value ORV
-----------------------------------------------
If AIA=AIB=0 for a particular contour level, then that level is ignored by the CPCLAM subroutine when it adds contour levels to the area map. Otherwise, that contour level is added to the area map, and AIA and AIB are used as the area identifiers for each side of the contour line.
When you let Conpack choose contour levels, then AIA(I)=I+1, and AIB(I)=I, where I is the Ith contour level. We use this automatic numbering of contour levels in the next module.
Note: If you set the elements of AIA and AIB manually, you should make sure that they are consistent. In other words, if the contour levels with nonzero values of AIA and AIB are c1, c2, ... cn, where c1 < c2 < ... < cn, and ak is the area identifier above ck, and bk is the area identifier below ck, then for all 1<=k<=n-1, ak = bk+1. Otherwise you will confuse the Areas utility, and strange results will occur.
Some hardware devices will fail when attempting to fill an area that is defined by too many points. To reduce the number of points in any given area, you can define vertical strips, and then fill the areas within these strips. As you specify more strips, you reduce the number of points that define any given area in a contour level.

1 CALL CPSETI ('NVS - NUMBER OF VERTICAL STRIPS', 3)
2 CALL CPRECT (ZDAT, 23, 23, 14, RWRK, LWRK, IWRK, LWRK)
3
4 SUBROUTINE FILL (XCRA, YCRA, NCRA, IAREA, IGRP, NGRPS)
5 IFILL = 0
6 DO 101, I=1, NGRPS
7 IF (IGRP(I) .EQ. 3) IFILL = IAREA(I)
8 101 CONTINUE
CALL CPSETI ('GIC', igic)
CALL CPSETI ('GIL', igil)
CALL CPSETI ('GIS', igis)
CALL CPSETI ('NVS', nvs)
Notice that line 1 of the ccpvs.f code segment sets the number of vertical strips to 3. Then line 2 initializes Conpack normally. Vertical strips are usually invisible when finished, but in this example, they are given different color shades to emphasize them for you to study.
GIC, GIL, and GIS must be set before any call to CPCLAM or CPLBAM so they will be effective; this is discussed in the next module. Occasionally you may want to set GIC and GIL because you have another edge group that is already assigned to group 3. However, unless you need to change GIC, GIL, or GIS, it is recommended that you do not change their values.

1 EXTERNAL FILL
2 CALL COLOR
3 CALL ARINAM (MAP, LMAP)
4 CALL CPSETI ('CLS - CONTOUR LEVEL SELECTION FLAG', NCL)
5 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK)
6 CALL CPCLAM (ZREG, RWRK, IWRK, MAP)
7 CALL GSFAIS (1)
8 CALL ARSCAM (MAP, XWRK, YWRK, NWRK, IAREA, IGRP, NOGRPS, FILL)
9 CALL CPBACK (ZREG, RWRK, IWRK)
10 CALL CPLBDR (ZREG, RWRK, IWRK)
11 CALL CPCLDR (ZREG, RWRK, IWRK)
CALL ARINAM (MAP, LMAP) CALL CPRECT (ZREG, K, M, N, RWRK, + LRWK, IWRK, LIWK) CALL CPSPS1 (ZSPS, KSPS, MSPS, + NSPS,RWRK, LRWK, IWRK, LIWK,ZREG, + LZRG) CALL CPSPS2 (XSPS, YSPS, ZSPS, + KSPS,MSPS, NSPS, RWRK, LRWK, + IWRK, LIWK, ZREG, LZRG) CALL CPCLAM (ZREG, RWRK, IWRK, MAP)
The contour lines added to the area map are as specified by the first NCL (Number of Contour Lines) elements of the parameter arrays CLV, AIA, and AIB. If NCL is zero, CPPKCL is called to generate these values.
If, for a given value of I between 1 and NCL inclusive, the Ith element of either AIA or AIB is nonzero, then the contour lines specified by the Ith element of CLV are added to the area map, with the Ith element of AIA as the area identifier for the area "above" each line (where field values are greater than they are along the line), and with the Ith element of AIB as the area identifier for the area "below" each line (where field values are less than they are along the line).
If a given contour level occurs twice in the array CLV, then the desired value of AIA may be associated with one contour level, and the desired value of AIB may be associated with the other contour level that has the same value.
If the parameter T2D (Tension on 2-Dimensional splines) has a nonzero value, the contour lines are smoothed, using cubic splines under tension.
Four other types of lines are added to the area map by CPCLAM:
Lines are added to the area map in the following order:
If, during the last call to CPRECT, CPSPS1, or CPSPS2, the data being contoured were found to be essentially constant, then no contour lines are added to the area map; however, the other lines are added.
Line 1 of the ccpfil.f code segment declares the fill routine to be external so we can pass it into ARSCAM. Line 3 initializes Areas. Line 4 sets the number of contour levels to a fixed value, in this case 15, or the number of colors defined in the color table.
Line 5 initializes Conpack, and line 6 adds the contour lines to the area map. Line 7 sets the interior fill style to be solid so that we don't get hollow fill, and line 8 fills the contour levels using the Areas routine ARSCAM. Lines 9 through 11 draw a perimeter, labels, and contour lines.

1 EXTERNAL FILL 2 CALL COLOR 3 CALL ARINAM (MAP, LMAP) 4 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK) 5 CALL CPCLAM (ZREG, RWRK, IWRK, MAP) 6 CALL CPLBAM (ZREG, RWRK, IWRK, MAP) 7 CALL GSFAIS (1) 8 CALL ARSCAM (MAP, XWRK, YWRK, NWRK, IAREA, IGRP, NOGRPS, FILL) 9 CALL CPBACK (ZREG, RWRK, IWRK) 10 CALL CPLBDR (ZREG, RWRK, IWRK)
CALL CPLBAM (ZREG, RWRK, IWRK, MAP)
Line 1 of the ccplbam.f code segment declares the fill routine to be external so that it can be passed to ARSCAM. Line 2 sets up our color table. Lines 3 through 6 initialize Areas, initialize Conpack, add contour lines to the area map, then add label boxes to the area map. Lines 7 and 8 color-fill the contour levels. Lines 9 and 10 draw a perimeter and labels.

1 EXTERNAL FILL
2 EXTERNAL CPDRPL
3
4 CALL CPSETI ('LLP - LINE LABEL POSITIONING', 2)
5 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK)
6 CALL ARINAM (MAP, LMAP)
7 CALL CPLBAM (ZREG, RWRK, IWRK, MAP)
8 CALL CPLBDR (ZREG, RWRK, IWRK)
9 CALL CPCLAM (ZREG, RWRK, IWRK, MAP)
10 CALL ARSCAM (MAP, XWRK, YWRK, NWRK, IAREA, IGRP, NOGRPS, FILL)
11 CALL CPCLDM (ZREG, RWRK, IWRK, MAP, CPDRPL)
CALL CPCLDM (ZREG, RWRK, IWRK, MAP, + MASK)
Each such polyline lies in precisely one of the areas defined by the area map. The MASK routine may use the information provided by its arguments (that describe the area the polyline is in) to decide whether or not to draw the polyline.
The contour lines generated are those specified by the first NCL elements of the parameter arrays CLV and CLU. If NCL is zero, CPPKCL is called to generate these values. Each element of CLV specifies a contour level and the corresponding element of CLU specifies whether or not contour lines are to be generated at that level. If the parameter T2D has a nonzero value, the contour lines are smoothed, using cubic splines under tension.
If the element of the parameter array CLU corresponding to PAI=-1 is nonzero, the edge of the grid is also generated. If the element of CLU corresponding to PAI=-2 is nonzero, the edges of special-value areas (if any) are generated. If the element of CLU corresponding to PAI=-3 is nonzero, the edges of out-of-range areas (if any) are generated. By default, none of these edges are generated.
Groups of lines are generated in the following order:
Before and after each group of lines is generated, the routine CPCHCL is called; a user-supplied version of this routine may override the settings for color, dash pattern, and line width. Also, of course, the routine MASK, which actually does the drawing, may override the settings of these quantities.
Conpack's Dash Pattern Use parameter DPU affects the pattern used to draw the lines. When DPU<=0, lines are drawn by calling the SPPS routine CURVE. The lines are all solid and unlabeled and specified dash patterns are not used. When DPU>0, lines are drawn by calling the Dashline routine CURVED. Lines are solid or dashed, depending on the dash pattern specified by the appropriate element of CLD.
If LLP=1 or LLP=1, then the dash pattern for the lines to be labeled is constructed by replicating, DPU times, the dash pattern specified by the appropriate element of CLD, and then appending to it the characters specified by the appropriate element of LLT. If LLP=1 or LLP=1, then label boxes are not created for contour line labels.
If, during the last call to CPRECT, CPSPS1, or CPSPS2, the data being contoured were found to be essentially constant, then no contour lines are generated. Instead, the constant-field label is written. Other lines are still generated.
Lines 1 and 2 of the ccpcldm.f code segment declare the fill and masking routines to be external so that they can be passed into ARSCAM and CPCLDM respectively. Line 4 chooses the regular labeling scheme so that label boxes can be drawn. Lines 5 and 6 initialize Conpack and Areas respectively.
Lines 7 and 8 add labels to the area map, then draw them. Similarly, line 9 adds contour lines to the area map, and line 11 draws them. By filling the contour levels before drawing the contour lines, we ensure that the contour lines are visible in the final plot.

1 IDR=1 2 DO 101, I=1, NAI 3 IF (IAI(I) .LT. 0) IDR=0 4 10 CONTINUE 5 IF (IDR .NE. 0) THEN 6 IF (IDUF .EQ. 0) THEN 7 CALL CURVE (XCS, YCS, NCS) 8 ELSE 9 CALL CURVED (XCS, YCS, NCS) 10 ENDIF 11 ENDIF 12 RETURN 13 END
CALL CPDRPL (XCS, YCS, NCS, IAREA, + IGRP, NGRP)
If the only reason you are using CPCLDM instead of CPCLDR is to avoid drawing contour lines through labels, follow these steps:
The code in the ccpdrpl example is taken from the default version of CPDRPL. Note that lines 1 through 4 of the ccpdrpl.f code segment first check for a negative area identifier, then turn off line drawing if it is negative. If the area identifier is positive (it's not in a label box or outside the perimeter), then line 6 checks to see if Conpack is drawing using Dashline, then draws the contour line in a way consistent with how the parameters are set.

1 EXTERNAL SFILL
2 EXTERNAL CPDRPL
3
4 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK)
5 CALL CPPKCL (ZREG, RWRK, IWRK)
6 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCL)
7 DO 111, I=1, NCL
8 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
9 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
10 CALL CPSETI ('AIA - AREA IDENTIFIER ABOVE', 0)
11 CALL CPSETI ('AIB - AREA IDENTIFIER BELOW', 0)
12 111 CONTINUE
13 CALL CPSETI ('NCL - NUMBER OF CONTOUR LEVELS', NCL + 2)
14 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', NCL + 1)
15 CALL CPSETR ('CLV - CONTOUR LEVEL VALUES', 1.25)
16 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
17 CALL CPSETI ('AIA - AREA IDENTIFIER ABOVE', 1)
18 CALL CPSETI ('AIB - AREA IDENTIFIER BELOW', 2)
19 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', NCL + 2)
20 CALL CPSETR ('CLV - CONTOUR LEVEL VALUES', 1.5)
21 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
22 CALL CPSETI ('AIA - AREA IDENTIFIER ABOVE', 3)
23 CALL CPSETI ('AIB - AREA IDENTIFIER BELOW', 1)
24 CALL CPCLAM (ZREG, RWRK, IWRK, MAP)
25 CALL ARSCAM (MAP, XWRK, YWRK, NWRK, IAREA, IGRP, NOGRPS, SFILL)
26 CALL CPCLDM (ZREG, RWRK, IWRK, MAP, CPDRPL)
CALL ARSCAM (MAP, XCS, YCS, MCS, + IAREA, IGRP, ISIZ, FILL)
Lines 1 and 2 of the ccpscam.f code segment are required so that Fortran knows that the fill and contour line drawing routines are subroutines. Line 4 initializes Conpack, and line 5 forces contour lines to be chosen so that we can modify contour line information. Line 6 retrieves the number of contour levels, and lines 7 through 12 turn on contour line drawing and contour line labels for every line. They also turn off area identifier information for all contour lines. It is necessary to turn off area identifier information in this case because when we add the contour lines to shade between, we need to override Conpack's default area identifiers.
Line 13 tells Conpack that we're adding two new contour lines. Line 15 sets the value for the first new contour line at 1.25, and line 20 sets the value for the second at 1.5. Notice that Conpack has already chosen a contour line at 1.5. Conpack doesn't mind that it now has two contour lines with the same value. Because we set the area identifiers to zero for the contour at 1.5 that Conpack chose, Areas overrides those values with the new area identifiers that we set in lines 22 and 23. Notice that the area identifier for the area above the contour at 1.25 is set to 1 in line 17, and that the area identifier for the area below the contour at 1.5 is also set to 1 in line 23. It is critical that these two values match for correct area fill.

1 SUBROUTINE SFILL (XWRK, YWRK, NWRK, IAREA, IGRP, NGRPS)
2
3 REAL XWRK(*), YWRK(*), ISCR(5000)
4 INTEGER IAREA(*), IGRP(*), RSCR(5000)
5
6 DO 10, I=1, NGRPS
7 IF (IGRP(I) .EQ. 3) IAREA3 = IAREA(I)
8 10 CONTINUE
9 IF (IAREA3 .EQ. 1) THEN
10 CALL SFSETR ('SP - SPACING BETWEEN FILL LINES', .006)
11 CALL SFNORM (XWRK, YWRK, NWRK, RSCR, 5000, ISCR, 5000)
12 ENDIF
13 RETURN
14 END
SUBROUTINE APR (XWRK, YWRK, NWRK, + IAREA, IGRP, NGRPS) DIMENSION XWRK(*), YWRK(*) DIMENSION IAREA(*), IGRP(*)
RETURN END
Calls to set up contour line labels appear in four places in the Conpack functional outline:
----------------------------------------------------------
1. Open GKS
2. Set window and viewport
3. Put in titles and other labels
* 4. Set up general parameters
5. Set up area maps
6. Initialize Conpack
7. Force Conpack to choose contour levels if necessary
* 8. Modify Conpack-chosen parameters
* 9. Draw labels
10. Draw background
* 11. Draw contour lines
12. Call FRAME
13. Close GKS
----------------------------------------------------------
* Steps discussed in this section.

1 CALL CPRECT (Z, M, M, N, RWRK, LRWK, IWRK, LIWK) 2 CALL CPBACK (Z, RWRK, IWRK) 3 CALL CPLBDR (Z, RWRK, IWRK)
CALL CPLBDR (ZREG, RWRK, IWRK)
Line 1 of the ccplbdr.f code segment initializes Conpack. Line 2 draws a perimeter, and line 3 draws labels using CPLBDR. Notice that we don't call CPCLDR in this program. By not calling CPCLDR, contour lines are never drawn. Also, by not drawing the contours before calling CPLBDR to draw labels, the information label in the bottom right corner of the plot fails to get the information it needs to label minimum and maximum values as well as contour interval.

1 CHARACTER*16 STRING
2 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
3 CALL CPPKCL (Z, RWRK, IWRK)
4 CALL CPPKLB (Z, RWRK, IWRK)
5 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NOCL)
6 DO 10, I=1, NOCL
7 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
8 CALL CPGETR ('CLV - CONTOUR LEVEL VALUES', CLVL)
9 WRITE (STRING, 5) CLVL
10 CALL CPSETC ('LLT - LINE LABEL TEXT STRING', STRING)
11 10 CONTINUE
12 CALL CPBACK (Z, RWRK, IWRK)
13 CALL CPCLDR (Z, RWRK, IWRK)
14 5 FORMAT ('Contour at ', F5.3)
CALL CPPKLB (ZREG, RWRK, IWRK)
If the constant field found flag CFF is nonzero, indicating that the data were found to be essentially constant on the last call to CPRECT, CPSPS1 or CPSPS2, CPPKLB does nothing. Otherwise, CPPKLB examines the first NCL elements of the parameter array CLV (which defines the contour levels) and the associated parameter arrays, looking for levels that are to be labeled (CLU = 2 or 3) for which no label is specified (LLT = ' '). (The value of LLT is a single blank.) If any such levels are found, CPPKLB generates labels for them.
SFU, the scale factor used parameter, may be set as a by-product of choosing the labels. SFU and SFS, the scale factor selector parameter, are described in section "Cp 10. Conpack parameter descriptions." After calling CPPKLB, a user program may examine the generated labels and change them in various ways.
Line 2 of the ccpklb.f code segment initializes Conpack, and line 3 forces contour levels to be chosen. Line 4 forces labels to be picked so that we can modify those labels. Lines 6 through 8 retrieve each value of the contour lines, then the label is changed in line 10 to the string created in line 9. Lines 12 and 13 draw a perimeter and contour lines.

1 DATA CIT /1., 2., 3., 4., 5., 6., 7., 8., 9., 0./
2 DATA LIT /2, 2, 2, 2, 2, 2, 2, 2, 2, 0/
3 CALL OPNGKS
4 DO 101, I=1, 10
5 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
6 CALL CPSETR ('CIT - CONTOUR INTERVAL TABLE', CIT(I))
7 CALL CPSETI ('LIT - LABEL INTERVAL TABLE', LIT(I))
8 101 CONTINUE
9 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
10 CALL CPBACK (Z, RWRK, IWRK)
11 CALL CPCLDR (Z, RWRK, IWRK)
CALL CPSETI ('PAI', n)
CALL CPSETR ('CIT', cit)
CALL CPSETI ('LIT', lit)
CALL CPGETI ('LIU', liu)
------------- PAI CIT LIT ------------- 1 1.0 5 2 2.0 5 3 2.5 4 4 4.0 5 5 5.0 5 6 0.0 0 7 0.0 0 8 0.0 0 9 0.0 0 10 0.0 0 -------------
Lines 1, 2, and 4 through 7 of the ccpcit.f code segment set CIT so that "nice" values are the same as they were in the old CONREC routine. LIT is set up to force every other contour level to be labeled no matter what. Lines 9 through 11 draw contours normally.

1 CALL CPSETR ('CIS - CONTOUR INTERVAL SPECIFIER', 15.)
2 CALL CPSETI ('LIS - LABEL INTERVAL SPECIFIER', 2)
3 CALL CPSETR ('CMN - CONTOUR MINIMUM', -5.)
4 CALL CPSETR ('CMX - CONTOUR MAXIMUM', 75.)
5 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
6 CALL CPBACK (Z, RWRK, IWRK)
7 CALL CPCLDR (Z, RWRK, IWRK)
CALL CPSETR ('CIS', cis)
CALL CPSETI ('LIS', lis)
Line 1 of the ccpcis.f code segment sets CIS to 15., then line 2 specifies labels on every other line. Lines 3 and 4 set the low and high contour levels to -5. and 75. Contours are set to n*CIS+CMN (in this case -5., 10., 25., ...).
The CMN and CMX parameters are documented in module "Cp 4.6 Default contour level selection: Fixed contour intervals and labels."

1 CALL CPSETI ('CLS - CONTOUR LEVEL SELECTION FLAG', 0)
2 CALL CPSETI ('NCL - NUMBER OF CONTOUR LEVELS', 40)
3 DO 11, I=1, 40
4 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
5 CALL CPSETR ('CLV - CONTOUR LEVEL VALUES', 5.0 * REAL (I) - 15.)
6 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', MOD (I, 4))
7 11 CONTINUE
8 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
9 CALL CPBACK (Z, RWRK, IWRK)
10 CALL CPCLDR (Z, RWRK, IWRK)
CALL CPSETI ('CLU', iclu)
----------------------- PAI CLV(PAI) CLU(PAI) ----------------------- 1 -10.0 1 2 -5.0 2 3 0.0 3 4 5.0 0 5 10.0 1 6 15.0 2 -----------------------Also notice that contour level -10.0 is a solid line, contour level -5.0 is labeled but not drawn, contour level 0.0 is drawn and labeled, and contour line 5.0 is neither drawn nor labeled, in accordance with the CLU parameter.
Line 1 of the ccpclu.f code segment tells Conpack that we will choose the contour levels. Line 2 sets the number of contour levels to 40, and lines 3 through 7 assign contour level values and set the CLU parameter to cycle through each of its four options. Lines 8 through 10 draw contours normally.

CALL CPSETI ('LLP', llp)
Also note that when you set LLP=1 or LLP=-1, the labels are actually included in the contour line. The other schemes perform the line labeling separate from the line drawing, and so should be used with the Areas utility to prevent writing over contour lines.

1 CALL CPRECT (Z, K, M, N, RWRK, LRWK, IWRK, LIWK)
2 CALL CPBACK (Z, RWRK, IWRK)
3 CALL CPPKCL (Z, RWRK, IWRK)
4 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCL)
5 DO 10, I=1, NCL
6 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
7 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
8 10 CONTINUE
9 CALL CPSETI ('RWC - REAL WORKSPACE FOR CONTOURS', 125)
10 CALL CPCLDR (Z, RWRK, IWRK)
CALL CPSETI ('RWC', irwc)
Lines 1 and 2 of the ccprwc.f code segment initialize data and draw a background. Lines 3 through 8 force contour line labels to be turned on for each line. Line 9 sets RWC so that some contour labels are drawn and some are not, and line 10 draws the lines and labels.
The amount of real workspace that Conpack is allowed to use for coordinates of points on contour lines is determined by the value of the RWC parameter. By default, each contour line is drawn in pieces of no more than RWC points each. If you have a very dense grid, this means that the contour lines are drawn in rather short chunks (short as measured in NDCs).
Dashline restarts the dash pattern at the beginning of each chunk. What happens is that each chunk is of just the right length so that the dash pattern "$$$$$$$$0" never puts out a single "0," but the dash pattern "$$$$$$$$5" which is on a much longer line, does eventually write out a single "5."
By setting RWC=250, the size of the chunks doubles, and you start getting more labels.
Notice that if you increase RWC too much, you eventually have to make the real workspace larger.

1 CALL CPSETI ('LLP - LINE LABEL POSITIONING', 2)
2 CALL CPSETR ('RC1 - REGULAR SCHEME CONSTANT 1', .1)
3 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK)
4 CALL CPPKCL (ZREG, RWRK, IWRK)
5 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCONS)
6 DO 12, I=1, NCONS
7 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
8 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
9 12 CONTINUE
10 CALL CPLBDR (ZREG, RWRK, IWRK)
CALL CPSETR ('RC1', rc1)
CALL CPSETR ('RC2', rc2)
CALL CPSETR ('RC3', rc3)
You can call CPLBAM to add label boxes for contour line labels to the area map; this prevents contour lines from passing through the labels. This is discussed in module "Cp 5.4 Adding label boxes to the area map."
Line 1 of the ccprc.f code segment tells Conpack that we want the moderately expensive labeling scheme. Line 2 sets the distance from the beginning of the contour line to the first label to be small, so that even short contour lines will be labeled. Line 3 initializes Conpack, and lines 4 through 9 force labeling of every line so that you can see the full effect of the labeling option. Line 10 draws the labels with a call to CPLBDR. You must use CPLBDR to draw labels when using the regular scheme for labeling.

You can call CPLBAM to add label boxes for contour line labels to the area map; this prevents contour lines from passing through the labels. This is discussed in module "Cp 5.4 Adding label boxes to the area map."
The penalty scheme is controlled by the ten parameters PC1, PC2, PC3, PC4, PC5, PC6, PW1, PW2, PW3, and PW4. These constants are briefly described here as needed, and complete descriptions appear in the following modules.
The penalty scheme uses seven tests to determine if a point on a contour line is unacceptable as a location for a label. The point P on a contour line is rejected as the center point of a label under these conditions:
Conpack places labels at points on a contour line where PFUN is minimized. Because of the number of parameters involved, each term of the penalty function is discussed in separate modules. This module describes the gradient term.
-------------------------------------------------------------
PFUN= Term
-------------------------------------------------------------
PW1 * GRAD / (GRAV + PC1 * GRSD) Gradient
+ PW2 * ENCB / PC2 Crossing contours
+ PW3 * CDIR / PC3 Tight curves
+ PW4 * MIN (1 - EXP {-[(D(I)-PC4)/PC5]2}) Optimum distance
-------------------------------------------------------------

1 CALL CPSETI ('LLP - LINE LABEL POSITIONING', 3)
2 CALL CPSETR ('PC1 - PENALTY SCHEME CONSTANT 1', 3.0)
3 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK)
4 CALL CPPKCL (ZREG, RWRK, IWRK)
5 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCONS)
6 DO 12, I=1, NCONS
7 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
8 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
9 12 CONTINUE
10 CALL CPLBDR (ZREG, RWRK, IWRK)
CPSETR ('PC1', pc1)
CPSETR ('PW1', pw1)
PW1 * GRAD / (GRAV + PC1 * GRSD)where GRAD is the estimated gradient at the point P, GRAV is the average gradient over the whole field being contoured, and GRSD is the standard deviation of the estimated gradients over the whole field. PC1 specifies, as a multiple of the standard deviation, how far the gradient at point P is allowed to be from the average gradient before it prevents P from being considered as a label position. And PW1 specifies the weight of the gradient term in the penalty function.
This means that labels are not placed on steep slopes going down, nor on steep slopes going up. If you want labels on the steep slopes, you have two choices: you can either make PC1 larger or you can set PW1=0.0. By increasing PC1, you increase the steepness of a slope that can be labeled. By decreasing PW1, you reduce the importance of the slope in the labeling scheme.
To simplify the weighting of terms, the base part of each term is always between 0.0 and 1.0 inclusive. 0.0<=GRAD/(GRAV+PC1*GRSD)<=1.0. If you want to make the gradient term twice as important as the other terms in the penalty function, set PW1=2.0, and PW2, PW3, and PW4=1.0. Or, if you only care about making sure that labels are not placed on the steep parts of fields, set PW1=1.0, and PW2, PW3, and PW4=0.0.
Line 1 of the ccppc1.f code segment chooses the penalty scheme labeling option by setting LLP=3. Line 2 sets the gradient constant so that any lines on a steep slope may be labeled. Line 4 initializes Conpack. Lines 5 through 9 turn on line labeling for every line. Notice that line 10 draws labels by calling CPLBDR; penalty scheme labels must be drawn with CPLBDR.
Conpack places labels at points on a contour line where PFUN is minimized. Because of the number of parameters involved, each term of the penalty function is discussed in separate modules. This module describes the crossing contours term.
-------------------------------------------------------------
PFUN= Term
-------------------------------------------------------------
PW1 * GRAD / (GRAV + PC1 * GRSD) Gradient
+ PW2 * ENCB / PC2 Crossing contours
+ PW3 * CDIR / PC3 Tight curves
+ PW4 * MIN (1 - EXP {-[(D(I)-PC4)/PC5]2}) Optimum distance
-------------------------------------------------------------

1 CALL CPSETI ('LLP - LINE LABEL POSITIONING', 3)
2 CALL CPSETR ('PC2 - PENALTY SCHEME CONSTANT 2', 1.0)
3 CALL CPSETR ('PW2 - PENALTY SCHEME WEIGHT 2', 1.0)
4 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK)
5 CALL CPPKCL (ZREG, RWRK, IWRK)
6 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCONS)
7 DO 12, I=1, NCONS
8 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
9 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
10 12 CONTINUE
11 CALL CPLBDR (ZREG, RWRK, IWRK)
CPSETR ('PC2', pc2)
CPSETR ('PW2', pw2)
In many senses, the gradient and "crossing contours" terms of the penalty function represent the same thing. Any locations where contour lines are close enough together for labels to cross them are also regions having a relatively steep slope.
To simplify the weighting of terms, the base part of each term is always between 0.0 and 1.0 inclusive. In other words, 0.0<=ENCB / PC2<=1.0. If you want to make the crossing contours term twice as important as the other terms in the penalty function, set PW2=2.0, and PW1, PW3, and PW4=1.0. Or, if you only care about making sure labels do not cross contour lines, set PW2=1.0, and PW1, PW3, and PW4=0.0.
By default, PW2=0.0; this allows labels to cross any number of contour lines. If you want to change it so that labels are unlikely to cross contour lines, set PW2>=1.0, and PC2=1.0, as shown in the ccppc2.f code segment.
Line 1 of the ccppc2.f code segment chooses the penalty scheme labeling option by setting LLP=3. Line 2 sets the crossing contours constant so that labels do not cross contour lines. Line 3 changes the weighting function so that this option is observed. Line 4 initializes Conpack. Lines 5 through 10 turn on line labeling for every line. Notice that line 11 draws labels by calling CPLBDR; penalty scheme labels must be drawn with CPLBDR.
Conpack places labels at points on a contour line where PFUN is minimized. Because of the number of parameters involved, each term of the penalty function is discussed in separate modules. This module describes the "tight curves" term.
-------------------------------------------------------------
PFUN= Term
-------------------------------------------------------------
PW1 * GRAD / (GRAV + PC1 * GRSD) Gradient
+ PW2 * ENCB / PC2 Crossing contours
+ PW3 * CDIR / PC3 Tight curves
+ PW4 * MIN (1 - EXP {-[(D(I)-PC4)/PC5]2}) Optimum distance
-------------------------------------------------------------

1 CALL CPSETI ('LLP - LINE LABEL POSITIONING', 3)
2 CALL CPSETR ('PC3 - PENALTY SCHEME CONSTANT 3', 10.0)
3 CALL CPSETR ('PW3 - PENALTY SCHEME WEIGHT 3', 2.0)
4 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK)
5 CALL CPPKCL (ZREG, RWRK, IWRK)
6 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCONS)
7 DO 12, I=1, NCONS
8 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
9 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
10 12 CONTINUE
11 CALL CPLBDR (ZREG, RWRK, IWRK)
CALL CPSETR ('PC3', pc3)
CALL CPSETR ('PW3', pw3)
PW3 * CDIR / PC3where CDIR is the cumulative change in the direction of the contour line in a circular region centered at the point P with a radius equal to half of the largest dimension of the label. PC3 specifies the largest such cumulative change allowed in degrees. The illustration shows that CDIR is the sum of the angles specifying the change in direction of the contour inside the label circle (CDIR=a+b+c+d+e+f+g+h+i, where c, f, and g are zero in the illustration).
By default, PC3=60.0, so a contour line cannot bend more than 60 degrees within the diameter of the label if a label is to be placed at that point. The idea is that labels should not cover up interesting details of contour lines.
To simplify the weighting of terms, the base part of each term is always between 0.0 and 1.0 inclusive. In other words, 0.0 <= CDIR / PC3 <= 1.0. If you want to make the tight curves term twice as important as the other terms in the penalty function, set PW3=2.0, and PW1, PW2, and PW4=1.0. Or, if you only care about making sure that labels are not placed on tight bends, set PW3=1.0, and PW1, PW2, and PW4=0.0.
The ccppc3 example follows much the same form as ccppc1 and ccppc2, and it illustrates the use of PC3 and PW3. Study these examples to determine the differences.
Conpack places labels at points on a contour line where PFUN is minimized. This module describes the optimum distance term.
-------------------------------------------------------------
PFUN= Term
-------------------------------------------------------------
PW1 * GRAD / (GRAV + PC1 * GRSD) Gradient
+ PW2 * ENCB / PC2 Crossing contours
+ PW3 * CDIR / PC3 Tight curves
+ PW4 * MIN (1 - EXP {-[(D(I)-PC4)/PC5]2}) Optimum distance
-------------------------------------------------------------

1 CALL CPSETI ('LLP - LINE LABEL POSITIONING', 3)
2 CALL CPSETR ('PC4 - PENALTY SCHEME CONSTANT 4', 0.1)
3 CALL CPSETR ('PC5 - PENALTY SCHEME CONSTANT 5', 0.2)
4 CALL CPSETR ('PC6 - PENALTY SCHEME CONSTANT 6', 0.05)
5 CALL CPSETR ('PW4 - PENALTY SCHEME WEIGHT 4', 5.0)
6 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK)
7 CALL CPPKCL (ZREG, RWRK, IWRK)
8 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCONS)
9 DO 12, I=1, NCONS
10 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
11 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
12 12 CONTINUE
13 CALL CPLBDR (ZREG, RWRK, IWRK)
CALL CPSETR ('PC4', pc4)
CALL CPSETR ('PC5', pc5)
CALL CPSETR ('PC6', pc6)
CALL CPSETR ('PW4', pw4)
Let the penalty term be written as:

For a given label Li, the penalty would be:

where di is the distance from the point P (under consideration) to the center of Li. "di-PC4" is the amount by which that distance differs from the desired optimum value. The following table may help explain what PC5 does:
-------------------------------------------- | di - PC4 | penalty | di - PC4 | penalty -------------------------------------------- 0. 0. .25*PC5 .06059 1.25*PC5 .79039 .50*PC5 .22120 1.50*PC5 .89460 .75*PC5 .43022 1.75*PC5 .95323 1.00*PC5 .63212 2.00*PC5 .98168 --------------------------------------------One problem is that, if you make PC5 too small, it may happen that no point P you consider gives you a penalty less than .99, so you will be using the best of a bad lot.
The ccppc4 example follows much the same form as ccppc1, ccppc2, and ccppc3; it illustrates the use of PC4, PC5, PC6, and PW4. Study these examples to determine the differences.

1 CALL CPSETI ('LLP - LINE LABEL POSITIONING', 3)
2 CALL CPSETI ('LLO - LINE LABLE ORIENTATION', 1)
3 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK)
4 CALL CPPKCL (ZREG, RWRK, IWRK)
5 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCONS)
6 DO 12, I=1, NCONS
7 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
8 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
9 12 CONTINUE
10 CALL CPLBDR (ZREG, RWRK, IWRK)
CALL CPSETR ('LLA', rlla)
CALL CPSETI ('LLO', llo)
Compare the results here with the plot in module "Cp 6.9 Label placement: Penalty scheme."

1 CALL COLOR
2 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK)
3 CALL CPPKCL (ZREG, RWRK, IWRK)
4 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCONS)
5 CALL CPSETI ('LLP - LINE LABEL POSITIONING', 2)
6 CALL CPSETR ('LLS - LINE LABEL SIZE', .02)
7 CALL CPSETC ('HLT - HIGH/LOW LABEL TEXT STRINGS', ' '' ')
8 DO 11, I=1, NCONS
9 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
10 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
11 CALL CPSETI ('LLC - LINE LABEL COLOR INDEX', MOD (I, 16) + 1)
12 11 CONTINUE
13 CALL CPBACK (ZREG, RWRK, IWRK)
14 CALL CPCLDM (ZREG, RWRK, IWRK, MAP, CPDRPL)
15 CALL CPLBDR (ZREG, RWRK, IWRK)
16
17 SUBROUTINE COLOR
18 CALL GSCR (1, 0, 0., 0., 0.)
19 CALL GSCR (1, 1, 1.0, 1.0, 1.0)
20 CALL GSCR (1, 2, 0.0, 0.9, 1.0)
21 CALL GSCR (1, 3, 0.9, 0.25, 0.0)
22 CALL GSCR (1, 4, 1.0, 0.0, 0.2)
23 CALL GSCR (1, 5, 1.0, 0.65, 0.0)
24 CALL GSCR (1, 6, 1.0, 1.0, 0.0)
CALL CPSETI ('LLC', llc)
Line 1 of the ccpllc.f code segment sets up a color table using the subroutine named "color," partially defined in lines 17 through 24. A complete discussion of setting up a color table appears in Chapter 7 "Color tables and color mapping systems" of the NCAR Graphics Fundamentals guide. Line 2 of the code segment initializes Conpack, and line 3 picks contour levels so that we can force labeling of every line in lines 8 through 12.
Line 5 selects the regular scheme for labeling so that the color attribute is used, and line 11 chooses colors by cycling through the color table. Line 6 enlarges the label size to make the labels more visible over the contour lines, and line 7 turns off high and low labels to emphasize the desired labels. High and low label options are discussed in module "Cp 6.1 Drawing labels." Note that contour lines are masked in line 14.

1 CALL CPRECT (ZREG, MREG, MREG, NREG, RWRK, LRWK, IWRK, LIWK)
2 CALL CPPKCL (ZREG, RWRK, IWRK)
3 CALL CPGETI ('NCL - NUMBER OF CONTOUR LEVELS', NCONS)
4 CALL CPSETI ('LLP - LINE LABEL POSITIONING', 2)
5 CALL CPSETC ('HLT - HIGH/LOW LABEL TEXT STRINGS', ' '' ')
6 CALL CPSETI ('LLO - LINE LABEL ORIENTATION', 1)
7 DO 11, I=1, NCONS
8 CALL CPSETI ('PAI - PARAMETER ARRAY INDEX', I)
9 CALL CPSETI ('CLU - CONTOUR LEVEL USE FLAGS', 3)
10 CALL CPGETR ('CLV - CONTOUR LEVEL VALUES', VALUE)
11 WRITE (STRING, 5) VALUE
12 CALL CPSETC ('LLT - LINE LABEL TEXT STRING', STRING)
13 11 CONTINUE
14 CALL CPBACK (ZREG, RWRK, IWRK)
15 CALL CPCLDM (ZREG, RWRK, IWRK, MAP, CPDRPL)
16 CALL CPLBDR (ZREG, RWRK, IWRK)
17 5 FORMAT (F6.2, ':SRIL:O:N:C', F6.2)
CALL CPSETC ('LLT', cllt)
The LLT parameter allows you to give each contour line a label of your choice. In the ccpllt example, each contour level value is followed by "oC". Long labels are not terribly useful in publication-quality plots because they don't follow the curves of the contours. By default, Conpack prints the value of the level as the label, with numbers represented in the form discussed in the numeric control modules Cp 7.3 through Cp 7.5.
Line 1 of the ccpllt.f code segment initializes Conpack for regularly spaced data, and line 2 forces the choosing of contour levels so that we can turn on labeling for each line in line 11. Line 4 chooses the regular labeling scheme so that the text options will be used. Line 5 turns off high and low labels to show the contour labels more clearly. This option is described in module "Cp 6.1 Drawing labels."
Line 6 forces labels to be placed parallel to the contour line being labeled. Line 10 retrieves the value of the contour level so that we can make a meaningful label for each line. Line 11 does an internal write to the variable string so that each line is labeled with its index in the CLV array. Line 12 sets up the label array so that each line is given the appropriate label. In lines 14 through 16, a background is drawn using CPBACK, contours are drawn by CPCLDM, and labels are drawn with a call to CPLBDR, as this tutorial has now demonstrated many times. Line 17 provides a format for the contour line label text and places the "degrees Celcius" symbol after the contour line value.
Previous Chapter Tutorial Home Next Chapter