Accessing Files Using IDL Dialogs

DIALOG_PICKFILE and DIALOG_READ_IMAGE are the two primary file access dialogs in IDL. Use DIALOG_PICKFILE to select any type of file. You can select multiple files, define the directory or define file filters using keywords. Use DIALOG_READ_IMAGE to access supported image formats (listed in Image File Formats). This dialog offers preview capabilities and basic image information. The corollary DIALOG_WRITE_IMAGE allows you to write data to a select image file type.

See the following topics for more information:

You can use other dialogs to access ASCII, binary and HDF data as described in:

Accessing Any File Type Using a Dialog

The DIALOG_PICKFILE function lets you interactively pick a file using the platform's own native graphical file selection dialog. This function returns a string or an array of strings that contain the full path name of the selected file or files. The user can also enter the name of the file. The following statement opens the selection dialog and shows any .pro files in the current working directory. If you select a file and click Open, the file variable contains the full file path.

file = DIALOG_PICKFILE(/READ, FILTER = '*.pro') 

Other keywords allow you to specify the initial directory, the dialog title, the filter list, and whether multiple file selection is permitted. See "DIALOG_PICKFILE" (IDL Reference Guide) for details.

After you select a file using DIALOG_PICKFILE, you can then use one of the file I/O routines to access the data within the file. See Accessing Image Data Programmatically or Accessing Non-Image Data Programmatically for more information.

Importing an Image File Using a Dialog

The DIALOG_READ_IMAGE function opens a graphical user interface which lets you read image files. This interface simplifies the use of IDL image file I/O. You can preview images with a quick and simple browsing mechanism which also reports important information about the image file. You can also control the preview mode.

The following statement opens the dialog so that you can select among .gif, tiff, .dcm, .png and .jpg files.

result = DIALOG_READ_IMAGE(FILE=selectedFile, IMAGE=image) 

See Using the Select Image File Dialog Interface under "DIALOG_READ_IMAGE" (IDL Reference Guide) for additional information if desired. When you select a file and click Open, the file path is stored in selectedFile variable and the image data is stored in the image variable. Enter the following line to display image data in an iImage display.

IF result EQ 1 THEN iImage, image 

Saving an Image File Using a Dialog

The DIALOG_WRITE_IMAGE function displays a graphical user interface that lets you write and save image files. This interface simplifies the use of IDL image file I/O. The following statements create and write a simple image to a .tif file name myimage.tif:

myimage = DIST(100) 
result = DIALOG_WRITE_IMAGE(myimage, FILENAME='myimage.tif')  

When you select Save, it creates a .tif file in your current working directory or the directory of your choice. See "DIALOG_WRITE_IMAGE" (IDL Reference Guide) for a complete list of keywords and a description of the dialog interface.