Many varieties of ASCII tables can be handled, but the simplest (and default) is the comma-separated value (CSV) style as shown in the example below:
Each column contains a field and each row contains a record. The (optional) first row contains the name of each column. The remainder of the rows contain comma-separated values (other separator options are possible). The Table Reader icon allows the user to specify how their table is formatted, which columns to read and which data types are in each column. If no data types are specified, then the first row of data will be examined and an attempt made to identify the data type (number or string) of each column.
When delimiters are not combined, missing values are easily identified as the following three example rows show:
When delimiters are combined, it is no longer possible to identify missing values. In the Macro language, the bitmap() function can be used to convert values to missing values.
Multiple rows containing meta-data can be included in a table file. The formatting of this meta-data is more strictly controlled and must be a space-separated list of PARAM=VALUE pairs. This meta-data can be accessed in the Macro language, and is also used when visualising the data.
The following example shows a table file with 5 rows of meta-data, followed by a header row, followed by combined-space-delimited data rows:
The next section shows some Macro code to parse this table.
Using ASCII Tables in Macro
After being read with the
read_table() function, a table's columns can be accessed either by index or by name. A column will either be a vector of numbers or a list of strings. Meta-data can also be queried.
The following example code shows how to read a standard CSV file, such as the first example presented on this page, in Macro:
The default parameters of Metview's table reader are such that a standard CSV file (comma-separated, one header row) is read without additional arguments. We can then extract the values from the first row by using its name as an argument to the
The following example code shows how to read the FLEXTRA data file shown above in this page, how to extract its data, and how to access its meta-data.