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 | , 7 sig figs | 4 | y=1.7 | y=float(x) |
double prec. | , 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) |
Now try,
a=5 b=3 c=a/b print,c
This probably isn't the answer you were expecting! Look at ``help,a'' ``help,b'' and ``help,c''. These are all integers. This brings us onto the subject of how IDL stores variables.
Try ,
a=5. b=3. print,a/b
This should give you answer you expect. Use help to look at ``a'' and ``b''. They are now floating point numbers. This is why you get a different answer from when you used integers.
If you multiply or divide two variables IDL gives the answer as the more complex type. So combining two integers gives you an integer, combining an integer and a real gives you a real.
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).