AGOCG logo
Graphics Multimedia VR Visualisation Contents
Training Reports Workshops Briefings Index

Back Next

Review of IDL

6 Data Import

As there is no distinct IDL data type, any file can be imported. Unformatted input transfers a binary representation of the file directly to memory. Formatted files can be read in two main ways. With free format, IDL decides how to format the data, with explicit format, you must specify the exact format.

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.

6.1 Image Data

IDL provides routines to read in many standard image file formats. These are:
FormatRoutinesDescription
BMPREAD_BMP, WRITE_BMPWindows bitmap
GIFREAD_GIF, WRITE_GIFGraphics Interchange Format
InterfileREAD_INTERFILEInterfile v3.3
JPEGREAD_JPEG, WRITE_JPEGJoint Photographic Experts Group files
NRIFWRITE_NRIFNCAR Raster Interchange Format
PICTREAD_PICT, WRITE_PICTMacintosh PICT files (version 2)
PPMREAD_PPM, WRITE_PPMPPM/PGM
SRFREAD_SRF, WRITE_SRFSun Raster File
TIFFREAD_TIFF, WRITE_TIFF8 or 24 bit Tagged Image File Format
X11 Bitmap READ_X11_BITMAPFormat used for reading bitmaps for IDL widget button labels
XWDREAD_XWDX Windows Dump format

6.2 AVSIDL

AVSIDL is a program which allows data to be passed between IDL and AVS. It requires AVS and IDL 3.1 or later, which must be able to open an xterm on the current display. The program is not supported, but freely available from the International AVS Centre (http://www.iavsc.org/). It has been tested on the RS 600 and Sun Sparcstation.

Graphics     Multimedia      Virtual Environments      Visualisation      Contents