Skip to content

Category: IDL hints

IDL’s array index special handling, including the colon ( ‘:’ ) and the asterisk ( * )

Note that IDL 2-dimensional arrays are given as Z[A,B] where A is column ref; B is row ref

x[*] means take each element of x (separately), so

x[*] = y[*] means,
x[0] = y[0], x[1] = y[1], … up to all elements of the arrays

x[0:2] is essentially does the same but on a subset of an array; eg
take elements 0 through 2 of the array (and do “whatever”)

I read also that this notation, esp on lhs, is much much faster than
conventional looping etc.

print idl’s path and see if it can find a file within it and note capitalization conventions

IDL> print, file_which(‘chjuldaytolmstGALFA.pro’)
/usr/share/astro/idlshare/locallib/chjuldaytolmstGALFA.pro

 

and more specifically:

from https://stackoverflow.com/questions/29986130/idl-procedure-wont-compile

IDL procedure won’t compile

But when I try to find the procedure using “Findpro” I get

Procedure CHLOADCT found in directory  /data/clh93/colortables/CH/

So my paths are right. I don’t understand why it won’t find my procedure, does anyone know what’s going on?

Answers:

Things to check in situations like this:

  1. you are consistent about whether the routine is a function or procedure, i.e., routine is procedure and you are calling it as a procedure
  2. routine you are calling is either compiled already or the last routine in a file named the same as it with a .pro extension; the case of the filename and routine call must match or the filename must be all lowercase (just use all lowercase in filenames!)
  3. quick check to see if my_routine.pro is in your !path:
    IDL> print, file_which('my_routine.pro')
    

    It will return an empty string if it can’t find it.

  4. make sure the file is not in your !path twice and you are getting someone else’s or an old version

Detect input (read) error without crashing program. Complicated fortran-like reads

Fortran has the ability to send one somewhere upon an I/O error:

read(43,100,end=50) x,y,z         in which case program will go to statement labeled “50′ upon a read error.

IDL does not have such a simple way to do it. But after many hours, I got an equivalent process to work.  An example is in the
/data/psrdata/rmgalprojs/rm2016/AO_Pulsars_RM/Longi_RM_Plots.pro file, specifically in
the PersArmNoIntArm data input section.

——————————————————————————

The same section of code illustrates painful read in of a complicated data file, where a single (long) row had been turned into six. It is similar to but not quite identical to fortran. I had to eliminate all format = ‘(sd;jkfsd;jkg)’ statements because idl and i (≡fortran) did not interpret them the same. Instead I had to force variables to have the right type before reading data into them, by initializing them.  For example, to read the following variables properly, i did things like:

ztext = ‘  ‘
xfloat = 3.5
ydoubleprecision=8.d0

Then when I read a file into those variables from a file , idl will treat those variables as the types given in the initialization statements.

To edit much of IDL source incl say coyote: must be on thuban2 on root and centos7

Because mirzam was down tonight I used idl on canopus instead. In trying to run some idl galactic magnetic field idl programs on canopus, I kept hitting an obscure error on coyote’s cggreek routine which makes greek letters for plots.  Googling it I found that an idl 8.6.1 (as on canny) error prevented old cggreek from working.  (It worked ok forever on mirzy, which has I think idl 8.7)

So I installed the new cggreek from github to thuban2’s /var/share/astro/idleshare/coyote.  but this didn’t work!  why?  because i had to install it onto /var/share/astro_centos7/idleshare/coyote   Note because of access issues, one can not install directly onto /usr/share/astro on mirzy or canny, but must instead go to thuban2/var/share/astro_centos7/ as above (and see below).

by the way i used su cp etc etc on thuban 2 to overcome permission issues on canny or mirzy themselves, but prev post shows that su – on thuban2 might be easier

idl idlde show line numbers! whew!

in idlde, go to window>>preferences>>General>>Editors>>text editors and place a checkmark on “show line numbers” and then go to bottom and apply and save

 

very hard to find this –googling and manuals did not help  –joel

IDL print two arrays side by side

Solution from: 
https://stackoverflow.com/questions/25167780/output-2-array-values-to-a-text-file-using-idl

IDL> x = findgen(10)
IDL> y = findgen(10) * 2
IDL> print, transpose([[x], [y]]), format='(2F)'

--Joel