I/O drivers
This module provides the diskdata IO driver designed to be used as an interface for initializations blocks for both reading and writing files formated for the diskdata procedure.
Driver diskdata
diskdata:[dense|sparse|autondx|dataframe;][sglq|noq|csv;][skiph;emptyndx;append;trans;nozeros;fsep=c;dsep=c]
The driver can only be used in `initializations' blocks. In the opening part of the block, no file name has to be provided, but general options can be stated at this point: they will be applied to all labels. In the block, each label entry is understood as the file name to use for the actual processing. Note that, before the file name, one can add further options separated by comas or semicolons, that are effective to the particular entry. Here, the csv option might be followed by a list of columns separated by commas and enclosed in parenthesis. The columns are identified by their number (first column has index 1) and must be given in ascending order without duplicate. If the last column number is suffixed by the plus sign, the following columns will also be included in the selection (e.g. "csv(1,3+)" skips the second column). To use names, the option skiph must be used and the column names are taken from the header row that is skipped through this option. When using skiph, column numbers need to be stated by prefixing the column number by # (even in this case columns must be given in ascending order).This column selection is ignored for a writing operation. The file name given can use extended notation.
The diskdata driver takes the following options:
- dense
- dense data format
- sparse
- sparse data format
- autondx
- sparse data format with automatic indexation (applies only to 1-dimension arrays indiced by ranges)
- autondx=st
- same as autondx but starting index is set to st (instead of 1)
- dataframe
- dense data format for a 2-dimension array and first index as a range (for the line numbers)
- sglq
- strings quoted with single quotes
- noq
- strings are not quoted in the file
- csv
- use CSV format: quoting and escaping with double quotes, all lines are processed ( i.e. characters '!' and '&' are ordinary symbols)
- skiph
- When reading, the first line of the file is skipped, when writing, the first line of the file is preserved (or a comment line is inserted if the file does not already exist)
- emptyndx
- When reading array indices an empty cell causes a failure. With this option empty cells are replaced by the default value of the corresponding type ( e.g. 0 for a numerical value)
- append
- append output to the end of an existing file
- trans
- tables are transposed
- nozeros
- skip zero values
- fsep=c
- character used to separate fields. The default value is ","; tabulation or ";" are also often employed
- dsep=c
- character used as decimal separator (default: ".")
Example:
declarations Set1: set of string ! Declare a set of strings ar1,ar2: array(Set1,range) of real ! Declare two dynamic arrays r: real ! Declare a real value end-declarations initializations from "diskdata:" ! Use 'diskdata' format for reading ar1 as "sparse;csv(1,3,4);ind.dat" ! Read `ar1' from 'in.dat' in sparse format ! using CSV conventions and selecting columns 1,3 and 4 r as "r_init.dat" ! Initialize `r' from 'r_init.dat' end-initializations initializations to "diskdata:append" ! Use 'diskdata' format for output [ar1, ar2] as "out.dat" ! Save two arrays in sparse format Set1 as "out.dat" ! Save set `Set1' to the same file end-initializations