CP File Format

The CP file format is a simple format for storing scalar floating point 2-D raster data. The files are very similar to images in that the points are equally spaced. The file is ASCII based and the header contains all the information necessary to find the location of each data value. A CP format data file consists of a header followed by the data in one of two formats.

Header

A typicial header for a CP format data file is shown below.

C XMAX, XMIN = 0.3000E+02-.1840E+04
C NPX        = 100
C YMAX, YMIN = 0.7540E+03-.1686E+04
C NPY        = 130
 13000

The header contains the maximum and minimum extents of the data in the X and Y directions as well as the number of points in each direction. The header lines are writen as GF comment lines to allow the 3-column format to be read by GF for displaying CP files as a set of line plots. This is why the last line of the header is a standard GF line containing the number of points in the file.

The FORTRAN code fragment below could be used to write the header.

        WRITE(1,'(''C XMAX, XMIN = '',2E10.4)') XMAX,XMIN
        WRITE(1,'(''C NPX        = '',I3)') NPX
        WRITE(1,'(''C YMAX, YMIN = '',2E10.4)') YMAX,YMAX
        WRITE(1,'(''C NPY        = '',I3)') NPY

        NP=NPX*NPY
        WRITE(1,'(I6)') NP

Data format

PSALL automatically detects the format of the data using the length of the first data line.

One column data format

The one-column format consists of a single column of data with a width of 10 characters. As shown below. The (X,Y) location of a given Z point is determined by the position of the data in the file. The data runs with the Y loop on the outside. Consider the code fragment below. It reads each Z value and calculates the corresponding X and Y values and stores all the values in arrays. Note that it is not necessary to store the X and Y values in arrays, because they can be easily calculated from the indices of the Z array.

      DO 10 I=1,NPX
          XPOSITION = FLOAT(I-1)/FLOAT(NPX-1)*(XMAX-XMIN)+XMIN
          DO 10 J=1,NPY
               YPOSITION = FLOAT(J-1)/FLOAT(NPY-1)*(YMAX-YMIN)+YMIN
               READ(1,'(E10.4)') Z(I,J)
               X(I,J)=XPOSITION
               Y(I,J)=YPOSITION
10    CONTINUE
          

The start of a one column format CP file looks like:

C XMAX, XMIN = 0.3000E+02-.1840E+04
C NPX        = 100
C YMAX, YMIN = 0.7540E+03-.1686E+04
C NPY        = 130
 13000
0.9990E+03
0.9990E+03
0.9990E+03
0.9990E+03
0.9990E+03

Note the values of the data here are the 999.0 null value. The value used for null data can be set in PSALL. Null data is equivilent to a transperant pixel in an image file.

Three column data format

The only difference here is that the X and Y values are also stored in the data file. The one column format has files 1/3 the size of the three column format, so it is prefered for large files. The data in the three columns, each 10 characters wide, is arranged X,Z,Y to allow the Z value to be plotted vs X using GF by reading the first two columns of the CP file. The X,Z,Y data is preceeded by a 3 character INVEC value.

The code fragment below writes the array Z(I,J) to a 3 column CP format file. The INVEC variable (see the GFx Manual for more details on the INVEC usage in GF files) is set to 0 for the start of each row, so that data at each Y value will plot as a separate data segment in GF. This value is ignored when the file is read as a CP format file.

       DO 10 I=1,NPX
          X = FLOAT(I-1)/FLOAT(NPX-1)*(XMAX-XMIN)+XMIN
          INVEC=0
          DO 10 J=1,NPY
               Y = FLOAT(J-1)/FLOAT(NPY-1)*(YMAX-YMIN)+YMIN
               WRITE(1,'(I3,3E10.4)') INVEC,X,Z(I,J),Y
               INVEC=1
10    CONTINUE