Writesthe contents of one or more variables (in ASCII fixed format) to a file using a format that you specify.
var_list The list of variables containing the values to be written. Note that variables of type structure are not supported. An exception to this is the !DT, or date/time, structure. It is possible to transfer date/time data using this routine.
Dt_Template An array of integers indicating the data/time templates that are to be used for interpreting date/time data. Positive numbers refer to date templates; negative numbers refer to time templates. For more details, see DC_WRITE_FREE, Example 4. To see a complete list of date/time templates, see the PV-WAVE Programmer's Guide.
Format A string containing the C- or FORTRAN-like format statement that will be used to write the data. The format string must contain at least one format code that transfers data; FORTRAN formats must be enclosed in parentheses. If not provided, C format(s) that match the data type(s) of the variables in var_list are assumed; for example
%lf
for float, %i
for integer, and %s
for string.
If neither the Row or Column keywords are provided, the data is stored in rows. If both keywords are used, the Row keyword is assumed.
date/time structures, but not from any other kind of structures.
NOTE: This function can be used to write data from
NOTE: Any variable you include in var_list must have been previously created; otherwise, an error occurs.
The format string is processed from left to right. Record terminators and format codes are processed until no variables are left in var_list or until an error occurs. In a FORTRAN format string, when a slash record terminator ( / ) is encountered, a new output record is started.
TIP: If an error does occur, view the contents of the file (using an operating system command) to see how much data was transferred. This will enable you to isolate the portion of the variable list in which the error occurred.
For more information about format reversion and group repeat specifications, see the PV-WAVE Programmer's Guide.
If you are interested in an illustration showing what row-oriented data can look like inside a file, see the PV-WAVE Programmer's Guide.
sara
is a floating-point array with 10 elements all equal to 1.0, tana
is a floating-point array with 5 elements all equal to 2.0, and cora
is a floating-point array with 8 elements all equal to 3.0, the function call:
status = DC_WRITE_FIXED('outfile.dat', sara, $ tana, cora, Format="(5(1X, F7.4))")
outfile.dat
containing the following values:
..1.0000..1.0000..1.0000..1.0000..1.0000 ..1.0000..1.0000..1.0000..1.0000..1.0000 ..2.0000..2.0000..2.0000..2.0000..2.0000 ..3.0000..3.0000..3.0000..3.0000..3.0000 ..3.0000..3.0000..3.0000
bogus
is a 2-by-4 integer array with values 1 through 4 in the first column and values 5 through 8 in the second column, the following function call:
status=DC_WRITE_FIXED('intfile.dat',/Column, bogus, Format='(I5)')
intfile.dat
, as shown below:
....1....5 ....2....6 ....3....7 ....4....8
On the other hand, the following function call:
status = DC_WRITE_FIXED('intfile.dat', $ bogus(1,*), Format='(4I5)')
....5....6....7....8
foo
is a floating-point array with 6 elements all equal to 1.0, hoo
is a floating-point array with 6 elements all equal to 2.0, doo
is a floating-point array with 6 elements all equal to 3.0, and boo
is a floating-point array with 6 elements all equal to 4.0, the function call:
status = DC_WRITE_FIXED('omni.dat', foo, $ hoo, doo, boo, Format="%f, %f, %f, %f", $ /Column)
omni.dat
that is organized as shown below:
1.0000, 2.0000, 3.0000, 4.0000 1.0000, 2.0000, 3.0000, 4.0000 1.0000, 2.0000, 3.0000, 4.0000 1.0000, 2.0000, 3.0000, 4.0000 1.0000, 2.0000, 3.0000, 4.0000 1.0000, 2.0000, 3.0000, 4.0000
"%f, "
causes a comma followed by a space to be inserted after every value written to the file.
CSV (Comma Separated Values) data by default, or you can use the Delim keyword to specify some other delimiter besides the comma.
TIP: An even easier way to write this data is to use another "DC" function, DC_WRITE_FREE. The DC_WRITE_FREE function writes
float
and date
, that contain some data values and also some chronological information about when those data values were recorded:
date = STR_TO_DT(['10/10/92', '11/11/92', '12/12/92'] float = [1.2, 3.4, 5.6]
date
. For more information on the internal structure of date/time structure variables, see the PV-WAVE Programmer's Guide.In this example, date/time Template 1 (MM/DD/YY) is used to transfer this data, which means the month, day, and year will be written as adjacent values separated by a slash ( / ).
If you enter the following command:
status = DC_WRITE_FIXED("thymus.dat", $ date, float, /Column, Dt_Template=[1], $ Format="(A10, 1X, F4.2)")
10/10/1992 1.20 11/11/1992 3.40 12/12/1992 5.60
thymus.dat
as a series of strings. In each new output record, Template 1 is used to write the data from date, using the A10 character format, and a value from float
is written, using the F4.2 format.
NOTE: If you have date and time data stored in the same variable, the variable must be listed twice in the variable list in order to extract both the date and time data. For more details, see DC_READ_FREE, Example 4.
date
, time
, mins
, type
, ext
, cost
, and num_called
. The following command writes this information to a file and organizes the values by columns:
status = DC_WRITE_FIXED('phonedata.dat', $ date, time, mins, type, ext, cost, $ num_called, /Column, $ Format="%s %s %5.2f %i %i %5.2f %s")
date
and time
are variables with a data type of string. Because they are not defined as a date/time structure, such as the variable date
that was part of the previous example, date
and time
are not stored using any of the date or time templates. Thus, there is no need to include the Dt_Template keyword as part of the function call.
The result is a file
phonedata.dat
that is organized as shown below:
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
status = DC_WRITE_FIXED('phonedata.dat', $ date, time, mins, type, ext, cost, $ num_called, /Column, Format="(A6,1X,A6,"+ $ "2X,F5.2,4X,I2,4X,I3,2X,F5.2,1X,A12)")
NOTE: If you wish to enter a format string similar to the FORTRAN one shown above, try to get the entire format string on the same line. Otherwise, use the string concatenation operator (+), as shown in the above example, to split the format string into two shorter strings.
See the PV-WAVE Programmer's Guide for more information about fixed format I/O in PV-WAVE.