Tutorial IDL

Tutorial IDL

English
28 Pages
Read
Download
Downloading requires you to have access to the YouScribe library
Learn all about the services we offer

Description

IDL: a small tutorial for DATA studentsF. Spada & C.I. van Tuyll15th February 2005Contents1 Introduction 22 Getting started 33 Links 54 Command line interface 65 Programs 76 Constants and Variables 86.1 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86.2 Conversion functions . . . . . . . . . . . . . . . . . . . . . . . 97 Arrays 107.1 Simple operations . . . . . . . . . . . . . . . . . . . . . . . . . 107.2 Subscripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Files I/O 149 Program Control 1710 Calling procedures and functions 2011 Graphics 2111.1 Graphics preferences . . . . . . . . . . . . . . . . . . . . . . . 2111.2 Simple plotting . . . . . . . . . . . . . . . . . . . . . . . . . . 2111.3 Contour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2211.4 Bar plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2311.5 Saving your plot. . . . . . . . . . . . . . . . . . . . . . . . . . 2411.6 Useful graphics command . . . . . . . . . . . . . . . . . . . . 2512 Saving and restoring IDL data 2613 Random numbers 2711 Introduction1IDL (Interactive Data Language) is a scienti c computing package, whichcan be used for data analysis and visualisation. IDL is an array based lan-guage, which means that no complicated program routines are needed tocalculatewitharrays. Thetoolsarecalledbyusingacommandlineinterface.This tutorial shows only a glimpse of what you can do with IDL. It takes ...

Subjects

Informations

Published by
Reads 16
Language English
Report a problem
IDL:
a
small
F.
tutorial
for
DATA
Spada & C.I. van Tuyll
15th
February
2005
students
Contents 1 Introduction 2 2 Getting started 3 3 Links 5 4 Command line interface 6 5 Programs 7 6 Constants and Variables 8 6.1 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 6.2 Conversion functions . . . . . . . . . . . . . . . . . . . . . . . 9 7 Arrays 10 7.1 Simple operations . . . . . . . . . . . . . . . . . . . . . . . . . 10 7.2 Subscripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 8 Files I/O 14 9 Program Control 17 10 Calling procedures and functions 20 11 Graphics 21 11.1 Graphics preferences . . . . . . . . . . . . . . . . . . . . . . . 21 11.2 Simple plotting . . . . . . . . . . . . . . . . . . . . . . . . . . 21 11.3 Contour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 11.4 Bar plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 11.5 Saving your plot . . . . . . . . . . . . . . . . . . . . . . . . . . 24 11.6 Useful graphics command . . . . . . . . . . . . . . . . . . . . 25 12 Saving and restoring IDL data 26 13 Random numbers 27 1
1 Introduction IDL1(Interactive Data Language) is a scientific computing package, which can be used for data analysis and visualisation. IDL is an array based lan-guage, which means that no complicated program routines are needed to calculate with arrays. The tools are called by using a command line interface. This tutorial shows only a glimpse of what you can do with IDL. It takes a while to get to know all the possibilities of this package. But in the end, IDL provides a lot of powerful solutions to handle your data. But don’t worry, we will only use some of the basic features. And we hope that this tutorial will guide you through most of the problems you will encounter. WARNING: the IDL program on the window computers uses a rather old version of IDL, 5.3, while IDL 6.1 is available yet. This means that if you use an IDL program, you have to check if it does not contain procedures which are too fancy, as IDL 5.3 cannot handle it. Most of the time, you will not encounter any problems, but still... The programs, which are provided for this course are ’bug free’ (hopefully!). If you encounter any problems, please tell me, than I will try to fix it.
1is a registered trademark of Research Systems Inc (RSI).IDL
2
2 Getting started You will work with the students version of IDL on windows. This program is started as follows: Start -> Programs -> Research Systems IDL 5.3 -> IDL When you start IDL, the graphical user interface appears, as shown in Fig. 1. The main parts and useful tools are described below.
Figure 1: IDL graphical user interface.
Command LineIn this window behind the IDL promptIDL>you can type all the commands. More about this in the Command Line section. Variable watch windowThis window keeps track of all variables which are used. They are sorted by type: Locals, Params, Common and System.
3
Output LogAll output, including error notices, is printed in the output window.
Program Windowwindow can be used for multiple purposes, butThis most of the time this panel is used for editing programs. However, I prefer to write my programs with a simple editor program.
Menu Bar and Tool BarLike every other windows based program, at the top of the IDL window, you can find some basic features in different menus or behind an icon on the tool bar.
You can quit IDL by typing
IDL> exit
or go the menu bar, and click onFile -> Exit.
4
3 Links Before you start with IDL, it is worthwhile to note some useful IDL links.
First of all, IDL provides some online guides itself. The most useful is the reference guide, which describes all of IDL’s built-in routines. You can find this guide by typing IDL> ? topicname But you can also go to the menu bar and click onHelp -> Contents.
Also a fast way of searching for information on IDL routines is the webpage: http://idlastro.gsfc.nasa.gov/idl html help/idl alph.html
The use of IDL is not restricted to built-in routines, sometimes it can be (a lot) better to write your own. Or you can search on the internet for solu-tions, which IDL does not provide. A lot of helpful material can be found at http://www.dfanning.com/
The newsgroup of IDL is: comp.lang.idl-pvwave
The web site of IDL is http://www.rsinc.com/idl/index.asp
5
4 Command line interface Try typing the following commands at the IDL prompt: IDL> a = 5 IDL> print, a IDL> help, a IDL> a = [2, 3] IDL> print, a IDL> help, a Important: notice that the commands and the parameter list are separated by a comma!! To repeat a command, you can go up and down through previous commands using the arrow keys. This is the interactive way of working with idl: each line is executed immediately. After every return statement, you can watch the output log and try to un-derstand what these commands mean. All commands started with semicolons (;) are neglected, as they will be treated like comments: IDL> ; This is a comment !! A command can be continued on the next line by typing a dollar sign ($) first: IDL> a=[01,02,03,04,05,$ IDL> 06,07,08,09,10] IDL> print, a It is possible to type two statement on the same line, by connecting them with an ampersand (&): IDL> a=5 & print, a IDL keeps track of all variables and programs that are used during the exe-cution. Information on all these variables is shown by typing IDL> help
6
5 Programs Usually, you want to execute many command statements at a time. For this purpose, it is more useful to write programs that can be stored, reused and can execute several code lines.
Write in a file called first.pro this simple program: a = 25 b = 3 c = a * b print, a, b, c end run idl and run the program (.run) IDL> .run first or go the menu bar and click onRun -> Compile
If you write the same program, but you add as first line the following pro first then for executing it you need to do IDL> .run first IDL> first By using the second method, you need to compile the program only once. After that, this program is stored and you can call it as much as you like.
Note that you use the right pathway to your program. Probably this is something like \\homedirs\accountname\mydocuments\where accountname refers to your accountname on the fysica system.
7
6 Constants and Variables Try to run this program x = 3 y = 2.5 z = x + y ^y + in(z) w = x s string1 = ’Here is ’ string2 = "the data: " print, string1, string2, x, y, z, w end
6.1 Operators Square bracketsare used to create arrays and to enclose array subscripts. ParenthesesUsed to group expressions and to enclose function parameter lists. Parentheses can be used to override the order of operator evaluation described above. Also used to enclose array subscripts. Mathematical Operators Assignement: = Addition/Concatenation: + Subtraction: -Multiplication: * division: / Exponentiation:^ Matrix multiplication (row*column): # Boolean operator: AND NOT OR XOR
8
Relational operator: EQ equal to NE not equal to GE greater than or equal to GT greater than LE less than or equal to LT less than
6.2 Conversion functions STRINGConvert to string BYTEConvert to byte
FIXConvert to 16-bit integer, or optionally other type
UINTConvert to 16-bit unsigned integer
LONGConvert to 32-bit integer ULONGConvert to 32-bit unsigned integer
LONG64Convert to 64-bit integer ULONG64Convert to 64-bit unsigned integer
FLOATConvert to floating-point DOUBLEConvert to double-precision floating-point COMPLEXConvert to complex value
DCOMPLEXConvert to double-precision complex value
9
7 Arrays Arrays are multidimensional data sets which are manipulated according to mathematical rules. Array elements can be of any IDL data type, but all elements of a given array must be of the same data type. Array subscripts provide a means of selecting one or more elements of an array for retrieval or modification. One-dimensional arrays are often called vectors. Arrays can have up to eight dimensions in IDL. Square braces are used to define arrays: vect1 = [1, 2, 3, 4] vect2 = [1, 0, 1, 0] matrix1 = [[1,2,3],[4,5,6]] matrix2 = [[vect1],[vect2]]
7.1 Simple operations IDL is an array-oriented language. This means that array operations execute more efficiently than similar one-dimensional operations, so array can be componentwise added, multiplied, ...: res1 = vect1 + vect2 res2 = vect1 * vect2 res3 = vect1 + sin(vect2) print, res1, res2, res3 end Try to add these lines to the code that you wrote before: maxvec = max(vect1) minvec = min(vect1) print, maxvec, minvec maxmat = max(matrix1) minmat = min(matrix1) print, maxmat, minmat Some other basic operators on matrices are: transpose, determ, invert, rotate. Construct the following matrixAand try these operations:
10