|
IDL Reference Guide: Procedures and Functions |
|
The BINARY_TEMPLATE function presents a graphical user interface which allows the user to interactively generate a template structure for use with READ_BINARY.
The graphical user interface allows the user to define one or more fields in the binary file. The file may be big, little, or native byte ordering.
Individual fields can be edited by the user to define the dimensionality and type of data to be read. Where necessary, fields can be defined in terms of other previously defined fields using IDL expressions. Fields can also be designated as "Verify". When a file is read using a template with "Verify" fields, those fields will be checked against a user defined value supplied via the template.
| Note Greater than (">") and less than ("<") symbols can appear in the "New Field" and the "Modify Field" dialogs where the offset value is displayed. The presence of either symbol indicates that the supplied offset value is "relative" from the end of the previous field or from the initial position in the file. Greater than means offset forward. Less than means offset backward. ">0" and "<0" are synonymous and mean "offset zero bytes". You can delete these special symbols (thereby indicating that their corresponding offset value is not "relative") by typing over them in the "New Field" or "Modify Field" dialogs. |
Result = BINARY_TEMPLATE ( [Filename] [, CANCEL=variable] [, GROUP=widget_id] [, N_ROWS=rows] [, TEMPLATE=variable] )
This function returns an anonymous structure that contains the template. If the user cancels out of the graphical user interface and no initial template was supplied, it returns zero.
A scalar string containing the name of a binary file which may be used to test the template. As the user interacts with the BINARY_TEMPLATE graphical user interface, the user's input will be tested for correctness against the binary data in the file. If filename is not specified, a dialog allows the user to choose the file.
Set this keyword to a named variable that will contain the byte value 1 if the user clicked the "Cancel" button, or 0 otherwise.
The widget ID of an existing widget that serves as "group leader" for the BINARY_TEMPLATE interface. When a group leader is killed, for any reason, all widgets in the group are also destroyed.
Set this keyword to the number of rows to be visible in the BINARY_TEMPLATE's table of fields.
| Note The N_ROWS keyword is analogous to the WIDGET_TABLE and the Y_SCROLL_SIZE keywords. |
Set this keyword to structure variable containing an initial template (usually from a previous call to BINARY_TEMPLATE). This template structure will be used to fill in the initial fields in the new BINARY_TEMPLATE. If TEMPLATE is specified and the user cancels out of the dialog, the specified template will be returned as the Result.
Use the following command to launch the Binary Template dialog so that a structure can be defined for the file, head.dat:
sTemplate = BINARY_TEMPLATE(FILEPATH('head.dat', $
SUBDIRECTORY=['examples', 'data']))
| Note If no filename is supplied in the call to the BINARY_TEMPLATE function, a file selection dialog is displayed prior to the first BINARY_TEMPLATE screen. |
A binary template describes of the format of the data in a binary file, and can be used to successfully import binary data from any file that shares has structure. The Binary Template dialog allows you to specify characteristics of each field within a binary file, and returns a structure containing the template information. The READ_BINARY function accesses the data in a binary file, using the template to determine how to import the data correctly. (You only have to explicitly call READ_BINARY when you call BINARY_TEMPLATE from the command line. When you start the Binary Template dialog from an iTool or the IDLDE, the READ_BINARY routine is called for you.)
After starting the Binary Template dialog using one of the methods described in Launching the Binary Template Dialog, complete the following steps to create the template:
surface.dat from the examples\data subdirectory of your IDL distribution. This file contains an integer array of elevation data of the Maroon Bells mountains, a group of mountains located among the Rocky Mountains of Colorado.The Binary Template window is displayed.
sMarBellsTemplate
The following table describes each of these options.
|
Template name
|
Enter a name that describes the template. This field is optional.
|
|
File's byte ordering
|
Select the byte order of the data:
Native — the storage method is native to the machine you are currently running. Little Endian for Intel microprocessor-based machines and Big Endian for Motorola microprocessor-based machines. No byte swapping will be performed.
Little Endian — the storage method where the least significant byte appears first in the number. Given the hexadecimal number A02B, the Little Endian method stores it as 2BA0. Specify this if the original file was created on a machine that uses an Intel microprocessor.
Big Endian — the storage method where the most significant byte appears first in the number. Given the hexadecimal number A02B, the big endian method stores it as A02B. Specify this if the original file was created on a machine that uses a Motorola microprocessor.
See Files and I/O for more information on byte ordering.
|
| Note If a field has already been defined, clicking in the Return column will toggle the value of the field between Yes and No. Fields that are not marked for return can be used for calculations by other fields in the template. At least one field must be marked Yes for return in order for the BINARY_TEMPLATE function to return a template. |
marbells
0 From beginning of file
2, and are defined as 350 and 450 respectively
The following table describes the New Field dialog options:
| Note If BINARY_TEMPLATE is called by a program that is running in the IDL Virtual Machine, the Offsets, Verify, and Size fields can contain integers or field names, but not an IDL expression. |
The BINARY_TEMPLATE function returns a structure variable containing the template. The result of the previous actions depends on the location from which you launched the Binary Template dialog. The READ_BINARY function, which reads data from a file according to the template specification, is automatically called when you access the Binary Template dialog from iTools or from the Import Binary macro. From the command line, you must explicitly read the binary data with the template specification.
After defining the structure of your binary data using the Binary Template dialog, refer to the appropriate section:
| Note You can create a SAVE file of a template in order to use it from session to session. See Example: Create a SAVE File of a Custom ASCII Template for a related example. |
IDL Online Help (March 06, 2007)