next up previous contents
Next: Arrays Up: Lecture 2: Programming in Previous: Lecture 2: Programming in   Contents

Variables, data types

IDL has several types of variables. I list some of them here:

type range bytes to define to convert
byte 0 to 255 1 b=15B b=byte(x)
integer -32768 to +32767 2 i=15 i=fix(x)
long -2147483648 to +2147483647 4 j=long(15) j=long(x)
      j=147483647  
floating pt $\pm 10^{38}$, 7 sig figs 4 y=1.7 y=float(x)
double prec. $\pm 10^{308}$, 14 sig figs 8 y=1.7d0 d=double(x)
complex two floating point no.s 8 z=complex(1.2,0.3) z=complex(x)
string (used for text) 0-32767 s='blah' s=string(x)

  1. Variable names can have letters, numbers and underscores in them.

  2. They are NOT case-sensitive: foo, Foo and FOO are all the same variable.

  3. Note that the default type of integer is only a 2-byte integer. (Remember if you want a big loop index variable! BUT remember loops are BAD in IDL.

To convert one variable form to another use fix. Eg

str_var=fix(153.15,type=7) ;sets str_var to a string
help,str_var 
;STR_VAR         STRING    = '      153.150'; shows that it is a string, but it has much white space
;remove this with
str_var=strtrim(str_var,2); 2 removes white space from the front and back
(I do this so often that I have a routine called trmfix that combines fix,type=7 and strtrim).

IDL is a dynamically typed language (you don't declare all variables first like you do in Fortran).


next up previous contents
Next: Arrays Up: Lecture 2: Programming in Previous: Lecture 2: Programming in   Contents
lecjm 2008-11-06