pro hello_world, number_questions,goodbye=goodbye ;+ ;pro hello_world ;Procedure to print ``Hello world'' to screen then ask 'Anyone there?' ;number_questions times. If goodbye set print 'Goodbye'. Then list ;files in my home directory. ; ;Parameters: number_questions - integer number of times to ask 'anyone there?' ;Keywords: goodbye, if this is set prints 'Goodbye' to screen ;John Marsham, (01/11/06) ;- print,'Hello world' ;print the line ''Hello world'' to screen for i=1,number_questions do begin print,'Anyone there?' endfor files=findfile('~lecjm/*',count=nfiles) ;This finds all the files in the ;directory ~lecjm ;Change this to your home directory print,'I can see',nfiles,' files. They are:' print,files if keyword_set(goodbye) then print,'Goodbye' stop; STOPS the program here end
findfile is an function built in to IDL. You can also define you own functions using .pro files. Functions are just like an procedures really, but are called with
something=function_name(parameter,... keyword=keyword) etccount is a keyword of the function findfile. We have passed one parameter (files) to the function findfile.
We'll return to more formal definitions of prodecures , functions etc later on.
Right, that's hopefully got you started. Try playing with things. Just do things on the command line. Note ``?'' brings up the IDL help as we'll see in lecture 1.
As lecture 1 explains it's very messy to keep all your code in your home direcory. You want to keep it organised in sub-directories. IDL can find it, but only if you tell it where it is (in your .cshrc fil e- lecture 1) or if IDL is started from the directory containing the code.