casacore
|
Filling a table from an Ascii file. More...
#include <ReadAsciiTable.h>
Public Member Functions | |
String | readAsciiTable (const String &filein, const String &tableDescName, const String &tableName, Bool autoHeader=False, Char separator= ' ', const String &commentMarkerRegex="", Int firstLine=1, Int lastLine=-1, const IPosition &autoShape=IPosition()) |
Create a table with name as given by tableName. More... | |
String | readAsciiTable (const String &filein, const String &tableproto, const String &tablename, const Vector< String > &columnNames, const Vector< String > &dataTypes, Char separator, const String &commentMarkerRegex, Int firstLine, Int lastLine) |
This form gets the header info in the given vectors. More... | |
String | readAsciiTable (const String &headerFile, const String &dataFile, const String &tableDescName, const String &tablename, Char separator= ' ', const String &commentMarkerRegex="", Int firstLine=1, Int lastLine=-1) |
This form reads TWO Ascii files. More... | |
String | readAsciiTable (const String &headerFile, const String &dataFile, const String &tableDescName, const char *tablename, Char separator= ' ', const String &commentMarkerRegex="", Int firstLine=1, Int lastLine=-1) |
Table | readAsciiTable (String &formatString, Table::TableType tableType, const String &filein, const String &tableDescName, const String &tableName, Bool autoHeader=False, Char separator= ' ', const String &commentMarkerRegex="", Int firstLine=1, Int lastLine=-1, const IPosition &autoShape=IPosition()) |
Similar versions as above, but returning a Table object. More... | |
Table | readAsciiTable (String &formatString, Table::TableType tableType, const String &filein, const String &tableproto, const String &tablename, const Vector< String > &columnNames, const Vector< String > &dataTypes, Char separator, const String &commentMarkerRegex, Int firstLine, Int lastLine) |
Table | readAsciiTable (String &formatString, Table::TableType tableType, const String &headerFile, const String &dataFile, const String &tableDescName, const String &tablename, Char separator= ' ', const String &commentMarkerRegex="", Int firstLine=1, Int lastLine=-1) |
Table | readAsciiTable (String &formatString, Table::TableType tableType, const String &headerFile, const String &dataFile, const String &tableDescName, const char *tablename, Char separator= ' ', const String &commentMarkerRegex="", Int firstLine=1, Int lastLine=-1) |
Filling a table from an Ascii file.
Public interface
Global functions to fill a table from an Ascii file.
The table columns are filled from a file containing the data values separated by a separator (optionally followed by whitespace). The default separator is a comma. Non-given values default to 0, False, or blank string (depending on data type). A value is not given between 2 consecutive separators or if less values are given than needed. One line per table row should be given. The following two header lines define the columns in the table:
D2,4
defines a column containing arrays with shape [2,4]. It "consumes" 8 numbers in each input data line. The last column can contain a 0 in one of the shape numbers. It indicates that the arrays are variable shaped; it "consumes" all remaining numbers in each input data line. If needed, the arrays are filled with default values (0, False, or blank). E.g. I0
indicates a variable shaped vector. I0,4
with a line with remaining input 1 2 3 4 5 6 7 8 9
results in an array with shape [3,4] (filled with with 3 zeroes). If the autoHeader
argument is True, the column definition lines should not be given. It recognizes the types from the first data line. It gives the names 'column0', etc. to the columns. It can recognize integer, double, and string types. It is possible to give a shape argument which has the same function as the shape values discussed above.
There are two forms of the readAsciiTable function:
autoHeader=True
is given). creates a table with name table.test
from the text file file.in
. The text file could look like:
resulting in a table with 6 columns and 2 rows.
Definition at line 183 of file ReadAsciiTable.h.
String casacore::ReadAsciiTable_global_functions_readAsciiTable::readAsciiTable | ( | const String & | filein, |
const String & | tableDescName, | ||
const String & | tableName, | ||
Bool | autoHeader = False , |
||
Char | separator = ' ' , |
||
const String & | commentMarkerRegex = "" , |
||
Int | firstLine = 1 , |
||
Int | lastLine = -1 , |
||
const IPosition & | autoShape = IPosition() |
||
) |
Create a table with name as given by tableName.
If autoHeader==True, the format is automatically derived from the first data line. It can recognize integer, double, and String types. The columns will be named column1, column2, etc.. If the autoShape argument is given with 1 or more axes, all values are treated as a single column with the given shape. Note that one of the can have length 0 indicating a variable shaped array. If autoHeader==False, the layout of the table has to be defined in the first 2 lines of the input file. The remaining lines in the input file contain the data.
When the tableDescName is not blank, the table description will be stored in a table description file with the given name.
It returns a string containing the format of the columns in the form COL1=R, COL2=D,...
The separator gives the character separating the values. The default is a blank. Note that irrespective of the separator, blanks between values are always ignored. A string value has to be enclosed in double quotes if it has to contain blanks or the separator value.
Header and data lines starting with the regular expression given in the commentMarker are ignored. By default no comment marker is present. E.g. "#" ignores all lines starting with the #-sign. " *#" does the same, but the lines to ignore can start with whitespace.
The first and last line argument give the 1-relative number of the first and last line to read from the file. firstLine <= 0 is the same as 1. lastLine <= 0 means until end-of-file. Note that lines matching the comment marker are also counted.
String casacore::ReadAsciiTable_global_functions_readAsciiTable::readAsciiTable | ( | const String & | filein, |
const String & | tableproto, | ||
const String & | tablename, | ||
const Vector< String > & | columnNames, | ||
const Vector< String > & | dataTypes, | ||
Char | separator, | ||
const String & | commentMarkerRegex, | ||
Int | firstLine, | ||
Int | lastLine | ||
) |
This form gets the header info in the given vectors.
Each element in the dataTypes vector has to be of the form as would be given in a header line.
String casacore::ReadAsciiTable_global_functions_readAsciiTable::readAsciiTable | ( | const String & | headerFile, |
const String & | dataFile, | ||
const String & | tableDescName, | ||
const String & | tablename, | ||
Char | separator = ' ' , |
||
const String & | commentMarkerRegex = "" , |
||
Int | firstLine = 1 , |
||
Int | lastLine = -1 |
||
) |
This form reads TWO Ascii files.
The first file may contain keywords and their values as well as the two lines described above for the names and type of variables. The second file is intended for data only.
When the tableDescName is not blank, the table description will be stored in a table description file with the given name.
It returns a string containing the format of the columns in the form COL1=R, COL2=D,...
The separator gives the character separating the values. The default is a blank. Note that irrespective of the separator, blanks between values are always ignored. A string value has to be enclosed in double quotes if it has to contain blanks or the separator value.
Header and data lines starting with the regular expression given in the commentMarker are ignored. By default no comment marker is present. E.g. "#" ignores all lines starting with the #-sign. " *#" does the same, but the lines to ignore can start with whitespace.
The first and last line argument give the 1-relative number of the first and last line to read from the data file. firstLine <= 0 is the same as 1. lastLine <= 0 means until end-of-file. Note that lines matching the comment marker are also counted.
String casacore::ReadAsciiTable_global_functions_readAsciiTable::readAsciiTable | ( | const String & | headerFile, |
const String & | dataFile, | ||
const String & | tableDescName, | ||
const char * | tablename, | ||
Char | separator = ' ' , |
||
const String & | commentMarkerRegex = "" , |
||
Int | firstLine = 1 , |
||
Int | lastLine = -1 |
||
) |
Table casacore::ReadAsciiTable_global_functions_readAsciiTable::readAsciiTable | ( | String & | formatString, |
Table::TableType | tableType, | ||
const String & | filein, | ||
const String & | tableDescName, | ||
const String & | tableName, | ||
Bool | autoHeader = False , |
||
Char | separator = ' ' , |
||
const String & | commentMarkerRegex = "" , |
||
Int | firstLine = 1 , |
||
Int | lastLine = -1 , |
||
const IPosition & | autoShape = IPosition() |
||
) |
Table casacore::ReadAsciiTable_global_functions_readAsciiTable::readAsciiTable | ( | String & | formatString, |
Table::TableType | tableType, | ||
const String & | filein, | ||
const String & | tableproto, | ||
const String & | tablename, | ||
const Vector< String > & | columnNames, | ||
const Vector< String > & | dataTypes, | ||
Char | separator, | ||
const String & | commentMarkerRegex, | ||
Int | firstLine, | ||
Int | lastLine | ||
) |
Table casacore::ReadAsciiTable_global_functions_readAsciiTable::readAsciiTable | ( | String & | formatString, |
Table::TableType | tableType, | ||
const String & | headerFile, | ||
const String & | dataFile, | ||
const String & | tableDescName, | ||
const String & | tablename, | ||
Char | separator = ' ' , |
||
const String & | commentMarkerRegex = "" , |
||
Int | firstLine = 1 , |
||
Int | lastLine = -1 |
||
) |
Table casacore::ReadAsciiTable_global_functions_readAsciiTable::readAsciiTable | ( | String & | formatString, |
Table::TableType | tableType, | ||
const String & | headerFile, | ||
const String & | dataFile, | ||
const String & | tableDescName, | ||
const char * | tablename, | ||
Char | separator = ' ' , |
||
const String & | commentMarkerRegex = "" , |
||
Int | firstLine = 1 , |
||
Int | lastLine = -1 |
||
) |