Previous Using IDL: Importing and Writing Data into Variables Next

Using Macros to Import ASCII Files

To import an ASCII file into IDL using a macro, complete the following steps:

  1. Select the Import ASCII toolbar button. The Select an ASCII file to read dialog appears.
  2.  

  3. Select a file to import.
  4.  

  5. See Using the ASCII Template Dialog under ASCII_TEMPLATE for instructions on how to use the dialog to define the structure of your ASCII data.

ASCII files opened with the Import ASCII macro are stored in structure variables which are named filename_ASCII where filename is the name of the file you opened without the extension.


Note
IDL variables must begin with a letter, and may contain only letters, digits, the underscore character, or the dollar sign. If the first character of filename is not a letter, the prefix "var" is added to the variable name. Any spaces within filename are converted to underscores. Any other illegal characters within filename are removed.

For example, if you opened ascii.txt, the data is now in the structure variable named ASCII_ASCII. Each field (named in the ASCII Template dialog) is an element of the structure.

The structure can be viewed in the Variable Watch Window.

Figure 1-3: Variable Watch Window Showing ASCII_ASCII Structure

Figure 1-3: Variable Watch Window Showing ASCII_ASCII Structure

You can specify which part of the structure variable you want to access by using the following syntax:

variable_name.element_name

For example, if you want to view the Longitude field data, enter the following:

Print, ASCII_ASCII.LONGITUDE  

If you want to plot the Temperature data, enter the following:

IPLOT, ASCII_ASCII.TEMPERATURE  

The following figure results.

 

Figure 1-4: Plot of ASCII_ASCII.TEMPERATURE

Figure 1-4: Plot of ASCII_ASCII.TEMPERATURE

  IDL Online Help (March 06, 2007)