|
IDL Reference Guide: Procedures and Functions |
|
The ASCII_TEMPLATE function presents a graphical user interface (GUI) which generates a template defining an ASCII file format. Templates are IDL structure variables that may be used when reading ASCII files with the READ_ASCII routine. See READ_ASCII for details on reading ASCII files.
This routine is written in the IDL language. Its source code can be found in the file ascii_template.pro in the lib subdirectory of the IDL distribution.
Result = ASCII_TEMPLATE( [Filename] [, BROWSE_LINES=lines] [, CANCEL=variable] [, GROUP=widget_id] )
Returns a template defining an ASCII file format.
A string containing the name of a file to base the template on. If Filename is not specified, a dialog allows you to choose a file.
Set this keyword equal to the number of lines that will be read in at a time when the "Browse" button is selected. The default is 50 lines.
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 ASCII_TEMPLATE graphical user interface. When a group leader is killed, for any reason, all widgets in the group are also destroyed.
Use the following command to generate a template structure from the file "myFile":
myTemplate = ASCII_TEMPLATE(myFile)
| Note If no filename is supplied in the call to the ASCII_TEMPLATE function, a file selection dialog is displayed prior to the first ASCII_TEMPLATE screen. |
The ASCII_TEMPLATE function lets you describe the data organization of an ASCII file and generates a template that describes how to correctly import the ASCII data. The READ_ASCII function accesses the data in an ASCII file, using the template to determine how to import the data correctly. (You only have to explicitly call READ_ASCII when you call ASCII_TEMPLATE from the command line. When you start the ASCII Template dialog from an iTool or the IDLDE, the READ_ASCII routine is called for you.) The template is an IDL variable that you can use to read other files with the same organization.
After starting the ASCII Template dialog using one of the methods described in Launching the ASCII Template Dialog, complete the following steps to create the template:
sine_waves.txt from the examples\data subdirectory of your IDL distribution. The ASCII Template window is displayed.
1
The following table describes each of these options.
2
The following table describes each of these options:
SmoothSine and Field2 NoisySine by selecting each field and entering the names in the Name field. The Type fields are correct and do not need to be changed.
The following table describes each of these options:
The result of these actions depends on the location from which you launched the ASCII Template dialog. The READ_ASCII function, which reads data from a file according to the template specification, is automatically called when you access the ASCII Template dialog from iTools or from the Import ASCII macro. From the command line, you must explicitly read the ASCII data with the template specification. After defining the structure of your ASCII data using the ASCII Template dialog, refer to the appropriate section:
When importing an ASCII data file into IDL, you must first describe the format of the data using the interactive ASCII_TEMPLATE function. If you have a number of ASCII files that have the same format, you can create and save a customized ASCII template using the SAVE procedure. After creating a SAVE file of your custom template, you can avoid having to repeatedly define the same fields and records when reading in ASCII files that have the same structure.
plotTemplate, which will contain your custom ASCII template: plotTemplate = ASCII_TEMPLATE( )
A dialog box appears, prompting you to select a file.
plot.txt file in the examples/data subdirectory of the IDL distribution.
| Note Another way to import ASCII data is to use the Import ASCII File toolbar button on the IDLDE toolbar. To use this feature, simply click the button and select plot.txt from the file selection dialog. |
plot.txt file using the custom template, plotTemplate:
PLOT_ASCII = READ_ASCII(FILEPATH('plot.txt', SUBDIRECTORY = $
['examples', 'data']), TEMPLATE = plotTemplate)
plot.txt file data:PRINT, PLOT_ASCII
The file contents are printed in the Output Log window. Your output will resemble the following display.
SAVE, plotTemplate, FILENAME='myPlotTemplate.sav'
RESTORE, 'myPlotTemplate.sav'
This file contains your custom ASCII template information stored in the structure variable, plotTemplate.
| Note If you are attempting to restore a file that is not in your current working directory, you will need to specify a path to the file. |
plotTemplate for the TEMPLATE:
PLOT_ASCII = READ_ASCII(FILEPATH('plot.txt', $
SUBDIRECTORY = ['examples', 'data']), $
TEMPLATE = plotTemplate)
PRINT, PLOT_ASCII
QUERY_ASCII, READ_ASCII, BINARY_TEMPLATE
IDL Online Help (March 06, 2007)