For example, the simple data file below contains a series of records consisting for an integer and three floats
1 1. 2.34 5.6 0 2.0 3.5 10.9 2 0.9 67.5349 5.6
The following procedure will import the data into a structure, a
pro import_test function name a={moltype:0, dec:0.0, cnt:0.0, msize:0.0} define an anonymous structure a with 4 elements, moltype=integer, dec, cnt and mszie=floats n_items = 0 initialise a counter OPENR, 1, 'data.txt' open the file for reading while (n_items LT 1000) do begin process the file line by line on_ioerror, endoffile READF, 1, a read the current line and put it into the structure n_items=n_items + 1 endwhile endoffile: close, 1 close the file end;
In order to explicitly specify the format, the FORMAT keyword must be used with the READF statement. The format string is similar to that used in FORTRAN.
Where the data consists of a repetitive series of arrays or structures, such as a series of images, and associated variable can be used to access it. An associated variable maps the structure of an IDL array or structure onto the data file. The data file can then be treated as an array of these structures. The data file is not stored in memory, the particular part of the image is access from file when it is subscripted, allowing much larger data sets to be handled. The same file may be accessed in different ways by associating it with different structures.
Support is also provided for the XDR (eXternal Data Representation) format. This is a binary format designed to allow cross platform file transfer. These files are handled using the normal read and write routines, but the XDR keyword must be specified. They can only be opened in one direction (i.e. read or write) at a time.
Format | Routines | Description |
---|---|---|
BMP | READ_BMP, WRITE_BMP | Windows bitmap |
GIF | READ_GIF, WRITE_GIF | Graphics Interchange Format |
Interfile | READ_INTERFILE | Interfile v3.3 |
JPEG | READ_JPEG, WRITE_JPEG | Joint Photographic Experts Group files |
NRIF | WRITE_NRIF | NCAR Raster Interchange Format |
PICT | READ_PICT, WRITE_PICT | Macintosh PICT files (version 2) |
PPM | READ_PPM, WRITE_PPM | PPM/PGM |
SRF | READ_SRF, WRITE_SRF | Sun Raster File |
TIFF | READ_TIFF, WRITE_TIFF | 8 or 24 bit Tagged Image File Format |
X11 Bitmap | READ_X11_BITMAP | Format used for reading bitmaps for IDL widget button labels |
XWD | READ_XWD | X Windows Dump format |
Graphics Multimedia Virtual Environments Visualisation Contents