The READ_ASCII function reads data from an ASCII file into an IDL structure variable. READ_ASCII may be used with templates created by the ASCII_TEMPLATE function.
This routine handles ASCII files consisting of an optional header of a fixed number of lines, followed by columnar data. One or more rows of data constitute a record . Each data element within a record is considered to be in a different column, or field . The data in one field must be of, or promotable to, a single type (e.g., FLOAT). Adjacent fields may be collected into multi-column fields, called groups . Files may also contain comments, which exist between a user-specified comment string and the corresponding end-of-line.
READ_ASCII is designed to be used with templates created by the ASCII template function.
This routine is written in the IDL language. Its source code can be found in the file
read_ascii.pro
in the
lib
subdirectory of the IDL distribution.
You can define the attributes of a field in two ways. If you use a template, you can either use a previously generated template, or create a template with the ASCII_TEMPLATE function on page ASCII_TEMPLATE . You can use COMMENT_SYMBOL, DATA_START, DELIMITER, or MISSING_VALUE to either override template attributes or to provide one-time attributes for the file to be read, without a template.
Set this keyword to a string that identifies the character used to delineate comments in the ASCII file to be read. When READ_ASCII encounters the comment character, it discards data from that point until it reaches the end of the current line, identifying the rest of the line as a comment. The default character is a space, ` ', specifying that no comments will be recognized.
Set this keyword equal to the number of header lines you want to skip. The default value is 0 if no template is specified.
Set this keyword to a string that identifies the end of a field. If no delimiter is specified, READ_ASCII uses information provided by the template in use. The default is a space, ` ', specifying that an empty element constitutes the end of a field.
Set this keyword equal to a named variable that will contain the header in a string array of length DATA_START. If no header exists, an empty string is returned.
Set this keyword equal to a value used to replace any missing or invalid data. The default value, if no template is supplied, is !VALUES.F_NAN. See for details.
Set this keyword equal to the number of records to read. The default is to read up to and including the last record.
Set this keyword equal to the index of the first record to read. The default is the first record of the file (record 0).
Use this keyword to specify the ASCII file template (generated by the function ASCII_TEMPLATE ), that defines attributes of the file to be read. Specific attributes of the template may be overridden by the following keywords: COMMENT_SYMBOL, DATA_START, DELIMITER, MISSING_VALUE.
To read ASCII data using default file attributes, except for setting the number of skipped header lines to 10, type:
data = READ_ASCII(file, DATA_START=10)
To use a template to define file attributes, overriding the number of skipped header lines defined in the template, type:
data = READ_ASCII(file, TEMPLATE=template, DATA_START=10)
To use the ASCII_TEMPLATE GUI to generate a template within the function, type:
data = READ_ASCII(myfile, TEMPLATE=ASCII_TEMPLATE(mytemplate))