A class to parse files with input that are in columns separated by commas, spaces, or tabs.
General notes on the file:
-
All blank lines are skipped
-
All lines that begin with a '#' are skipped
-
The first section of the file contains parameters. This parameter section must be before the data
-
The next section is the main data of the file. It contains columns of data.
-
The file can be read with case sensitive or insensitive strings. Case sensitivity applies to header names and parameter keys (if case insensitive, these will be converted to lower case internally)
-
The first line after the column name heading may be an optional line specifying nonstandard units for each column. These are represented as [nmi], [fpm], [deg], etc. If so defined, then values stored will be converted from these units into internal units.
Otherwise it is assumed that values are already in internal units.
If the default units as understood by the end user are not internal units (for example using degrees for latitude instead of radians), then further processing of the stored data may be necessary upon retrieval. Use [unspecified] for any column that has no applicable units (e.g. strings or booleans). A dash (-) in the units field will be interpreted as "unitless".
Notes on the columns of data
-
The columns of data may be separated by any number of commas, spaces, or tabs (but see setColumnDelimiters)
-
The first line of the columns of data is considered the "headings." These are strings which can be accessed with the getHeading() method.
-
The next line is optional. It contains the a string representing the units for a column. A line is considered a line of units if at least half of the fields read in are interpreted as valid units.
-
The columns of data can be strings or double-precision floating point values
-
If the values are doubles, then they are assumed to be in internal units. If a unit type is specified, their values will be converted into internal units and stored. The end user is responsible for converting values if the unspecified default units are something other than the internal ones.
-
This format essentially follows RFC 4180 (when using commas)
Parameters are essentially a "key/value" pair. Once an parameter is entered (either from the setParameter method or from the file), then that parameter name is reserved. If any future updates to the parameter (either from the setParameter method or the file), then the previous value will be overwritten. Parameters have the following rules:
-
Parameters have the basic form "key = value"
-
Parameter keys can be any combination of letters and numbers.
-
There must be spaces around the equals sign
-
The value may be a string, a double-precision value, or a boolean value.
-
If the value is a double precision value, then units may be added.
For example, "param = 10 [nmi]"
-
The units are optional.
-
Boolean values are represented by T, F, true, false, TRUE, or FALSE.
-
If a parameter has not been set and it is read, something will be returned. It is not defined what that something is. To avoid this, check is a parameter exists with the containsParameter() method.
void larcfm::SeparatedInput::setCsv |
( |
| ) |
|
Sets this object to formally read comma-separated-value (CSV) input. This format the delimiter is a comma and the quote character is a double-quote. Any amount of whitespace before or after a comma is removed. So the string a, "b " ,c will be read three fields: a, b with a trailing space, and c. Like any quote character, if you to put the quote in the field, duplicate it, so the line: a, b"", c will be three fields: a, b" and c.
void larcfm::SeparatedInput::setQuoteCharacter |
( |
char |
q | ) |
|
This sets the 'quote' character. The quote character is a way to contain a delimiter within a field of the data. So if the delimiter is a comma and ' is the quote character, then 'hello, folks' is a valid field.
A quote character does not need to be set, the default is null, meaning, don't use a quote characters.
A quote character can be put in the field by duplicating it. So if the delimiter is a comma and ' is a quote character, then ''hello'', fol''ks will be two fields: 'hello' and fol'ks. Be careful with nested quotes 'a''b' is interpreted as a'b not as two quoted strings: a and b. However, 'a' 'b' will be interpreted as the string: a b
Notes
-
Quotes do not apply to parameters
-
This will generate an error if the quote character matches the delimiters
-
This is not used for parameters or fixed-width columns.
- Parameters
-
q | quotation character, if set to null do not treat quote characters specially |