It's great to have plots on the screen, but you will often need to get them on paper to include in reports etc. IDL treats the screen as one device and a postscript file (which you can print) as another. You can switch devices with the set_plot command:
IDL> set_plot,'ps'will switch to postscript output and
IDL> set_plot,'x'will switch back to the screen. The device command allows you to do various things to control which postscript file your output goes to, how big your plot will appear, and so on. If you want a .png, .jpeg etc file for powerpoint, word, animations etc the easiest thing to do is plot it in a graphics window, using
IDL> set_plot,'x'then read it to file using
IDL> filename='~username/blah.png' IDL> write_png,filename,tvrd()Alternatively, use
IDL> set_plot, 'z' IDL> device, set_resolution=[640,680] IDL> plot, x, y etc... IDL> write_png, 'filename.png',tvrd()
Here is the program to plot modtran output, with extra lines added so that it will put the plot in a postscript file called modtran.ps .
;;;;;; Set up array to contain the data ;;;;;;;;;;;;;;; modtrandata=fltarr(14,201) ;;;;;; Open the file, attach it to unit no. 1 ;;;;;;;;; openr,1,'/nfs/env-fs-04_u35/jmarsham/public_html/Teaching/IDL_course/pldat.dat' ;;;;;; read the data from the file attached to unit 1 ;;;;;;; ;;;;;; into the array modtrandata readf,1,modtrandata ;;;;;; Close the file ;;;;;; close,1 ;;;;; switch to postscript output ;;;;;;; set_plot,'ps' ;;;;; set the name of the output file (if you dont set it, it is ;;;;; called idl.ps) device,file='modtran.ps' ;;;;;; Now make the plot ;;;;;; plot,modtrandata(1,*),modtrandata(11,*), $ xtitle='Wavelength / microns',$ ytitle='Radiance in Watts/(cm!U2!N Steradian Micron !4l!3m)' ;;;;;; Close the postscript file (important. The last bit of your plot ;;;;;; wont appear unless you do this device,/close ;;;;; switch back to X Window system ;;;;;;; set_plot,'x' ;;;;;; Don't forget the 'end' statement ;;;;;; endNote also the use of
device,file='~jmarsham/modtran.eps',/encapsulatedHere the general rule of using ``backslash'' keyword being equivalent to keyword=1 e.g.
\encapsulated
Note the !U or !E which gives you the superscript. !B gives you subscript. !4 gives you Greek and !3 returns you to English. So,
plot,modtrandata(1,*),modtrandata(11,*), $ xtitle='Wavelength (!4l!3m)',$ ytitle='Radiance (W/(cm!U2!N Steradian !4l!3m))'
should give you microns.
And that's it for the first session. You can now make most of the 2-D graphs that you will need. In the next session we'll look at some more sophisticated programming techniques.