# Chapter 8: Coordinate systems in NCAR Graphics

`Previous Chapter          LLUs Home          Next Chapter          Index`
NCAR Graphics depends on three different coordinate systems and a transformation between them to plot your data to the screen. Before any plotting can be done, this transformation must be defined, so it is a critical part of your graphics program. Each of the coordinate systems and the transformation are defined below.

## Table of coordinate system user entry points

This chapter discusses GKS and SPPS routines for setting up coordinate systems and normalization transformations.

### GKS

GSVP
Set viewport coordinates.

GSWN
Set window coordinates.

GSELNT
Select normalization transformation.

### SPPS

SET
Set viewport and user coordinates and logarithmic scaling.

GETSET
Retrieve viewport user coordinate and logarithmic scaling values.

## Definitions

This module introduces several important definitions which are used heavily in this guide.

### Discussion

NCAR Graphics uses two GKS coordinate systems: World Coordinates (WCs) and Normalized Device Coordinates (NDCs), as well as its own coordinates, user coordinates. All are expressed in real numbers.

The World Coordinate System (WCS) is the system in which you perform your calculations. It can have units of feet, meters, millibars, or whatever engineering units apply to the calculations. World coordinates are Cartesian coordinates expressed as real numbers. You can select a rectangular subspace of world coordinates for output; this space is called a "window." In world coordinates, both axes must monotonically increase starting with a data origin in the lower left coordinate of the frame.

Normalized Device Coordinates (NDCs) is a device-independent coordinate system used by GKS as an addressing system for a virtual (any) plotting device. In GKS, you must perform a transformation from WCs to NDCs. Whereas WCs have variable ranges, NDCs have a constrained range limited to (0.,0.) in the lower left corner and (1.,1.) in the upper right corner. A rectangular subspace of NDCs can be selected for output; this space is called a "viewport."

The user coordinate system in NCAR Graphics adds two important extensions to GKS world coordinates: "mirror-imaging" of an axis, and "nonlinear scaling" of an axis. Thus, in user coordinates, windows can be defined in which the horizontal coordinate of the window might be meters varying from 1000. at the left to 100. at the right (mirror-imaging), and the vertical coordinate might vary from 102 at the bottom to 103 at the top in logarithmic scaling.

If you are working in Cartesian space with linear scaling and standard minimum to maximum axis scaling, then world coordinates and user coordinates are equivalent.

The process of transforming data from WCs into NDCs for output on the plotting device is called a normalization transformation. The NCAR Graphics GKS-0A package currently supports two normalization transformation types. Type 0 defines an identity transformation in which the WCs, like NDCs, have horizontal and vertical axes ranging from 0. to 1. This is the transformation used to facilitate putting an object such as a title at a specific location on the frame. A type 1 normalization transformation allows the WCs to have whatever range of values is desired.

See "Appendix A: The use of X/Y coordinates in NCAR Graphics" for a complete description of NCAR Graphics coordinate systems.

## Normalization transformations

To define a normalization transformation within the GKS system requires two calls, one to the GKS routine GSVP to define its "viewport" and a second call to the GKS routine GSWN to define its "window." Using the SPPS routine SET, you can set the window, the viewport, mirror-imaging of axes, and nonlinear scaling of axes all in a single call. Since this routine is more flexible than the two GKS routines, we recommend using SET.

The graphic shows a normalization transformation from world coordinates to NDCs, in which there is mirror-imaging and nonlinear scaling of axes.

### Code segment from fcoord2.f

```1  CALL SET(VPL,VPR,VPB,VPT,1000.,100.,100.,1000.,2)
```

### Synopsis

```      CALL SET (VPL, VPR, VPB, VPT, WDL, WDR, WDB, WDT, LS)
```

### Arguments

VPL, VPR, VPB, and VPT
Real, Input---Normalized Device Coordinates (NDCs) that define a viewport. The letters "L," "R," "B," and "T" refer to the left, right, bottom, and top edges of the viewport, respectively. VPL must be less than VPR, and VPB must be less than VPT. All coordinates have values in the range of 0. to 1.

WDL, WDR, WDB, and WDT
Real, Input---User coordinates that define a window. The letters "L," "R," "B," and "T" refer to the left, right, bottom, and top edges of the window, respectively. Axis reversal (also called mirror-imaging of an axis) is controlled by the order of these values. If WDL is greater than WDR, the X coordinates are mirror-imaged. Similarly, if WDB is greater than WDT, the Y coordinates are mirror-imaged.

LS
Integer, Input---Specifies the desired combination of linear or logarithmic axis scaling. Possibilities are:

1 Linear X, Linear Y
2 Linear X, Log Y
3 Log X, Linear Y
4 Log X, Log Y
Note that the window defining coordinates are always input to SET as they would be before any logarithmic transformation.

### Discussion

A call to the SPPS routine SET provides a way to completely define the mapping from window user coordinates to viewport Normalized Device Coordinates (NDCs), including the specification of axis scaling reversal and whether axes are to have linear or logarithmic scaling.

Every call to SET redefines GKS normalization transformation 1 with the new viewport and window coordinates, axis scaling, and axis mirror-imaging. This normalization transformation 1 will be in effect until it is changed by either another SET call or by a call to the GKS routine GSELNT.

Caution: If you use GSELNT to define a new normalization transformation, you will still have the mirror-imaging and linear/log scaling established by the last SET call. If the last SET call used nonlinear axis scaling or mirror-imaging of an axis, you may need to do another SET call to alter these settings.

## Restoring the normalization transformation

To save the state of a normalization transformation, set and use a new transformation, and then restore the state of the first transformation, use the GETSET and SET routines. Use GETSET to access the normalization transformation parameters and save them by using unique argument names. You can then call SET with the new transformation and do what is needed. Then, when you are ready to restore the original normalization transformation, call SET again, using the saved parameters.

### Code segment from fcoord1.f

```1     CALL GETSET(VPLS,VPRS,VPBS,VPTS,WDLS,WDRS,WDBS,WDTS,LSS)
2     CALL SET(VPL,VPR,VPB,VPT,1000.,100.,100.,1000.,2)
3     CALL SET(VPLS,VPRS,VPBS,VPTS,WDLS,WDRS,WDBS,WDTS,LSS)
```

### Synopsis

```      CALL GETSET (VPL, VPR, VPB, VPT, WDL, WDR, WDB, WDT, LS)
```

### Arguments

VPL, VPR, VPB, and VPT
Real, Output---Normalized device coordinates of the existing viewport. The letters "L," "R," "B," and "T" refer to the left, right, bottom, and top edges of the viewport, respectively. VPL must be less than VPR, and VPB must be less than VPT.

WDL, WDR, WDB, and WDT
Real, Output---User coordinates of the existing window. The letters "L," "R," "B," and "T" refer to the left, right, bottom, and top edges of the window, respectively.

LS
Integer, Output---Current value of the log-scaling parameter.

### Discussion

Line 1 of the fcoord1.f code segment shows a call to GETSET to save all of the existing transformation parameters. Line 2 defines a new normalization transformation 1 including mirror-imaging on the X axis and logarithmic scaling on the Y axis. Line 3 resets the normalization transformation, which will return mirror-imaging and axis scaling to their original values.

See "Appendix A: The use of X/Ycoordinates in NCAR Graphics" for a complete description of NCAR Graphics coordinate systems.

`Previous Chapter          LLUs Home          Next Chapter          Index`