Example—C and FORTRAN Format Strings
Below is shown part of a data file; this file contains data of many different types. For the purpose of this example, assume you are importing the data with one of PV-WAVE’s I/O routines. To specify a fixed format for importing this file, you have to know what kind of data it contains, and then create a format string that will import the data properly.
You can use C format strings only if you are using one of the DC routines (either DC_READ_FIXED or DC_WRITE_FIXED). These routines are introduced in
"Functions for Simplified Data Connectivity". The detailed descriptions for these routines can be found in a separate volume, the PV‑WAVE
Reference.
Phone Data |
Date | Time | Minutes | Type | Ext | Cost | Number Called |
901002 | 093200 | 21.40 | 1 | 311 | 5.78 | 2158597430 |
901002 | 093600 | 51.56 | 1 | 379 | 13.92 | 2149583711 |
901002 | 093700 | 61.39 | 2 | 435 | 16.58 | 9137485920 |
The first two lines of the phone data file are text—the title and column headings. Since these lines do not contain data, you may wish to filter them out. If you are using either DC_READ_FREE or DC_READ_FIXED, these lines can be skipped with the Nskip keyword.
The first two columns in the file, date and time, contain integer data. Since they appear to be fairly large integers, import them with the C conversion specification %ld. In FORTRAN, you need to specify the width of the field as well as the type. The FORTRAN specifier would be I6.
The next column, minutes, contains floating point numbers, which can be imported with %f for C or F5.2 for FORTRAN.
If you have a data column that is not necessary for the analysis, such as the type column, import it as an ordinary character with %c in C or A1 in FORTRAN. The data must be read when using a C format because assignment suppression is not allowed in PV-WAVE.
The ext column contains small integers, which you can import with %i (or %d) in C or I3 in FORTRAN.
The cost column is best imported with %f in C or F5.2 in FORTRAN.
In our example, the Number Called data is not needed for the analysis. This data can be skipped because it falls at the end of the row.
Based on this interpretation of the data, the C format string for reading this data file looks like this:
%ld %ld %f %c %i %f
The FORTRAN format string for reading this data file looks like this:
(I6,1X,I6,2X,F5.2,4X,A1,4X,I3,2X,F5.2)
In FORTRAN, X is the specifier for blank space. It is used to account for the space between each column of values.
Another way to skip the type column would be to enter the following FORTRAN specification:
(I6,1X,I6,2X,F5.2,9X,I3,2X,F5.2)
This specification treats the type column as just another blank space.
note | Import date and time with a character format if you want to use the STR_TO_DT conversion utility to convert date and time into “true” (Julian) date/time data. This would change the C format to: |
%s %s %f %c %i %f
and the FORTRAN format to:
(A6,1X,A6,2X,F5.2,9X,I3,2X,F5.2)
For more information on the STR_TO_DT conversion utility, refer to the description for STR_TO_DT in the PV‑WAVE Reference, or refer to Working with Date/Time Data in the PV‑WAVE User’s Guide. The chapter that describes date and time data also includes an example of how to handle date/time data that does not include the delimiters that the STR_TO_DT conversion utility expects.