An IDL "Cheat Sheet"
by Chris Salter

On-Line Monitoring:

On the "observer" workstation:

1. To monitor individual spectra (e.g. 1-sec dumps)

observer% gousr
observer% cd a1763,
    If your project number is a1763
observer% idl
     To monitor each 1-sec record, get a channel-by-channel rms of records in each
     scan, to get a record # v frequency image and finally, for Standard ON/OFF data,
     a display of (ON-OFF/OFF), type;

IDL> cormonall,1
   To get out of monitoring loop:
IDL> ctrl-c
IDL> retall

   To get back in monitoring loop:
IDL> cormonall,1

   If you would like the data to be Hanning smoothed before display, use;
IDL> cormonall,1,/han

   If you just wish to see the data displayed record-by-record, use;
IDL> cormon,1                         
IDL> cormon,1,/han

2. To display a strip-chart recording of the total power by 1-sec records:

observer% idl
IDL> @phil
IDL> @corinit
IDL> lun=coronl()
IDL> corstripch,lun,maxpnt=500,v1=[.8,2]
   maxpnt is the number of 1-sec records displayed before the
   record rolls off the display edge.
   v1 defines the minimum and maximum values to display for the y-axis.

   To get out of this loop:

IDL> ctrl-c
IDL> retall

   To restart with a different vertical scale:

IDL> rew,lun
IDL> corstripch,lun,maxpnt=500,v1=[.7,1.5]

   (However, this is better achieved without leaving the program.
   Try hitting a return, and then changing the v1 parameters.)

   If on "observer" you would like to start
corstripch from
   the UNIX command line, obtaining the display in the screen
   to your upper right, obtain details on what to enter by typing;

observer% corstripch -h
   and proceed as described there.

Reducing Data in IDL for the Interim Correlator

   To start IDL, and make Phil's analysis routines available;

observer% idl


1. To open files and list scans within them

IDL> openr,lun,'/share/olcor/corfile',/get_lun
    The above file location applies to data while it is being acquired.
    To open corfile for access after you "move" your data at the end of a run,
    corfile will have the format, corfile.ddmmmyy.axxxx.n
    dd is the day number, mmm is the first three letters of the month,
    and yy is the last two digits of the year
    axxxx is your project code and n is the file sequence.
    If your data is not in /share/olcor, then try /proj/axxxx, e.g. /proj/a1763

IDL> corlist,lun
    To list all scans in corfile

    If you have finished working with a particular file, and wish to
    proceed to work with another, then it is good practice to release the
    previous "lun", as only a relatively small number can be opened before
    being told you cannot open any more! Do this as follows;

IDL> free_lun, lun

2. To reduce standard ON-OFF data

IDL> io=corposonoff(lun,b,scan=scan#,/han,/scljy)
    (ON-OFF/OFF) scaled into Jy, Hanning smoothed.
    Resulting spectrum placed in b.

IDL> io=corposonoff(lun,b,scan=scan#,/han,/sclcal)
    (ON-OFF/OFF) scaled into K, Hanning smoothed.
    Resulting spectrum placed in structure b.

3. Plotting data

IDL> corplot,b             Plot the result against frequency
IDL> corplot,b,/vel      Plot the result against velocity
IDL> corplot,b,/chn     Plot the result against channel
IDL> corplot,b,m=2    Plot second sbc v freq: m=1 is 1st sbc
   m=2 is 2nd sbc, m=4 is 3rd sbc,
   m=8 is 4th sbc.

    You will often want to restrict the range displayed for the x- and/or y-axis,
    You can do this via;

IDL> hor, x_low, x_high         to restrict the x-axis display between x_low and x_high
IDL> ver, y_low, y_high         to restrict the y-axis display between y_low and y_high

    To return the axes to plotting the full ranges of x and y values, use;
IDL> hor
IDL> ver

4. Reducing single scans (e.g. ON only)

IDL> istat=corinpscan(lun,b,scan=scan#,/han,/sum)
    Reduce single scan, records summed, Hanning
    smoothed, uncalibrated.
    Resulting spectrum placed in structure b.

5. Mathematical operations

IDL> c=cormath(a,b,/sum)
IDL> c=cormath(a,b,/sub)
IDL> c=cormath(a,b,/mult)
IDL> c=cormath(a,b,/div)
    Operate on structures a & b, producing c
IDL> bout=cormath(b1,sadd=1.34)
IDL> bout=cormath(b1,ssub=1.34)
IDL> bout=cormath(b1,smul=1.34)
IDL> bout=cormath(b1,sdiv=1.34)
    Add, subtract, multiply or divide the data by 1.34
    (i.e. a scalar).

6. Accumulating more than a single scan

IDL> coraccum,inp_struct,out_struct,/new
    Accumulate structures. Use /new only first time

IDL> corplot,out_struct
    First normalise by dividing by b.b1.accum

7. Averaging orthogonal polarizations

IDL> bpol=coravg(b,/pol)
    Average the 2 polns of structure b, placing result
    in structure, bpol

8. Smoothing spectra

IDL> corsmo, b_in,b_out,smo=n
    To boxcar smooth your data by n channels

9. Reading values off of a plot

    To use a cursor, and return the values beneath this;
IDL> cursor, x, y, /down
IDL> print, x, y
    Plot the spectrum you wish to deal with on its own before using the cursors.

10. Making a PostScript plot

    To output a plot to a postscript file. First refine a set of IDL
    instructions that will produce the plot you would like as a
.ps file.

IDL> set_plot,'ps'
IDL> device,filename='', ysize=12
IDL> {set of instructions to make desired plot}
IDL> device, /close
IDL> set_plot,'x'

11. To save and restore from your current IDL session

    To save your current working session -- including all IDL data
    structures - type;

IDL> save,file='3c258b.sav'
    To restore this to resume your IDL session;
IDL> restore,file='3c258b.sav'

    To save a number of variables, including IDL data structures - type;
IDL> save, var1, var2, var3, .... varn, file='saveset.sav'

12. Fitting baselines

    For baseline fitting, the most straightforward way is as follows;
IDL> is=corbl(b_in,b_out,/sub)
    The program will ask for input from you, and here is an example of
    the most basic input parameters;

b 2         to work on the second spectrum in the structure "b_in"
m           to set a mask within which to make the fit.
              Mark region to fit using the "left button" on the mouse,
              and signal completion of mask setting using the "right button".
f 5         will fit a 5th order polynomial, and (via "/sub")
             subtract this from the input scan.
q           to exit, placing the "fit subtracted" scan in "b_out".

   If you feel the polynomial fitting in not doing a good job, try an
   alternative fitting procedure via;


    If you wish to "roll your own", baseline fitting can be achieved via
    the routine bluser, see Phil's documentation for details. As a
    simple example as to how this might be used;

    1) One needs to first of all copy out the data from the structure of
    interest into a 1-d array;

    2) Then create an array of the same no. of elements as the data;
    Where N is the number of pixels in the array, y.
    3) Then to set a mask, fit a polynomial, etc.;
    4) This will allow you to fit a maskover which to fit the data using
'm'. Use left button of your mouse to set the mask, and
    the right button to "sign off" from mask setting.
    5) Fit an nth order polynomial by the
'f n' instruction.
    6) There are also commands for setting the display range, looking at
    the fitted polynomial, etc.
    7) Then correct and copy the corrected data back into the structure
    with something like,

IDL> newy=y-yfit
IDL> bpol.b1.d[*]=newy[*]

Working with WAPP data in a single data file

% idl
IDL> @phil
IDL> @wasinit2

IDL> file='file_spec'
    (At present, and provisionally, on-line data file are written into;
    e.g. /share/pserverf.sdb1/wappdata, which the cima dialog will
    report as /export/sdb1/wappdata, where the "sdb1" can
    change, e.g. could be sda2, sda3, etc.
    These on-line files are later moved to, e.g.,

IDL> is=wasopen(file,desc)
    (You will need to rerun this after each new source for the on-line

IDL> waslist, desc
    (To list the scans in the file)

    Then use corxxxx procedures, as in;
IDL> is=corposonoff(desc, b, scan=.........,/han,/scljy)