What is a File Reader?
Simply put, a file reader is an IDL routine that can open a file of a specified file type, read the data from that file, and create one or more IDL variables containing the data. IDL includes a set of Default File Readers; you can also create custom file readers to read data from files in less common formats.
Tip
See the documentation for
READ_IMAGE or any of the other READ_* routines for additional information about file reader routines. Many of the READ_* routines are written in the IDL language; you can inspect their source code for ideas on how to create a file reader for files of other data formats.
Using File Readers
File readers are used in the following ways:
- By invoking the file reader routine explicitly, either at the IDL command line or in an IDL program.
- By selecting Open from the IDL Workbench File menu. If the file you choose to open is of a registered file type, IDL will automatically invoke the file reader for that file type.
- By using the IOPEN routine. If the file you specify is of a registered file type, IDL will automatically invoke the file reader for that file type.
For example, you can explicitly invoke the READ_JPG routine at the IDL command line to read a JPEG file and create variables containing the image data.
A registered file type is identified in IDL's file reader registry file as having a reader routine capable of reading data in its file format. The file reader registry is described in detail in Registering Custom File Readers. Many common file types are registered by default; see Default File Readers, below.
Default File Readers
Table 9-1 lists the file types for which IDL supplies a default file reader routine. If the table contains the word "Yes" in the Registered column, IDL will attempt to use the file reader routine shown if you select a file with the listed file extension using either the File → Open menu item in the IDL Workbench or the IOPEN routine.
Note
If the selected file does not have one of the extensions shown in Table 9-1, IDL will attempt to locate a suitable file reader. See File Reader Search Algorithm for details.
|
File Type
|
File Extensions
|
Reader Routine
|
Registered
|
|---|---|---|---|
| ASCII text |
|
READ_ASCII |
Yes |
| Binary data |
various |
READ_BINARY |
Yes (using IOPEN only) |
| Bitmap image |
|
READ_BMP |
Yes |
| Comma-separated values (text) |
|
READ_CSV |
Yes |
| DICOM image |
|
READ_DICOM |
Yes |
| GIF image |
|
READ_GIF |
Yes |
| Interfile image |
|
READ_INTERFILE |
No |
| JPEG image |
|
READ_JPEG |
Yes |
| JPEG2000 image |
|
READ_JPEG2000 |
Yes |
| MrSID image |
|
READ_MRSID |
No |
| Macintosh PICT image |
|
READ_PICT |
Yes |
| PNG image |
|
READ_PNG |
Yes |
| PPM image |
|
READ_PPM |
No |
| Shapefile |
.shp |
IDLffShape |
Yes |
| Sun Rasterfile image |
|
READ_SRF |
No |
| Symbolic Link spreadsheet data |
|
READ_SYLK |
No |
| TIFF image |
|
READ_TIFF |
Yes |
| Audio Stream data |
|
READ_WAV |
Yes |
| Wavefront Data Visualizer data |
|
READ_WAVE |
No |
| X11 Bitmap image |
various |
READ_X11_BITMAP |
No |
| X Windows Dump image |
various |
READ_XWD |
No |
Creating a Custom File Reader
If you have data contained in files that do not match any of the file types listed in Table 9-1, you may want to create and register a custom file reader. To create a file reader:
- Use IDL's file input/output routines to create a routine that can open your data files and read the contents. See Files and Input/Output in the Application Programming manual for information on IDL's input/output capabilities.
- If you want to register your file reader, consider creating a query routine as described in Creating a Registered Query Routine. The query routine is optional, but allows IDL to determine if a file with an unknown file extension should be opened using your file reader.
- If you want to register your file reader, update the
idlextenions.xmlfile as described in Registering Custom File Readers.
If you only want to use your file reader from the IDL command line or in IDL programs, there are no restrictions on the reader routine. If you want to register your file reader with IDL so that it will be used by the IOPEN routine and when selecting files using the IDL Workbench File → Open menu item, be sure to create the reader routine as described in Creating a Registered File Reader Routine.