Previous Using IDL: Importing and Writing Data into Variables Next

Using Macros to Import Binary Files

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

  1. Select the Import Binary toolbar button. The Select a binary file to read dialog appears.
  2.  

  3. Select a file to import. For example, select the surface.dat from the examples/data directory in your IDL installation directory. Click Open.
  4.  

  5. See Using the BINARY_TEMPLATE Interface under BINARY_TEMPLATE for instructions on how to use the dialog to define the structure of your binary data.

Binary files opened with the Import Binary File macro are stored in structure variables which are named filename_BINARY 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.

So, the file we just opened (surface.dat) is now in the structure variable named SURFACE_BINARY. The variable is a structure, and contains elements that are the field names defined in the Binary Template dialog. In this case the single field is named marbells. The structure can be viewed in the Variable Watch Window.

Figure 1-5: Variable Watch Window Showing MARBELLS_BINARY Structure

Figure 1-5: Variable Watch Window Showing MARBELLS_BINARY Structure

Access data from the structure variable using the following syntax:

variable_name.element_name

For example, display the surface by entering:

ISURFACE, SURFACE_BINARY.marbells  

  IDL Online Help (March 06, 2007)