Programming in IDL 1
Programming in IDL 1
Programming in IDL 1
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Programm<strong>in</strong>g</strong> Assignment 1:<br />
Adapted from Rutton: http://www.astro.uu.nl/~rutten/rrweb/rjr-material/idl/manuals/idl-briefmanual.txt<br />
<strong>IDL</strong><br />
<strong>IDL</strong> is used often <strong>in</strong> astronomical image process<strong>in</strong>g.<br />
It is an <strong>in</strong>teractive computer language with the follow<strong>in</strong>g advantages:<br />
• programm<strong>in</strong>g language, not a package – you make up your own stuff<br />
• <strong>in</strong>teractive: test out new tricks by try<strong>in</strong>g them statement by statement<br />
The major disadvantage is that <strong>IDL</strong> licenses are very expensive. The student version is cheaper<br />
but limited to array size 65536 (256x256 pixel images).<br />
Manuals<br />
The onl<strong>in</strong>e help is reasonably good.<br />
<strong>IDL</strong> Tutorial: http://nstx.pppl.gov/nstx/Software/<strong>IDL</strong>/idl_<strong>in</strong>tro.html<br />
Another one: http://www.msi.umn.edu/software/idl/tutorial/<br />
Tips and Tricks: http://www.dfann<strong>in</strong>g.com/documents/tips.html<br />
The <strong>IDL</strong> astronomy library: http://idlastro.gsfc.nasa.gov/homepage.html<br />
David Fann<strong>in</strong>g's Coyote's Guide: http://www.dfann<strong>in</strong>g.com/<br />
S<strong>in</strong>ce <strong>IDL</strong> is a proprietary program, you will need to log <strong>in</strong>to the astrolab mach<strong>in</strong>es to use it:<br />
ssh -X -l username astrolabXX.astro.wash<strong>in</strong>gton.edu (or -Y on a mac)<br />
where XX = 1-29<br />
<strong>IDL</strong> as <strong>in</strong>terpreter<br />
<strong>IDL</strong> works directly on the command l<strong>in</strong>e when you hit return. This makes it easy to try new<br />
statements and statement sequences. The up cursor arrow br<strong>in</strong>gs back earlier commands.<br />
Try out the follow<strong>in</strong>g <strong>IDL</strong> statements on the command l<strong>in</strong>e.<br />
On-l<strong>in</strong>e help. Before start<strong>in</strong>g idl, type <strong>in</strong> the term<strong>in</strong>al:<br />
% idlhelp<br />
Start idl:<br />
% idl<br />
<strong>IDL</strong> 1<br />
1
Try the follow<strong>in</strong>g statements. The left column gives the statement you should type <strong>in</strong>to <strong>IDL</strong><br />
through the command l<strong>in</strong>e. The right column gives you notes <strong>in</strong> italics and questions <strong>in</strong> regular<br />
text. Record your <strong>in</strong>put and answers to the questions <strong>in</strong> an Emacs file.<br />
<strong>IDL</strong> Statements Notes and Questions<br />
> pr<strong>in</strong>t, 3*5 1. What happens if you don't use a comma?<br />
> pr<strong>in</strong>t, 3*5 ; Hello there! 2. What does the ";" do? (try it without the ; )<br />
> a=3*5 This equal sign is an assignment. Read this as "a gets<br />
the value of 3 times 5."<br />
> help,a<br />
> help,A<br />
> d=32767<br />
> pr<strong>in</strong>t,d+1<br />
3. What does help do? What's the difference between<br />
us<strong>in</strong>g a and A? “INT” means <strong>in</strong>teger.<br />
Integers run from -32768 to + 32768.<br />
4. What happened?<br />
> pr<strong>in</strong>t,d+1. 5. What is the difference between us<strong>in</strong>g d+1 and d+1.?<br />
> x = d+1.<br />
> help, x<br />
> pr<strong>in</strong>t,3/5<br />
> pr<strong>in</strong>t,3/5.<br />
> width = 20<br />
> height = 5*9<br />
> pr<strong>in</strong>t, width * height<br />
> a=[1,2,3,4,5,6]<br />
> a=[a,7]<br />
Float: Float<strong>in</strong>g-po<strong>in</strong>t, with six significant places.<br />
Double: Float<strong>in</strong>g-po<strong>in</strong>t with approximately sixteen<br />
decimal digits.<br />
Str<strong>in</strong>g: A sequence of 0 to 32,767 characters.<br />
One float<strong>in</strong>g number makes the result a float.<br />
6. Expla<strong>in</strong> what happened <strong>in</strong> these three l<strong>in</strong>es.<br />
<strong>IDL</strong> 1<br />
<strong>IDL</strong> variables can be (multi-dimensional) arrays. You<br />
can lengthen array A by add<strong>in</strong>g value at the end.<br />
7. Lengthen array "a" by add<strong>in</strong>g the number 8. Provide<br />
your command.<br />
> pr<strong>in</strong>t, a, 1E6*a S<strong>in</strong>gle precision: 6 significant digits, pr<strong>in</strong>t, a, 1D6*a Double precision: 16 significant digits<br />
> pr<strong>in</strong>t, a, 1/a<br />
> pr<strong>in</strong>t, a, 1./a<br />
> pr<strong>in</strong>t, a, a^2<br />
> pr<strong>in</strong>t, a, alog10(10^a)<br />
> a=1.*a Converts <strong>in</strong>to floats<br />
8. What's the difference between the output of these two<br />
l<strong>in</strong>es? Why?<br />
alog10 is what you normally mean when you write "log"<br />
> pr<strong>in</strong>t, a, alog10(10^a) 9. Expla<strong>in</strong> the output of this statement.<br />
> pr<strong>in</strong>t, a, alog(exp(a))<br />
> pr<strong>in</strong>t, a, acos(cos(a))<br />
> pr<strong>in</strong>t, a, a mod 2 12. What does “mod” do?<br />
10. Expla<strong>in</strong> the output of these two l<strong>in</strong>es (h<strong>in</strong>t: what is<br />
“alog,” “exp,” etc? Use idlhelp).<br />
11. Do the same as the above, but replace “cos” and<br />
“acos” with s<strong>in</strong>e and arcs<strong>in</strong>e. Provide your command.<br />
2
=sqrt(a) Type of b is def<strong>in</strong>ed through its assignment.<br />
> help Help without variable shows all variables.<br />
<strong>IDL</strong> 1<br />
> pr<strong>in</strong>t,'b=',b 13. What did the quotes do? Write another command<br />
us<strong>in</strong>g quotes and a variable. Provide your command and<br />
its output.<br />
> a=<strong>in</strong>tarr(100) Simple arrays: def<strong>in</strong>e A as <strong>in</strong>teger array<br />
A(0),...,A(99)=0<br />
> a=a+1 14. What does this do?<br />
> for i=0,99 do a(i)=i This is a one l<strong>in</strong>e for loop. BEWARE! <strong>IDL</strong> starts<br />
count<strong>in</strong>g at 0!<br />
15. What did this for loop do?<br />
> a=fltarr(100)<br />
> a=dblarr(100)<br />
> a=<strong>in</strong>dgen(100)<br />
> pr<strong>in</strong>t,a(0),a(99)<br />
> pr<strong>in</strong>t,a(10:19) 18. What does the : do?<br />
16. What do these commands do? What are the<br />
differences between them?<br />
17. What is the value of the 29th element <strong>in</strong> the array a?<br />
> b=sqrt(float(a)) 19. What does the float do? Why do you need it there?<br />
> for i=0,99 do if (b(i) GT<br />
5) then a(i) = a(i) + b(i)<br />
> exit Exit <strong>IDL</strong>.<br />
Due: October 12 by 5pm<br />
This is a for loop with an if statement <strong>in</strong>side it.<br />
20. Expla<strong>in</strong> what this command is do<strong>in</strong>g <strong>in</strong> a sentence.<br />
21. What does GT mean? What is the opposite of GT?<br />
22. How is = different from EQ?<br />
23. What does the 'i' mean <strong>in</strong> b(i)?<br />
24. Make an array named c of 100 float<strong>in</strong>g po<strong>in</strong>ts <strong>in</strong><br />
order from 0 to 99 (h<strong>in</strong>t: look for <strong>in</strong>dgen <strong>in</strong> idlhelp).<br />
Provide your command.<br />
25. Make the most complicated one l<strong>in</strong>e for loop with an<br />
if statement you can! Extra po<strong>in</strong>ts go to those who use<br />
mod, log and trig functions. Provide your command.<br />
3