Reads a file that contains ASCII representations of basic data types.
Full or relative path needed to locate ASCII file.
A scalar or one-dimensional array specifying the dimension sizes of the data to be read.
As of version 6.0.0, dimensions can be of type int or long.
A string representing the type of the data being read.
The asciiread function is used to read ASCII data. If datatype is a numeric type, then non-numeric characters are ignored and the numbers are read in the order they appear in the input file. However, note that for the float and double types, the string 'nan' (any case) is read as a valid numerical value. For all the integer types, the prefix '0x' or '0X' signifies a value represented in hexadecimal (base 16). For the 'byte' type only, the prefix '0', not followed by 'x' or 'X', signifies a value represented in octal (base 8).
All numeric types require require a separator. A separator is a non-numeric character [eg, space, comma, alphabetic character].
For string data, each line of the file is read as a string.
For character data, the file is read byte-by-byte.
An error message is generated whenever the number of elements read is less than the number implied by the dimensions parameter.
If -1 is given for the dimensions parameter, all values in the file will be read into a one-dimensional variable. The dimension size of this variable will be equal to the number of elements in the file.
In version 6.0.0, we fixed a notable quirk in this function: if dimensions was set to explicit dimension sizes, then a _FillValue attribute was returned, equal to the default fill value for that type. If dimensions was equal to -1, then a _FillValue attribute was NOT returned.
Several functions located in contributed.ncl provide additional flexibility for reading ascii files.
Consider an ASCII file ("sample.file") that consists of three "header" lines followed by the data array of interest. This file is best read using the readAsciiTable function. However, this example is offered to illustrate how one can read the file directly via the asciiread and ndtooned functions.
but this 2nd line has 3 numbers: 10, 30, 50. and a blank line.
Consider an ASCII file ("numberByte_ascii.file") that consists of three rows. Each row has 30 numbers. Unseen at the end of each line is an end-of-line character. Each number is to be interpreted as a numeric type "byte".
The file can not be directly read as numeric bytes because all numeric types require a non-numeric separator. Also, the 'hidden' end-of-line character complicates the situation. Use of charactertoshort and stringtocharacter can be used to get the desired type "short" or "byte".
The following code snippet will result in each numeric value being separated. The "ncol+1" is to account for the hidden end-of-line character. The "zero_offset" variable is used to 'normalize' the integer character representation to numeric ibtegers.
Printing as byte is done as hexadecimal. The numbers are the same.