Supercomputing Institute Technical User Support

 

IDL: Reading and Writing Data

  1. Supported Formats
  2. Reading ASCII Data
  3. Reading Binary Data
  4. Reading and Writing Images

Supported Formats

Image Formats

IDL includes routines for reading and writing many standard graphics file formats.  These routines and the type of files they support are listed below.
 
BMP GEO TIFF Interfile
JPEG NRIF PICT
PNG PPM SRF
TIFF XWD X11 Bitmap

Scientific Formats

There are four scientific data formats supported by IDL:
 
CDF HDF
HDF-EOS netCDF

Other Formats

 
ASCII Binary DICOM
DXF WAV XDR

Reading ASCII Data

IDL uses the ASCII_TEMPLATE function in conjunction with the READ_ASCII function to import ASCII data.  To import import an ASCII data file into IDL, you must first describe the format of the data using the ASCII_TEMPLATE function.  This function will guide you through the description of the data to a variable.
1. At the IDL Command Line, enter the following:
plottemplate=ascii_template()
2. Select the file "plot.txt" located in the data directory:
/usr/local/rsi/idl_5.4/idl_5.4/examples/data/plot.txt
3. The following dialog appears:
4. First we will choose the field type. Since we know our data file is delimited by tabs (or whitespace) select the Delimited button. Also, be sure to specify to begin reading the data at line 3, not line 1 in the Data Starts at Line field. This is because there are two comment lines at the beginning of the file.  Click Next.

5. Now the following dialog box appears:

6. At this dialog, be sure to select Tab as the delimiter between data elements since we know we have used tabs in the original file.  Now move on to the final dialog by clicking Next.

7. Now the following dialog box appears:

8. In this dialog, we will give a name to each data field for IDL to recognize each set. At the top of the box, click on the first row and then name the data set by typing the name Time for the first set in the box.  Next, move on to the second row, naming this data set Temp1 for the first set of temperatures in the data set.  Finally, name the last data set Temp2. Click Finish.

9. Type the following at the IDL Command Line to read in the file plot.txt using the template weve just created:

plot_ascii=read_ascii(filepath('plot.txt',subdir=['examples', 'data']), template= plottemplate)
10. Then enter:
print, plot_ascii
You will see the following displayed in the Output Log:

IDL> print, plot_ascii
{
11                12               13               14               15               16              17               18               19
 2.90000      3.20000      6.00000      8.50000      9.20000      9.80000     12.7000      8.20000      5.80000
 1.90000      3.90000      7.10000      7.30000      10.1000      8.90000     13.9000      7.20000      6.90000
}

Reading Binary Data


Reading binary data can be done in much the same way as reading ASCII data using the BINARY_TEMPLATE function in conjunction with the READ_BINARY function.  However, in order to show you different ways of using IDL, we will use the READ_BINARY function alone.  The binary file that we will read in the following example contains an image of the Maroon Bells mountains, a group of mountains located in the Rocky Mountains of Colorado, stored as a binary integer array.  To read in the binary data we use the following command:

maroon_bells=read_binary('/usr/local/rsi/idl_5.4/idl_5.4/examples/data/surface.dat', $
data_dims=[350,450],data_type=2,endian='little')
Note: The dollar sign ($) at the end of the first line is the IDL continuation character. It allows you to enter long IDL commands as multiple lines.

In the READ_ASCII example, we used a macro to describe the filename by the path to the file (filepath('plot.txt',subdir=['examples', 'data'])).  This doesn't work well when you start using data in your home directories.  So, we just use the absolute filename '/usr/local/rsi/idl_5.4/idl_5.4/examples/data/surface.dat'.

In the READ_ASCII example, we used a template to describe the format of the data (template=plottemplate).  Here, we have described the data using keywords (template was one keyword).

DATA_DIMS

Set this keyword to a scalar or array of up to eight elements specifying the size of the data to be read and returned.

DATA_TYPE

Set this keyword to an IDL typecode of the data to be read.  The following table lists the IDL typecodes:
Type Code
Data Type
0 Undefined
1 Byte
2 Integer
3 Longword Integer
4 Floating point
5 Double-precision floating
6 Complex
7 String
8 Structure
9 Double-precision complex
10 Pointer
11 Object reference
12 Unsigned Integer
13 Unsigned Longword Integer
14 64-Bit Integer
15 Unsigned 64-Bit Integer

ENDIAN

Set this keyword to one of three string values: 'big', 'little', or 'native' which specifies the byte ordering of the file to be read.

Therefore, the dimension of the data is 350 by 450 ( data_dims=[350,450]), an integer array (data_type=2), and we selected Little Endian(endian='little'), since we know that this file was created on an Intel processor-based machine.

We now display the image by entering:

tvscl, maroon_bells

You can view an image in IDL with two different routines. The TV procedure writes an array to the display as an image without scaling. The TVSCL procedure displays the image with the color values scaled to use the whole color table.

Reading and Writing Images

Reading image files into IDL is also easy if you know the format in which the image is stored. First we must read in the image. Here we will use a TIFF format image of an aerial satellite view of Manhattan Island in New York City.
1. Enter the following at the IDL Command Line:
nyny=read_tiff('/usr/local/rsi/idl_5.4/idl_5.4/examples/data/image.tif')
2. Now display the image:
tv,nyny
3. Now, using IDLs WRITE_TIFF command, rename and write the file:
write_tiff,'copynyny.tif',nyny



 
This information is available in alternative formats upon request by individuals with disabilities. Please send email to alt-format@msi.umn.edu or call 612-624-0528.

HOME | QUESTIONS | FEEDBACK
Employment | Events | Links | People | Programs | Publications | Support | Welcome
 


URL: http://www.msi.umn.edu/software/fast/tutorial/fast-starting.html
This page last modified on Friday, 03 November, 2000,  09:10:02 CDT  
Please direct questions or problems to help@msi.umn.edu  
Website related questions or problems should be dirrected to webmaster@msi.umn.edu