X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



4981 Rate this article:
No rating

Accessing data in the structure returned by READ_ASCII


When dealing with ASCII-formatted data files that have large numbers of columns, the best way to access data returned by READ_ASCII is to use the structure tag number indexes. This is recommended over trying to use the READ_ASCII structure's 'FIELDNAME' field, which poses the problems discussed below.

The variable returned by READ_ASCII is a structure containing a variable number of fields that have a different naming convention depending upon the number of columns in the target dataset. Unless you explicitly change the names of every one of your columns in your ASCII_TEMPLATE dialog, datasets with less than 9 columns or less will return a READ_ASCII structure with field names ending with one digit, i.e. fields named "FIELD1" through "FIELD9". ASCII data files with 10 - 99 columns of data will return the first 9 column names formatted as "FIELD01" through "FIELD09" (and the remaining columns formatted with 2 digits, e.g. "FIELD99"). Datasets with more than 99 columns returns all FIELDNAMES with 3-digit formatting, so that the first 99 columns are named "FIELD001" through "FIELD099". Therefore, relying on field names is problematical.

The answer to this problem is to use structure tags instead. Structure tags can be used to reference a structure in place of structure names. A tag can be referenced using its index enclosed in parentheses as follows:

      Variable_Name.(Tag_Index)

If the variable returned by READ_ASCII is named "mydata", then the first column of values in the dataset will be contained in tag number 0, or mydata.(0). The second column will be contained in tag number 1, or mydata.(1), etc. This is true for any size dataset.

To see a demonstration, download the link below by right-clicking and selecting 'Save Target As...' to your current working directory. Then make a completely default 'demo_template' and proceed onto the other commands:

IDL> demo_template = ascii_template('sprngfld.txt')
IDL> mydata = read_ascii('
sprngfld.txt', template=demo_template)
IDL> help, /structure, mydata


** Structure
, 12 tags, length=1920, refs=1:
FIELD01 FLOAT Array[40]
FIELD02 FLOAT Array[40]
FIELD03 FLOAT Array[40]
FIELD04 FLOAT Array[40]
FIELD05 FLOAT Array[40]
FIELD06 FLOAT Array[40]
FIELD07 FLOAT Array[40]
FIELD08 FLOAT Array[40]
FIELD09 FLOAT Array[40]
FIELD10 FLOAT Array[40]
FIELD11 FLOAT Array[40]
FIELD12 FLOAT Array[40]
IDL> print, mydata.(0)
21.2000 27.3000 29.2000 35.4000 14.5000 30.9000 29.0000 27.6000 33.6000 24.4000 31.2000 33.4000 24.4000 30.4000 33.7000
29.3000 31.7000 32.7000 29.7000 27.9000 25.9000 22.0000 28.7000 22.5000 30.0000 24.5000 20.2000 16.9000 30.7000 27.3000
21.9000 29.5000 23.8000 23.4000 17.9000 23.7000 24.4000 29.7000 26.1000 31.1000
Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »