Primeros pasos in IDL

1. Introduction

1.1. Introduction

IDL is a software for data analysis, visualization and cross-platform application developments. It integrates a powerful, array-oriented language with numerous mathematical analysis and display technique, giving high flexibility. IDL allows us to exploit interactively through integrated graphical facilities large data sets.  Among the main characteristics are:

IDL is a comercial package that requires the payment of licences as well as their anual maintenance. Since the costs are very expensive only a limited amount of IDL licenses are available. Please use them efficiently, and do not block them while not used.  At present, there are 30 licenses available in the Unix network, and 6 in dino (a six processor SGI Power Challenge machine for running long jobs). Please do not use more than 1 license at times of high demand (typically from 10am to 5pm weekdays), and please exit IDL promptly when you have finished. To see the licence status in real-time, check the page: http://carlota/cgi-bin/licencias.pl?sw=detallado

The current version of IDL is v5.4. However, we are still keeping v5.2 around for avoiding potential problems if you are using old procedures that may not work with the current version. We will try to keep the same policy when installing new versions (but this is a deal with Research Systems, Inc. (RSI) company).  If you want to use IDL v5.2, type idl52, idlde52.

Note: many people have noted that IDL is not as precise and fast as fortran or C, therefore it will be a good approach either to call subroutines  (within IDL) written in other programming languages (e.g. fortran) or just using IDL to play around with the output arrays from these languages.

1.2. The devolpment environment

We start an IDL session by either typing

idl

or

idlde

The second allows a multiple document interface that includes built-in editing tools. This mode is higly recommended.

To exit an IDL session type

exit

or  click on Exit within File (left upper corner of the main menu) if you are within idlde.

The IDLdevelopment environment provides you 5 windows:

1.3. Help ?

If you started with idl you get into the IDL hypertext help by typing

?

Within idlde mode you just need to click on  Help at the right upper corner of the main menu.

Getting into the Help is very important and for sure will save you a lot of time when developing your applications. This hypertext provides you several facilities to achieve the desired information even if you don't have any idea of what variable or procedure will you use. Particularly useful is the option Help on IDL where you can get information either by topics or by alphabetical functional list.

You also could access the IDL help outside from IDL by typing idlhelp (which does not not pick up any licence) to start the GUI help window or idldemo to start the Demo mode.

Several manuals in PDF are available at:

/usr/pkg/rsi/idl_5.4/docs/

All manuals are cross-linked and cross-referenced. Use acroread to read them; for instance:

acroread /usr/pkg/rsi/idl_5.4/docs/getstart.pdf

Information about local libraries can be obtained by typing widget_olh, but it only works when you are within idl v5.2. Help about the local libraries can also be accessed by editing the help files in:

/usr/pkg/rsi/idl_local/help

Other sources of information are the ITT website and the David Fanning Consulting page, which contains many other interesting links. Also of interest are the Markwardt IDL Programs and the JHU/APL/S1R IDL page.There is also a very useful set of routines for astronomy in IDL astro lib (help about this library can be found as well by typing widget_olh within idl v5.2). An interesting place is IDL newsgroup. An introductory course given by Reinhold Kroll is available here.

1.4. Special Characters

!   First character of system variable names
 '  Delimit string constants· Indicate part of octal or hex constant
 ;  Begin comment field
 $ Continue on the next line· Issue operating system command if entered on a line by itself.
  "  Delimit string constants or precede octal constants
  .   Indicate constant is floating point· Start executive command
 & Separate multiple statements on one line
 :   End label identifiers
 *  Multiplication operator· Array subscript range· Pointer dereference (if in front of a valid pointer)
 @ Include file· Execute IDL batch file
 ?   Invokes online help when entered at the IDL command line.· Part of the ?: ternary operator used in conditional expressions.

IDL> print,!pi,!dpi
IDL>print,!path
IDL>print,!version
IDL>print,!err_string

IDL>a='tonto'  & b="tonto"
IDL>print,a
IDL>print,b

IDL>$pwd

IDL>@filename

IDL>.return
IDL>.reset_session

IDL>a=" hello " & b=" hello again " & print,a,b ; this is just a comment to show the usefulness of &

IDL>a=5 & b=2
IDL>; A shorter way of saying IF (a GT b) THEN z=a ELSE z=b:IDL>
IDL>z = (a GT b) ? a : b
 

1.5. Variables and Arrays

IDL has a variety of data types: bytes, short integers, long integers, floating, double, complex, and strings. Variables should start with a character and may continue either with characters, numbers or '$' and '_'.  Variables cannot be named as IDL commands (e.g, if, else, do).

IDL provides the following data types:

Type Bytes Range Conversion Routine Name  Constant  Array  Index 
Byte 1 0-255 byte  0B bytarr bindgen 
Integer 2 -32768 -- +32767 fix 0,0S  intarr indgen
Unsigned Integer 2 0-65535 uint 0U,0US uintarr uindgen
32 Bit Signed Long 4 2x +/- 109 long  0L lonarr lindgen 
32 Bit Unsigned Long 4 0-4x 109 ulong 0UL ulonarr  ulindgen
64 Bit Signed Long 8 -9,223,372,036,854,775,808 --+9,223,372,036,854,775,807. long64 0LL lon64arr l64indgen
64 Bit Unsigned Long 8 0-18,446,744,073,709,551,615 ulong64 0ULL ulon64arr ul64indgen
Float 4 +/- 1038 float  0.0  fltarr  findgen
Double Precision 8 +/- 10308 double  0.0 D dblarr  dindgen
Complex 8 (pair of reals) complex  COMPLEX(0,0) complexarr  cindgen
Double Precision Complex 16 (pair of double precision reals) dcomplex  DCOMPLEX(0,0) dcomplexarr  dcindgen
String 0-32767 Text string   '' or "" strarr sindgen

Unlike Fortran, IDL variables and arrays are defined dynamically and you do not need to declare them at the begining. For example the type of a variable or array may change several times along an IDL procedure. In principle this an IDLadvantage, but be careful since it is very easy to make mistakes!. If yoyIf you wish you can avoid problems by declaring your variables or arrays using the commands tabulated above.

EXAMPLES:

IDL>result=10/4
IDL>print,result
IDL>result=5
IDL>result=5*5.0
IDL>print,result

IDL>a=30000
IDL>b=30000
IDL>c=a+b
IDL>r='Result:'
IDL>print,r
IDL>print,c

IDL>a=long(a)
IDL>b=long(b)
IDL>print,'Result2:',a+b

IDL>a=40000*1L
IDL>b=40000*1L
IDL>print,'a+b =',a+b

IDL>a = [[0,1,2],[3,4,5],[6,7,8]]
IDL>print,a
IDL>a = [[0,1,2],[3,4,5],[6,7,8]]*1.0
IDL>print,a

1.6. Working with arrays

Arrays may have up to 8 dimensions. The first element of an array has subscript 0, therefore the latest element of a given dimension should be dim-1. Arrays may be initialised either with all its elements equal to 0 or equal to the subscript values:

IDL>a=indgen(5)
IDL>b=intarr(5)
IDL>print,'a:',a & print,'b:',b

To extract elements, subarrays or vectors from within arrays you only need to specify the subscript of the element [s], the subscript boundaries [s1:s2] or specify the whole set of elements of a desired dimension [*] respectively.

IDL>a=RANDOMU(seed,4,4) ; RANDOMU returns one or more uniformly-distributed, floating-point, IDL>pseudo-random numbers in the range 0 < Y <1.0 to fill the array.
IDL>print,a & print,a[0,0]
IDL>b=a[0:2,3] & print,b
IDL>print,a[3,*]
IDL>print,a[3,1:*]

Some interesting functions to play around with arrays:

ARRAY_EQUAL (compare data for equality in situations where the index of the elements that differ are not of interest)
CONGRID (resample image to any dimensions)
INVERT (compute inverse of a square array)
MIN  (return the minimum element of an array)
MAX (return the maximum element of an array)
N_ELEMENTS (number of elements of an array)
REFORM (changes the dimensions of an array without changing the total number of elements)
REPLICATE (form array of given dimensions filled with a value)
REVERSE (reverse vectors arrays)
ROT (rotate array by any amount)
SHIFT (shift array elements)
SORT (sort array contents and return vector of indices)
REBIN (resample array by integer multiples)
SIZE (return array size and type information, it can be seen from the Variable Watch Window)
TOTAL (sum array elements)
TRANSPOSE (Transpose array)
WHERE (let you know for example where are the array elements satisfying a given condition)

EXAMPLES:

IDL>a = INDGEN(10)  & PRINT, 'array = ', a
IDL>r=ARRAY_EQUALl(a,2) & print,r
IDL>;will return 0 (i.e., false) if not all the elements of a are equal to 2, otherwise will return 1, i.e. true)

IDL>a=RANDOMU(seed,4,4)  & print,a
IDL>total=N_ELEMENTS(a) & print,total

IDL>a=RANDOMU(seed,4,4)
IDL>print,MAX(a),MIN(a),MAX(a)/MIN(a)

IDL>a=indgen(4) & print,a
IDL>b = REFORM(a,2,2) & print,b

IDL>a = [[0,1,2],[3,4,5],[6,7,8]] & print,a
IDL>b=REVERSE(a) & print,b

IDL>a = [[0,1,2],[3,4,5],[6,7,8]] & print,a
IDL>b=TRANSPOSE(a) & print,b

IDL>a = INDGEN(10)  & PRINT, 'array = ', a
IDL>; Find the subscripts of all the elements in the array that have a value greater than 5:
IDL> result = WHERE(a GT 6, count)
IDL>PRINT, 'Number of elements > 6: ', count
IDL>PRINT, 'Subscripts of elements > 6: ', result
 

1.7. Journaling

If you wish to keep a record of the commands you type at the IDL command line you can use JOURNAL. The first step is to type

JOURNAL, 'your_log_name_file'

All the commands you type are saved in this file. If you wish to include a comment or any further notation in this file

JOURNAL,'your comment'

To end journaling type JOURNAL without arguments

JOURNAL
 

1.8. Configuration

If you wish to use a certain directory where you use to write your own procedures, or to access to a particular library of routines (not included in the defaults), IDL checks the environmental variable IDL_STARTUP when starting a session. All commands and paths you add to this variable will be automatically executed when opening a session. As an example, suppose you wish to include the old version of the popular IDL Astronomy Library which is kept in /usr/pkg/rsi/idl_local/lib_OLD/astro_OLD. The first step to follow is to include in your .cshrc file in your home directory the following statement:

setenv IDL_STARTUP /home/username/idl.startup

according to this statement you allow IDL to look a the idl.startup (you can use a different name if you wish) file located in your home where to check for the IDL_STARTUP variable. Next edit this file and include the following statements to include this directory and all its subdirectories:

IDL_ASTRO_OLD = EXPAND_PATH('+/usr/pkg/rsi/idl_local/lib_OLD/astro_OLD')
!path= IDL_ASTRO_OLD+':'+ !path

Type PATH within IDL to be sure that you really have included the old directory.

Note: it will be activated when you enter a new session but first you should type source .cshrc at your home.

There are many possibilities for your configuration that can be accessed from the main menu of idlde (click on File and then on Preferences).