Things I Wish I'd Known about IDL -- But Didn't Know to Ask

Back to my main IDL page

Two critical, must-read web tutorials.

These are quick - a five minute read each, at most - but the techniques demonstrated are extremely powerful. There's now one abot histograms too, but that's a real brain bender...

How to Make Colors Work Right

I wrote some notes up here on how to get colors working correctly, the modern way on 24 bit displays. Get out of the 8-bit stone age!

Vastly improved Command line debugging

Check out Craig Markwardt's DXDEBUG package for some command line debugging tools that will revolutionize the way you work. Want to examine or change variables at a different level of the call stack while at a breakpoint or STOP? No problem! Get it here

Using CTAGS with IDL

ctags is a powerful tool for software development which keeps track of which source file contains the definition for a given function. Many editors, vi and emacs both included, support jumping immediately to a given function using ctags.

By default, ctags doesn't support IDL, but adding this is trivial. Create a files called .ctags in your home directory, containing the following:

--regex-IDL=/^pro[ \t]+([a-zA-Z0-9_:]+)/\1/p,procedure/i
--regex-IDL=/^function[ \t]+([a-zA-Z0-9_:]+)/\1/f,function/i
Then you can run ctags -R on the top of your IDL directory and create a ctags file containing the information about every file in your entire tree. For vim, you will want to add something like set tags=./tags,tags,../tags,~mperrin/idl/tags to your .vimrc, and then you can navigate using tags.

About !p.multi and displaying plots.

How can I get !p.multi to work right when displaying images such as with tv?

See this archived discussion. The short version is, only the plot command moves !p.multi forward, and ONLY when called without the /noerase keyword.
So how to display an image with TV or the like and have it work with !p.multi? The trick is to call plot, get the position vector, and then use that for displaying everything else.

Saving the Command History

How often have you typed some long series of commands in to the IDL prompt interactively, decided you liked something, and then wanted to save all those commands into a pro file? Turns out this is fairly easy to do.
displays your command buffer. (You did set !edit_input = 512 in your .idlstartup, right?) Copy and paste the commands you want from this list into a text file, called, say, "tmp". You'll note the order of the commands is reversed from what you want - most recent at the top, and that there are line numbers prepended. But this is no problem! Just do
tac tmp | cut -c 9- >
which will strip the line numbers and fix the command order. Then you can edit to your heart's content.

NEW! I've just found out an even better way. The IDL intrinsic command "journal" will save a copy of your command history to a .pro file. It's so simple:

IDL> journal, ''    ; start journalling                        
IDL> (user enters commands)                                                   
IDL> journal    ; stop journalling

My thanks to Liam Gumley for pointing this out on comp.lang.idl-pvwave.

How does IDL decide how many colors it has?

Colors under IDL can be very frustrating, particularly on all these old Suns with 8-bit graphics cards. See David Fanning's discussion of this here

If you want to ensure the use of a private 8-bit color table rather than just using 8 or 10 colors from the shared color table, stick the following in your .idlstartup:

 ; force the use of a private 256 color map by opening and closing
 ; a window, basically hidden offscreen.
   window,0,colors=256,ypos=-2000,xpos=3000 & wdelete, 0

VIM IDL support

My favorite editor is Vim - Vi IMproved, see My IDL mode file for vim is available here. A modified version of the matchit.vim plugin (enabling balanced matching of 'begin'/'end' pairs etc.) can be found here.