X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



9002 Rate this article:
1.7

A Smart Way To Help IDL Find Data Files In Your File System

This Help Article is designed for programmers, who, in calls needing file path inputs, are either:
  • trying to debug errors like "The system cannot find the file specified" or "No such file or directory", or ...
  • trying to optimize their custom IDL program and data files for sharing with other users or porting to other systems.

We believe that the approach presented below offers the best strategy for organizing your data files and for addressing them in IDL procedure/function calls.

One of the biggest problems in porting IDL programs from the developer's machine to other machines arises because developers cannot always be sure into what directory location their program files will be installed. For this reason, if you are supplying data or resource files needed by your IDL program, then it is dangerous to identify these files by an absolute path. Identifying them by a path relative to IDL's default current working directory is also dangerous, because that default current working directory could also vary from machine to machine. When a suboptimal choice of file-addressing strategy has been made, errors like the following can occur:

    IDL> openr, lun, 'C:\MyIDLApps\data\mydata.dat', /GET_LUN
    OPENR: Error opening file. Unit: 100, File: C:\MyIDLApps\data\mydata.dat
    The system cannot find the file specified.

or:

    IDL> read_jpeg, 'myimage.jpg', image
    READ_JPEG: Error opening file. Unit: 100, File: /home/johndoe/myimage.jpg
    No such file or directory

To eliminate the above errors we can recommend at least two strategies for positioning and finding the data and resource files needed by your IDL program.

The first strategy is popular with Exelis Visual Information Solutions' PSG consulting group. It is based on use of a routine named
SOURCEPATH and the source code for that routine can be downloaded into your IDL search path from Exelis' 'Code Contrib' site at URL:

The instructions for how to use SOURCEPATH are shown at that link.

'sourcepath.pro' uses an approach based on IDL's
SCOPE_TRACEBACK routine, introduced in IDL 6.2. An alternative strategy, which you could embed at the beginning of your main application routine, is based on the IDL function ROUTINE_INFO, and is discussed below:

Place your data and resource files in either the same directory or in a child or sibling directory to your main application routine. Thus, let's say you have an application, whose main program you are distributing as "myidlapp.pro" or "myidlapp.sav" and this program is dependent for some of its data on "mydata.dat" and for one of its widget button bitmaps on "mybutton.bmp". Let's say that you export the data in the same directory that holds the main program (the "application root directory") and you export the bitmap in a subdirectory to the application root called "resource". We would then recommend that your main program have a line like the following near the top:

    info = routine_info('myidlapp', /SOURCE)
    appRootDir = file_dirname(info.path)

Now, in subsequent calls for the data or the resource file the following lines will work on any system that anyone installs your application on:

    dataFile = filepath('mydata.dat', ROOT_DIR=appRootDir)

and

    bitmapPath = filepath('mybutton.bmp', ROOT_DIR=appRootDir, $
        SUBDIRECTORY=['resource'])

Note one other strategy: If all your data files and resource files are in the same directory with your main program file, you can avoid the need for FILEPATH calls completely. In this scenario, after you have run the ROUTINE_INFO query block above, you can simply call:

    cd, appRootDir

and after that call you can open files by their name, no further path info required,
e.g. "
openr, lun, 'mydata.dat', /GET_LUN".

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »