ESRG UCSB Library

This page is a listing of the entire contents of this library for IDL. This listing is the long version. Viewing the much more compact listing may be handier.

[Go Back to Main IDL Libraries Search Page]


Last modified: Thu Dec 21 21:20:13 2000.

List of Routines


Routine Descriptions

ACOSD

[Next Routine] [List of Routines]
 NAME:
       ACOSD

 PURPOSE:
       Return the inverse cosine of a value, in degrees rather then radians.

 CALLING SEQUENCE:
       deg = acosd(x)

 INPUTS:
       value      cosine of angle 

 OPTIONAL INPUTS:

 OUTPUTS:
       Angle in degrees returned.

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  12/07/93

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/acosd.pro)


ADDPATH

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  addpath

 PURPOSE:  

 USEAGE:   addpath,pathname,cut=cut

 INPUT:    
   pathname   Name of new path to add to this session's directory path.
              if pathname is already present in !path no action is taken.
              This last feature allows addpath to be repeatedly executed
              (e.g., within a script) without affecting !path after the
              first invocation.

 KEYWORD INPUT:

  cut         If set and pathname is set, the element of !path that
              matches pathname is removed. If pathname is not
              specified, the last element of !path is removed.

 OUTPUT:

 DISCUSSION:

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLES:  
           addpath,'/home/paul/idl'            ; add a path

           addpath,'/local/idl/lib/wided',/cut ; remove a specific path

           addpath,/cut                        ; remove last path element 

           addpath                             ; view !path

 AUTHOR:   Paul Ricchiazzi                        04 Nov 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/addpath.pro)


AIRMASS

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  airmass

 PURPOSE:  compute airmass as a function of angle, sza, including
           spherical earth effects

 USEAGE:   result=airmass(sza)

 INPUT:    
   sza     zenith angle   

 KEYWORD INPUT:

 OUTPUT:   relative airmass,
           by definition the relative airmass = 1 for sza=0.

 References:
   Kasten, F 1966: A new table and approximate formula for relative
   airmass. Arch. Meteor. Geophys. Bioklimatol. Ser. B, 14, 206-223

   Leontieva, E.N., and K.H. Stamnes 1996: Remote sensing of cloud
   optical properties from fround-based measurements of
   transmittance: a feasibility study, Journal of Applied
   Meteorology, 35, 2011-2022
  
 EXAMPLE:  

    sza=findrng(0,89.,dx=.1)
    plot,sza,1./cos(sza*!dtor),yran=[1,30]
    plot,sza,cos(sza*!dtor)*airmass(sza)

 AUTHOR:   Paul Ricchiazzi                        09 Jan 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/airmass.pro)


ARMBASETIME

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  armbasetime

 PURPOSE: The base_time variable provided by ARM net_cdf files is the
          number of seconds since jan 1, 1970 00:00:00 UTC.  This
          procedure converts base_time to the current date in yymmdd
          format, and the number of hours since the most recent
          Grenich midnight (00:00:00 UTC).

 USEAGE:  armbasetime,base_time,time,yymmdd,file=file

 INPUT:    
   bt     number of seconds since jan 1, 1970 00:00:00 UTC.

 KEYWORD_INPUT

  file    name arm net_cdf file. If this quantity is set the value
          of bt is set from the value read from the file.


 OUTPUT:

  time    time since Grenich midnight of the current day
  yymmdd  date string in yymmdd format

  
 EXAMPLE: 
    file='/home/paul/arm/iop_97/mfrsr/sgpmfrsrC1.a1.970915.000000.cdf'
    armbasetime,file=file,bt,time,yymmdd
    print,bt,time,"   ",hms(3600*time)," ",yymmdd

 AUTHOR:   Paul Ricchiazzi                        05 Jun 98
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/armbasetime.pro)


ASIND

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       ASIND

 PURPOSE:
       Return the inverse sine of a value, in degrees rather then radians.

 CALLING SEQUENCE:
       deg = asind(x)

 INPUTS:
       value      sine of angle 

 OPTIONAL INPUTS:

 OUTPUTS:
       Angle in degrees returned.

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  12/07/93

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/asind.pro)


AUTORANGE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    autorange

 PURPOSE:    given a range of values find a good tick mark interval
             and return a properly formatted tick label.  This routine
             can be used with the axis procedure to add additional
             axis which are not linearly related to the original 
             axis (see example)

 USEAGE:     autorange,range,ntick,tickv,tickl,ntickmax=ntickmax,$
                       cv=cv,log=log,colors=colors

 INPUT:      

   range     array of values

 keyword input

   ntickmax  maximum allowed number of tick marks (default=10)

   cv       if present and non-zero, the tick values will cover a bit
            less than the full range.  Otherwise tick values cover a
            bit more than the full range.  Set CV when you want exactly
            NTICK contour levels to appear on a contour plot.

 OUTPUT:

   ntick     number of tick marks
   tickv     array of tick values
   tickl     formatted tick labels   

 KEYWORD OUTPUT
   colors    vector of color values covering full color range and having
             one less element than ntick

; EXAMPLE:

   autorange,[.011,.022],ntick,tickv,tickl & print,tickl
   0.010 0.012 0.014 0.016 0.018 0.020

; plot solar spectrum with wavenumber on the lower x axis
; and wavelength on the upper x-axis
          
   solar,wn,f
   plot,wn,f,xstyle=5,xrange=[10000,40000],ymargin=[4,4]
   axis,xaxis=0,xstyle=1,xtitle='Wavenumber (cm-1)'
   autorange,1.e7/!x.crange,ntick,tickv,tickl 
   axis,xaxis=1,xticks=ntick-1,xtitle='Wavelength (nm)',$
               xtickv=1.e7/tickv,xtickname=tickl
          
          
 REVISIONS:

  author:  Paul Ricchiazzi                            mar94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/autorange.pro)


AVERAGE

[Previous Routine] [Next Routine] [List of Routines]
 FUNCTION: This procedure computes the AVERAGE of a the nk 
           fields stored in the array tab (nbcol,nblign,nk).

 INPUTS  : tab  --> 3 dimensional array (nbcol x nblign x nk)

 OUTPUTS : moy  --> average of the fields (nbcol x nblign)
           stdv --> standard deviation (nbcol x nblign)
           nb   --> number of points used in the average

 USE     : vertaver, array1, array2, outaver,outstdc,outelmts

 CONTACT : Didier JOURDAN   didier@esrg.ucsb.edu

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/average.pro)


AXGAP

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  axgap,pos

 PURPOSE:  draw a "gap symbol" to indicate a gap in the axis number scale.

 USEAGE:   axgap,pos

 INPUT:    
   pos     two element vector indicating x,y data coordinates of the
           axis break

 KEYWORD INPUT:
   one     gap symbol drawn on one axis only

   size    size of gap symbol (default = 1, which corresponds to size
           of default minor tick marks)

   skew    control skewness of gap symbol (default 0)

   gap     controls gap size (default 1)

 OUTPUT:
   none

 DISCUSSION:
   

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE: 

   y=smooth(randomn(iseed,100),5)
   plot,y,xticks=5,xtickn=['1','2','3','4','5','20']
   axgap

 AUTHOR:   Paul Ricchiazzi                        31 Aug 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/axgap.pro)


AZIMUTH

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:          azimuth

 PURPOSE:          given a smoothly varying 2d field, AZIMUTH
                   computes the angle between the gradient direction
                   of the field and the y direction (angle measured
                   clockwise).  This is is useful for computing the
                   satellite or solar azimuth angle when all you know
                   are the satellite or solar zenith angles.  For
                   example the relative azimuth at each point in a
                   satellite image is given by

                    relaz=abs(azimuth(satzen,1,1)-azimuth(-sunzen,1,1))

                   which is the angle between the satellite unit
                   vector and the solar ray vector, both projected
                   onto the surface.

 CALLING SEQUENCE:
                   result=azimuth(image,dx,dy)
 INPUT:
    image          smoothly varying image quantity (e.g., solar zenith angle)
    dx             pixel spacing, x direction
    dy             pixel spacing, y direction

 OUTPUT:
    result         angle between grad(image) and downward direction
                   (angle increases clockwise) 
 
 LIMITATION:       the image is fit by a quadratic function of x and y
                   which is analytically differentiated to find the
                   gradient directions.  An image which is not well
                   approximated by a quadratic function may produce
                   weird results.


 EXAMPLE:
   f=cmplxgen(400,400,/center)
   tvim,f,/scale
   f=abs(f)^2      ; should be perfectly fit by a quadratic function
   a=azimuth(f,1,1)
   loadct,5
   tvim,a,scale=2,range=[-180,180,45]

  author:  Paul Ricchiazzi                            apr94
           Institute for Computational Earth System Science
           University of California, Santa Barbara


(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/azimuth.pro)


BALLOON_DRAG

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:   balloon_drag 

 PURPOSE:   compute drag on shere

 USEAGE:    result=balloon_drag(r,rho,v,cd)

 KEYWORD INPUT:    
   r        balloon radius in meters      (default=1.0 m)
   v        wind velocity (mph)           (default=5 m/s)
   rho      air density                   (default=1.29 kg/m3)
   cd       drag coefficient              (default=0.2)

 NOTE:      1 m/s = 3.60 km/hr = 2.23 mph = 1.94 knots

 OUTPUT:   
 
 result     drag force in newtons 

            
 SOURCE:    Steve Robinson
            NASA/MIT
            stever@space.mit.edu

            Drag on sphere = .5 * Cd * rho * v^2 * pi * r^2

            Cd = function of sphere Reynolds number 
                 (V*2*r)/(kinematic viscosity),
                 but 0.2 should be close.
            
 EXAMPLE:
            r=1. & v=10. & cd=.2
            rho=rhoz(p0=1013.,t0=273.,z=1.,lr=7.)
            print,balloon_drag(r,rho,v,cd)
            
  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/balloon_drag.pro)


BALLOON_LIFT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:   balloon_lift 

 PURPOSE:   compute lifting capacity of a helium balloon

 USEAGE:    result=balloon_lift(r,rho,kg=kg)

 KEYWORD INPUT:    
   r        balloon radius in meters         (default=1.0 m)
   rho      air density at operating alitude (defualt=1.29 kg/m3)

   result   lifting capacity in newtons 
            (if kg is set lifting capacity is in kg)

 EXAMPLE:   lifting capacity of a 1 m radius helium balloon at an 
            altitude of 1 km. 
      
            rho=rhoz(p0=1013.,t0=273.,z=1.,lr=7.)
            print,balloon_lift(1.,rho)

 EXAMPLE:   lifting capacity of a non-stretching 1 m radius helium
            balloon at an altitude of 1 km.  To prevent the balloon
            from bursting at high altitude the balloon should not be
            filled to full capacity with helium at sealevel. Assume
            the helium retains its sealevel temperature (maybe less
            than ambient).

 r=1
 t0 = 273.
 p0 = 1013.
 rho1 = rhoz(p0 = p0,t0 = t0,z = 1,lr = 7.)
 rho0 = rhoz(p0 = p0,t0 = t0,z = 0,lr = 7.)
 p1 = p0*(rho1/rho0)*(t0-7.)/t0
 rs=r*(p1/p0)^.3333
 print,balloon_lift(rs,rho1)

  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/balloon_lift.pro)


BARPLOT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  barplot

 PURPOSE:  produce a bar plot

 USEAGE:   barplot

 INPUT:  
   y       bar values fltarr(n)  

 KEYWORD INPUT:
   nbar    number of barplot overlays. Should only be set on the first
           call to BARPLOT

   over    if set, overplot new bar values.  

   dx      width of a bar (default=1).  An individual bar is sized to
           fill a fraction .5*DX/nn of the total plot width, where nn
           is the number of elements in y. Setting DX=2 eliminates
           blank space between adjacent bars.

   xinc    How far to move overplot bars to the left or right of the
           previous bar position (in units of the bar width).  Use
           with NBAR and XOFF to control degree to which overplot
           bars overlap previous bars. A positive value causes latter
           overplots to overlap bars starting from the left and
           finishing on the right. A negative value does the
           opposite.  (default = 0.6666)

   xoff    offset of bar with respect to labeled points on x-axis
           (default=0).  XOFF should be in the argument list and assigned
           to a named variable if NBAR, DX and XINC are used to control 
           bar overlap in multiplots.

           The xaxis labels are located at data coordinates 
           xlab=findgen(nn)+.5, where nn =n_elements(y)

   color   color index used to fill bars

   xtitle  string, x title of plot

   ytitle  string, y title of plot

   title   string, title of plot

   xlabels vector of strings used to label bar groups 

   xlabvec vector of x values at which to put XLABELS.
           if XLABVEC is not set, XLABELS are ploted at points
           .5+findgen(n_elements(xlabels))
           range of XLABVEC 0-1

   grid    if set, draw a y axis grid.  The numerical value of grid 
           is used to set the grid style (1=dotted line)

   yrange  a two element vector specifying the y axis range

   ynozero if set, y range may not include zero if all y values are
           are positive.

   xmargin two element vector specifies left and right margin around plot
           frame in units of character width.  (default = !x.margin)

   ymargin two element vector specifies bottom and top margin around plot
           frame in units of character height.  (default = !y.margin)


 OUTPUT:


 DISCUSSION:
   For best results try to arrange the order of overplots so that larger
   values of y are ploted first. See examples.

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  

  loadct,5
  y=randomu(iseed,6)
  color=[.8,.6,.3]*!d.n_colors
  dx=.6
  barplot,y,dx=dx,xlabels=1990+indgen(6),title='test',xtitle='Year',$
      ytitle='power (Watts)',color=color(0),/grid,xoff=xoff,nbar=3
  barplot,y^2,dx=dx,color=color(1),/over,xoff=xoff
  barplot,y^3,dx=dx,color=color(2),/over,xoff=xoff

; A fancier example

  y=randomu(iseed,5) & y=y(sort(y))
  xlabels=['January','February','March','April','May']
  color=[.2,.4,.6,.8]*!d.n_colors
  dx=.32
  barplot,y,dx=dx,xtitle='---- Month ----',$
        ytitle='power (Watts)',color=color(3),yrange=[0,1.],ymargin=[5,7],$
        /grid,xlabels=xlabels,charsize=1.5 ,xoff=xoff,nbar=4
  barplot,y^2,dx=dx,color=color(2),/over,   xoff=xoff
  barplot,y^3,dx=dx,color=color(1),/over,   xoff=xoff
  barplot,y^4,dx=dx,color=color(0),/over,   xoff=xoff
  x_axis,findgen(5)+.5,1.,xtickn=(y+y^2+y^3+y^4)/4,yspace=-1.5,$
         xtitle='----- Cumulative Average -----'
  x_axis,findgen(5)+.5,[1,4],xtitle='Plot Title',yspace=-.5,charsize=1.2,/ext
  legend,'.cSensor\\AVHRR 1\AVHRR 2\GTR-200\PSP',color=color,$
          /clrbox,bg=0,/box,pos=[0.06,0.57,0.23,0.98]

; use with histogram to make nicer histogram plots

  y=randomn(iseed,2000)
  yy=histogram(y,binsize=.5,min=-3)
  yy=yy(0:11)
  xlabel=string(f='(f3.0)',findrng(-3,3,12))
  ;plot,findrng(-3,3,12),yy,/xsty,psym=10  ; compare to this
  barplot,yy,dx=2,color=20,xlabel=['-3','-2','-1','0','1','2','3']
  
 AUTHOR:   Paul Ricchiazzi                        31 Aug 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/barplot.pro)


BC

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
        bc

 PURPOSE:
        wall to wall cross hairs to help read numbers off of plot
        axis. The graphics function is set to 6 for eXclusive OR.
        This allows the cross hairs to be drawn and erased without
        disturbing the contents of the window.  Hit RMB to exit

 CALLING SEQUENCE:
        bc

 INPUTS/OUTPUTS: none

 RESTRICTIONS:
        Works only with window system drivers.

 CATEGORY:
        Interactive graphics.


 author   Paul Ricchiazzi      April, 1993

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/bc.pro)


BOXONMAP

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:
   BOXONMAP, derived from IDL User Library Procedure BOX_CURSOR

 PURPOSE:
   Emulate the operation of a variable-sized box cursor (also known as
   a "marquee" selector).

 CATEGORY:
   Interactive graphics.

 CALLING SEQUENCE:
   BOXONMAP, wx0, wy0, wx1, wy1 [, INIT = init] [, FIXED_SIZE = fixed_size]

 INPUTS:
  No required input parameters.

 OPTIONAL INPUT PARAMETERS:
 wx0, wy0, wx1, and wy1 give the initial location of the lower left
       (wx0, wy0) and upper right (wnx, wny) corners of the box if the
 keyword INIT is set.  Otherwise, the box is initially drawn in the
 center of the screen.  Both input and output parameters are in
       Longitude (X) and Latitude (Y).

 KEYWORD PARAMETERS:
 INIT:  If this keyword is set, wx0, wy0, wx1, and wy1 contain the
       initial parameters for the box.

 FIXED_SIZE:  If this keyword is set, the initial parameters fix the
 size of the box.  This size may not be changed by the user.

 MESSAGE:  If this keyword is set, print a short message describing
 operation of the cursor.

 OUTPUTS:
 wx0:  X value (Lon) of lower left corner of box.
 wy0:  Y value (Lat) of lower left corner of box.
 wx1:  X value (Lon) of upper right corner of box.
 wy1:  Y value (Lat) of upper right corner of box.

 The box is also constrained to lie entirely within the window.

 COMMON BLOCKS:
 None.

 SIDE EFFECTS:
 A box is drawn in the currently active window.  It is erased
 on exit.
       A window for display of numeric latitude and longitude is created.
       It is destroyed on exit.

 RESTRICTIONS:
 Works only with window system drivers.

 PROCEDURE:
 The graphics function is set to 6 for eXclusive OR.  This
 allows the box to be drawn and erased without disturbing the
 contents of the window.

 Operation is as follows:
 Left mouse button:   Move the box by dragging.
 Middle mouse button: Resize the box by dragging.  The corner
  nearest the initial mouse position is moved.
 Right mouse button:  Exit this procedure, returning the
        current box parameters.

 MODIFICATION HISTORY:
 DMS, April, 1990.
 DMS, April, 1992.  Made dragging more intutitive.
 NFH, March, 1993,  Warp box & use map coordinates,
                          display Lat & Lon in text box.
 PJR/ESRG, March, 1994, display lat & lon in xmessage window

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/boxonmap.pro)


BOXPOS

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:   boxpos
 USEAGE:
            result=boxpos()
            result=boxpos(aspect=aspect,rmarg=rmarg,xpos=xpos,ypos=ypos,$
                         get=get,curbox=curbox,print=print)

 PURPOSE:   returns the 4 element position of a properly shaped data window.
            output is in normalized coordinates

 INPUT:

    none required

 keyword input:

    aspect       x/y aspect ratio of map (default = 1)

    rmarg        the amount of margin to leave on the right side of the
                 box.  The margin is specified in units of 10 character
                 widths, so merely setting the RMARG parameter provides
                 enough space for COLOR_KEY

    get          if set, retrieve the position information of the last
                 plot drawn. 
 
    xpos         two element vector specifying x position of a multi frame
                 plot,  the first element specifies the frame number, the
                 second element specifies the number of frames
                
    ypos         two element vector specifying y position of a multi frame
                 plot, the first element specifies the frame number, the
                 second element specifies the number of frames

    print        if set, print out the normal coordinates of the box
                 edges in format,
                                   pos=[x0,y0,x1,y1]

                 where (x0,y0) and (x1,y1) are the normal coordiates
                 of the lower left and upper right corners of the box
                 The default value of PRINT is 1 if the CURSOR keyword
                 is set.

                
 OUTPUT:
                 result=[x1,y1,x2,y2], 
                 where (x1,y1) and (x2,y2) are the lower left hand
                 and upper right hand corner of the new data window
                 in normalized coordinates.
                 
 EXAMPLE:        Draw a map over a TVIM image

     tvim,dist(200)
     map_set,0,0,/orth,/cont,/grid,pos=boxpos(/get),/noerase

                 Draw a map of the southern hemisphere with 2:1 aspect
                 ratio

     map_set,-90,0,/orth,/cont,/grid,pos=boxpos(aspect=2)
                  
                    now try a 1:1 aspect ratio

     map_set,-90,0,/orth,/cont,/grid,pos=boxpos(/aspect)

                  now allow room for color key, and draw color key

     map_set,-90,0,/orth,/cont,/grid,pos=boxpos(/aspect,/rmarg)
     color_key


                Draw a multframe plot 
 
     x=findgen(100)
     plot,x,x,pos=boxpos(aspect=1,ypos=[3,3])
     plot,x,x^2,pos=boxpos(aspect=1,ypos=[2,3]),/noerase
     plot,x,x^3,pos=boxpos(aspect=1,ypos=[1,3]),/noerase


;    NOTE: the XMULTI and YMULTI proceedures (in this directory) can
;          also be used to make multiframe plots and are more flexible
;          than BOXPOS for positioning the individual frames.

  author:  Paul Ricchiazzi                            25jan93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/boxpos.pro)


CAPTION

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  caption

 PURPOSE:  CAPTION can be used to print captions above or below a
           figures.  The character size is determined by the number
           of characters per line.  

 USEAGE:   caption,cap,xx,ybot=ybot,yt=ytop,nchar=nchar

 INPUT:    

   cap     string used for caption.  Normally all text within CAP 
           is line wrapped to produce a multiline caption. All
           white space within CAP is preserved in the caption.
           Within CAP the character "\" can be used to force a line
           break (i.e., to start a new line).  Extra white space
           following the "\" causes the text to be indented.

           t='this is a test \     junk test test'+$
             ' \     junk test \ \    junk: this is a test'

           caption,t

                             PRODUCES:

           this is a test
                junk test test
                junk test

                junk: this is a test

           Note that the backslash character must be surrounded by
           whitespace to be recognized

  
   xx      normal coordinates of left and right edge of caption
   

 KEYWORD INPUT:

   ytop       normal coordinates of top of caption
              (default=!y.window(0)-.15)

   nchar      number of characters per line

   vspace     vertical space factor, controls vertical space between
              lines (default = 1)

   bg_color   background color

   color      foreground color

   exdent     number of character positions to indent all lines except
              the first. (default=0)

   nowrap     if set do not line wrap the input text, instead use
              embedded backslash characters to control line breaks.

 KEYWORD OUTPUT:

   ybot       normal coordinates of bottom of caption. The value of
              of ybot can be used append more text with another call
              to CAPTION.

 DISCUSSION:

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  

    t1='CAPTION can be used to print captions above or below a '+$
      'figures.  The character size is determined by the number '+$
      'of characters per line.   here is a list of items: \ '+$
      '     1. item 1 \ '+$
      '     2. item 2 \ '+$
      'END OF FIRST CAPTION
       
    t2='BEGINNING OF SECOND CAPTION \ HERE is more text to add to  '+$
      'the previous text. Note how the  '+$
      'text starts immediately below the last line of the previous  '+$
      'written text. The use of ybot allows concatenation of text with  '+$
      'different right and left margins'
       
    w8x11 & !p.multi=[0,1,2]
    plot,dist(10)
       
    caption,t1,nchar=80,ybot=yy
    xwid=.5*(!x.window(1)-!x.window(0))
    xmid=.5*(!x.window(0)+!x.window(1))
    caption,t2,xwid+.5*[-xwid,xwid],nchar=40,ytop=yy

;; FILL option

    t= 'HERE is more sample text to demonstrate the use of CAPTION''s, '+$
       '"fill" option.  Note how the text is stretched to fill the '+$
       'entire width of the line.  It is probably a good idea not '+$
       'to force linebreaks using the backslash symbol while in this '+$
       'mode.  The "fill" option works best when NCHAR is large'
        
    erase
    caption,t,[.1,.9],ytop=.9,/fill,nchar=80
       
;; CAPTION used with READ_TEXT 

   caption,read_text('caption.txt','Figure 1.'),nchar=60
  

 AUTHOR:   Paul Ricchiazzi                        12 Mar 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/caption.pro)


CLASSIFY

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:         CLASSIFY

 FUNCTION:
            Display the physical locations of points selected on the
            basis of image quantities, xa and ya.  An interactive
            cursor box is used to select clusters of points from the
            2-d scatter plot of xa vs ya. These points are drawn on a
            satellite image to indicate their actual physical
            location.

 CALLING SEQUENCE:

       classify,xa,ya,class_out,image=image,class_in=class_in,select=select, $
              n_samples=n_samples,blow_up=blow_up,title=title,ytitle=ytitle, $
              xtitle=xtitle,ititle=ititle

 CATEGORY:
       Interactive graphics

 REQUIRED INPUTS:
       XA       First channel parameter, x-axis of scatter plot
       YA       Second channel parameter, y-axis of scatter plot

 OPTIONAL INPUTS (keyword parameters):
       IMAGE    Image of a particular satellite channel over which 
                points are ploted.  If not supplied points are ploted
                over blank plot

    CLASS_IN    (Byte array) Pixel color class initialization.  Each
                element corresponds to one pixel in the sample set
                (see n_samples, below). An initial run of CLASSIFY
                will generate the byte array, CLASS_OUT.  This can be
                used in a subsequent run of CLASSIFY with
                CLASS_IN=CLASS_OUT to restart CLASSIFY in its former
                state.  When set, CLASS_IN overrides the effect of
                SELECT and N_SAMPLES, below.

    N_SAMPLES   2 element vector specifying the number of samples in the
                x and y directions.  E.g., if N_SAMPLES=[100,150],
                then the scatter plot will consist of a 100x150
                element subset of the original image.  If N_SAMPLES
                is not set, a default number of samples in the x and
                y directions is used.
                
                
       SELECT   Vector of pre-selected indices (longword integers). 
                For example, SELECT=WHERE(XX LT 10) chooses only
                those sample points for which parameter xx
                is less than 10.

      BLOW_UP   Two element vector of specifying the image size blowup factor 

       TITLE    Title of scatter plot 
       XTITLE   Scatter plot x-axis label
       YTITLE   Scatter plot y-axis label
       ITITLE   Plot title of satellite image
       NO_COLOR don't use color, show points with unique symbols

 OUTPUTS
     CLASS_OUT  (Byte array) Color class of each sample point.  Values
                between 1 - 6 indicate different selected color
                classes.  Greater values indicate unselected points
                which can be selected with the cursor. CLASS_OUT can
                be used in another call to CLASSIFY, e.g.,
                CLASSIFY,XA,YA,CLASS_OUT ; followed by,
                CLASSIFY,XA,YA,CLASS_IN=CLASS_OUT


 COMMON BLOCKS:
       none

 SIDE EFFECTS:
       Two windows are created to contain the scatter plot (window 0) and
       the physical image (window 2).  Calls TVLCT to load a customized 
       color table with grey scale for byte values greater than 10 and
       discreet colors for byte values between 1 and 10.

 RESTRICTIONS:
       Works only on window system drivers

 PROCEDURE:
       Points which enter into the cursor box are hi-lighted and stored
       for plotting on the satellite image.  The left mouse button increases
       the size of the cursor box while the middle mouse button decreases it
       The right mouse button stops the selection process and displays a 
       pop-up menu with 4 options:

       (n) select a new selection class (assign a new color)
       (r) reset the selection set
       (d) display the selection set on the satellite image
       (p) save current plot to postscript file "plot.ps"
       (q) clean up displays and quit

  author:  Paul Ricchiazzi                            oct92 
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/classify.pro)


CLASSPLT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:   classplt

 USEAGE:    classplt,xx

            classplt,xx,yy,alat,alon,$
                    [title=title,xtitle=xtitle,ytitle=ytitle,sym=sym]

 PURPOSE:   Draws two seperate plots to the graphics device:
            1. 2-d scatter plot of yy vs xx
            2. physical position of selected classes with respect
               to coastline features.
 
 INPUT:
     xx       index array of selected points for a class 
              (class definition mode)

     xx       2-D array, x quantity of scatter plot (ploting mode)
     yy       2-D array, y quantity of scatter plot     
     alat     latitude array
     alon     longitude array
     title    plot title (optional).  One or two element string array
              if two strings are specified the first string is used to
              title the scatter plot while the second titles the mapped
              plot
     xtitle   x title (optional)
     ytitle   y title (optional)
     sym      a vector of symbol index values.  Classes are assigned symbols
              in the sequence specified in SYM. (default=[1,4,7,5,6,2])
              (1=+, 2=*, 3=., 4=diamond, 5=triangle, 6=square, 7=x)


 PROCEDURE:   At least two steps are required to make plots with CLASSPLT: 

              1. In class definition mode CLASSPLT is called with a single 
                 argument one or more times to accumulate class definitions
                 to be used later in the ploting mode.
              2. In plotting mode CLASSPLT is called with at least 4 
                 arguments.  In this mode CLASSPLT produces a scatter 
                 plot and position plot of the previously defined classes.

 EXAMPLE:

 a4=congrid(avhrr4,40,30)                        ; reduce size of sample set
 a3=congrid(avhrr3,40,30)                        ;   could also use SUPERPIX

 classplt,inside(a4,a3-a4,[3,6,5,3],[4,3,5,4])   ; define classes
 classplt,where(a4 gt -6 and a3-a4 lt 8)         ;
 classplt,where(a4 gt -17 and a3-a4 gt 8)        ; 

 classplt,a4,a3-a4,alat,alon                     ; make the plot

 Here is a sequence of commands which uses the interactive graphics
 procedure, INSIDE, to simplify class specifcation.
 
 classplt,inside(a4,a3-a4)
 classplt,inside(a4,a3-a4)
 classplt,inside(a4,a3-a4)
 classplt,a4,a3-a4,alat,alon

 COMMON BLOCKS: classblk


  author:  Paul Ricchiazzi                            oct92 
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/classplt.pro)


CLOUD_ART

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  cloud_art

 PURPOSE:  draw an idealized cloud

 USEAGE:   cloud_art,pos,bumps=bumps

 INPUT:    
  pos      normal coordinates of cloud frame, [xll,yll,xur,yur]
           where ll=lower left corner and ur=upper right corner


 KEYWORD INPUT:
  bumps    number of bumps on upper side of cloud. (default=6)
  

 OUTPUT:

 DISCUSSION:

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  

    w8x11
    cloud_art,[.1,.8,.9,.9],bumps=8

 AUTHOR:   Paul Ricchiazzi                        15 Mar 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/cloud_art.pro)


CLSTRSHD

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:           clstrshd

 USEAGE:            result=clstrshd(a, binsz)
                    result=clstrshd(a, binsz, /align, /compare)

 PURPOSE:           compute super pixel cluster shade statistical test
                    of a scene. the cluster shade is a test of skewness
                    in the greylevel histogram of each superpixel.

 INPUT:
         a          image array

         binsz      A scalar specifying the number of horizontal and 
                    vertical sub-pixels in one super pixel. 
                    BINSZ must be an odd integer.

         align      If set, output arrays are REBINed back up to the 
                    original size and output array cell centers are aligned
                    with input array cell centers.

         compare    if set, compare A and ABIN with the FLICK procedure

 OUTPUT:
                    cluster shade value at superpixel cell centers.

 AUTHOR:            Paul Ricchiazzi    oct92 
                    Earth Space Research Group, UCSB

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/clstrshd.pro)


CMPLXGEN

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:      cmplxgen

 USEAGE:       result=cmplxgen(nx,ny[,/center])

 INPUT:
   nx,ny       dimensions of output
 
 KEYWORD INPUT:
   center      if set RESULT is shifted so that the (0,0) point
               is the central element of the complex array

 OUTPUT:     
               float(result)     = array of column indecies
               imaginary(result) = array of row indecies

 EXAMPLE:      r=cmplxgen(4,3)

                          0 1 2 3                      0 0 0 0
               float(r) = 0 1 2 3       imaginary(r) = 1 1 1 1
                          0 1 2 3                      2 2 2 2

 AUTHOR:       Paul Ricchiazzi              oct92
               Earth Space Research Group,  UCSB

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/cmplxgen.pro)


COLOR_BAR

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  color_bar

 PURPOSE:  draw a horizontal color bar

 USEAGE:   color_bar

 INPUT:    
   levels  
     a vector of physical values (required)

   colors  
     a vector of color values. If colors is not specified a
     continuous spectrum of colors between colors values 1 and
     !d.n_colors-2 are used.


 KEYWORD INPUT:
   pos
     position of color bar in normal or subnormal coordinates
     [xmin,ymin,xmax,ymax], if pos is not specified, CURBOX is
     called to set the color bar position interactively.

   digits
     number of significant digits used in number scale label
     digits=0 causes an integer format to be used. any positive value
     causes a floating point format.

   stride
     if set, label only those intervals which have n mod stride eq 0,
     where n is the number of intervals counting left to right.
   
   subnorm
     use subnormal coordinates to specify pos. subnormal coordinates
     vary from 0 to 1 across the range of the last plotting window.
     If not set, normalized coordinates are used.
 
   labels  a string array of labels for color values. 

           if nlabels eq nlevels   ==> center labels under tick marks
           if nlabels eq nlevels-1 ==> center labels between tick marks
           otherwise               ==> execution stops, error message issued

           where nlabels=n_elements(labels) and nlevels=n_elements(levels)

   title   overall title for color bar, appears below labels


 OUTPUT:
  none

 DISCUSSION:

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  

    loadct,5
    !y.omargin=[10,0]
    !p.multi=[0,2,2]
    r=randata(50,50,s=4) & r=(r-3)
    levels=-9+indgen(10)
    colors=findrng(20,!d.n_colors,9)
    confill,r,/noscale,levels=levels,colors=colors
    confill,rotate(r,1),/noscale,levels=levels,colors=colors
    confill,rotate(r,2),/noscale,levels=levels,colors=colors
    confill,rotate(r,3),/noscale,levels=levels,colors=colors
    !y.omargin=0

    labels='10!a-'+strcompress(string(8-indgen(9)),/rem)
    title='ozone mass density (ug/m3)'
    color_bar,levels,colors,labels=labels,title=title

; use a continuous spectrum of colors

    !y.omargin=[10,0]
    !p.multi=[0,2,2]
    r=randata(50,50,s=4) & r=(r-3)
    levels=-9+indgen(10)
    colors=findrng(20,!d.n_colors,9)
    tvim,r & tvim,rotate(r,1) & tvim,rotate(r,2) & tvim,rotate(r,3)
    !y.omargin=0

    color_bar,indgen(10),labels=labels,title=title

 AUTHOR:   Paul Ricchiazzi                        09 Feb 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/color_bar.pro)


COLOR_FRAME

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  color_frame

 PURPOSE:  draw a color background on which to overlay plots

 USEAGE:   result=color_frame(color,pos=pos,xmargin=xmargin,ymargin=ymargin)

 INPUT:  
   color  
     the background color of the plot frame  
   

 KEYWORD INPUT:
   pos
     4 element vector specifying the lower left and upper right
     normalized coordinates of the plot frame [xll,yll,xur,yur]

   xmargin
     2 element vector specifying the left and right margins in character
     width units

   ymargin
     2 element vector specifying the lower and upper margins in character
     height units

   bg_color
     back ground color used outside of plot frame
;
 OUTPUT:
   result
     4 element vector specifying the lower left and upper right
     normalized coordinates of the plot frame [xll,yll,xur,yur]

 DISCUSSION: 
     COLOR_FRAME can be used to produce color backgrounds within plot
     frames.  Since COLOR_FRAME itself calls PLOT to obtain the
     default frame position, it is necessary to include the NOERASE
     keyword in the PLOT call that actually draws the plot. When this
     option is used new plots called with color_frame will not erase
     the screen even when !p.multi(0)=0.  Thus, in order to start a
     new page the user must explicitly erase the page using the ERASE
     command.  See examples.

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  

  !p.multi=[0,1,2]
  loadct,5
  xx=findrng(-2.5,2.5,200)
  yy=exp(-xx^2)
  yc=cos(xx*10)
  plot,xx,yy,pos=color_frame(50),/noerase
  plot,xx,yc*yy,pos=color_frame(70),/noerase
  erase
  plot,xx,yc^2*yy,pos=color_frame(90),/noerase
  plot,xx,yc^3*yy,pos=color_frame(110),/noerase
   
;; multi-frame plot

  loadct,5
  !p.multi=[0,1,2]
  plot,xx,yy,pos=color_frame(100,ymargin=ymulti(p,np=2)),/noerase
  plot,xx,yc*yy,pos=color_frame(60,ymargin=ymulti(p)),/noerase
   
;; plot within a plot

  loadct,5
  polyfill,[0,1,1,0,0],[0,0,1,1,0],color=bg_color,/norm
  !p.multi=0
  plot,xx,yy*yc,pos=color_frame(50),/noerase
  plot,xx,yy,pos=color_frame(100,pos=boxpos(/cur)),/noerase

 AUTHOR:   Paul Ricchiazzi                        23 Feb 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/color_frame.pro)


COLOR_KEY

[Previous Routine] [Next Routine] [List of Routines]
ROUTINE:     COLOR_KEY

PURPOSE:     draws a numbered color scale.  
             NOTE: COLOR_KEY is intended to replace PUT_COLOR_SCALE

USEAGE:     
            COLOR_KEY,pos=pos,ysize=ysize,range=range,inc=inc,$
                    charsize=charsize,barwidth=barwidth,step=step,$
                    labels=labels,title=title,colors=colors,nbotclr=nbotclr

PURPOSE:    Draws a numbered color scale

INPUT:      no required input

OPTIONAL KEYWORD INPUT:

  pos          2 element vector, x and y device coordinates of lower 
               left hand corner of color bar.  If POS is not set the
               color bar will be placed one character width to the 
               right of the lower right corner of the last defined 
               data window

  xoff         x offset of color bar from right edge of plot frame in
               units of default character with.  (default=1) xoff is
               disabled when pos is set.

  range        array which contains full range of physical values,
               The number scale limits are computed fron min(range) and
               max(range).  (default=0-255)

  inc          increment step of the number scale in physical units
               If INC is not set the number scale increment is set 
               automatically

  step         if set to one, the color table is modified with STEP_CT.
               The color scale is stepped at the number scale intervals. 

  colors       a vector of discreet colors selected from the original
               color table.  In this case the original color table is
               not modified and the number of elements of COLORS
               is used to find the number scale increments. This
               option should be used with devices that do not accept
               user specified color tables (such as the Apple Laser
               Writers).  BEWARE: when the COLORS option is used with
               TVIM's SCALE option care must be taken to ensure that
               COLOR_KEY's number scale matches the quantity values.
               Unlike the STEP option, this is not automatic (see
               example below)

  nbotclr      number of reserved colors at the bottom of the color
               table.  these colors will not appear in the color key.

  charsize     character size on number scale

  ysize        vertical size of color bar in device units. 
               if ysize is negative, the abs of ysize is interpreted
               as the normalized z coordinate of the top of the bar.

  barwidth     width of color bar (default=1)

  labels       a vector of strings used to label the color key levels
               if not set the default color key number labels are
               used.  If the number of elements in LABELS is the same
               as the number of elements in COLORS then the labels
               will appear in the middle of a given color band
               instead of at the boundary between colors.

  title        color scale title drawn to the right of the color key

  slevels      selected levels at which to mark vertical scale. If LABELS
               is also set, the number of elements in LABELS should be
               equal to either nsl, or nsl-1 where nsl is the number of
               elements in SLEVELS.  The SLEVELS input does not work when
               COLORS is also specified.

  rct          if set, reverse direction of grey scale increase.  This
               keyword can be used on black & white printers to allow
               large field values to be represented by dark colors.
               
               

KEYWORD OUTPUT

  clevels      physical values at the color key tic marks

  SIDE EFFECTS:
               if STEP is set COLOR_KEY calls STEP_CT to discreetize
               the color scale.  To return to original color table
               enter STEP_CT,/OFF

EXAMPLE:

; on devices which allow user defined color tables:

      loadct,0
      TVIM,dist(200),/scale
      COLOR_KEY,range=dist(200),inc=20,/step ; change the color scale
      COLOR_KEY,range=dist(200),inc=40,/step ; change it again

; on devices with a single hard-wired color table:

      d=dist(200)+20.
      inc=step_size(d)            ; finds good step size
      dmin=fix(min(d)/inc)*inc
      dmax=fix(max(d)/inc)*inc
      nclrs=(dmax-dmin)/inc
      colors=!p.color*indgen(nclrs)/(nclrs-1)
      TVIM,colors((d-dmin)/inc),/scale,/c_map
      color_key,range=[dmin,dmax],colors=colors


; draw one big color key which applies to all tvim images on frame
 
      !p.multi=[0,2,2]
      loadct,5
      im1=randata(128,128,s=3)
      im2=rotate(im1,5)
      im3=rotate(im1,7)
      im4=rotate(im1,2)
      range=[min(im1,max=mx),mx]
      !x.omargin=[0,20]
      tvim,im1,range=range
      tvim,im2,range=range
      tvim,im3,range=range
      tvim,im4,range=range
      color_key,range=range,xoff=10,ysize=-.97

; logarithmic scales  

      im=randata(128,128)
      im=abs(im) & im=3*(im/max(im) > .001)
      tvim,im,/rmarg ; here we assume im is the log10 of some plot quantity.

      ndec=3       ; number of decades

      slevels=[1.] ; starting value
      for i=0,ndec-1 do slevels=[slevels,(findgen(9)+2)*10.^i]
      slevels=alog10(slevels)
      labels=strarr(n_elements(slevels))
      labels(indgen(ndec+1)*9)=string(f='("10!a",i1,"!b")',indgen(ndec+1))
      color_key,range=im,slevels=slevels,labels=labels


 AUTHOR:       Paul Ricchiazzi    jan93 
               Earth Space Research Group, UCSB

 REVISIONS:
 20sep93: put in LABELS option
 21sep93: use pure white blankout color for postscript
 22sep93: put in COLORS option
 09sep96: put in SLEVELS option
 

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/color_key.pro)


COLOR_PAL

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:                 color_pal

 AUTHOR:                 Terry Figel, ESRG, UCSB 10-21-92

 CALLING SEQUENCE:        color_pal

 PURPOSE:                 Displays Color palette in a seperate window

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/color_pal.pro)


COMPASS

[Previous Routine] [Next Routine] [List of Routines]
ROUTINE:     compass

USEAGE       compass, lat0,lon0,alat,alon,rng,az
             compass, lat0,lon0,rng,az,alat,alon,/to_latlon

PURPOSE:     Given the geographical coordinates of an array of points
             on the on the earth's surface, compute the great-circle 
             distance and compass heading from the central point.
             Distances and azimuth angles about the central point are 
             provided in KM and Degrees.  

             If TO_LATLON is set, convert the specified range and
             azimuth values to lat, lon coordinates

INPUT:
  lat0       geographic latitude (degrees) of central point
  lon0       geographic longitude (degrees) of central point
 
INPUT/OUTPUT
  alat       geographic latitudes

  alon       geographic longitudes

  rng        great circle distances (km) from (lat0,lon0) to (alat,alon)

  az         azimuth angles (degrees), azimuth is measured clockwise
             from due north (compass heading)

KEYWORD INPUT:
 to_latlon   if set, rng, az input converted to lat, lon


EXAMPLE:

;; plot family of great circles passing though lat,lon=(0,0)

  rng=findrng(0,2*!pi*6371.2,400)
  map_set,/cyl,/cont,/grid
  for az=0,90,15 do begin &$
   compass,0,0,rng,az,alat,alon,/to_latlon & oplot,alon,alat & endfor
  

;; find the range and az of Janus Island from Palmer Station

  lat0=-64.767 & lon0=-64.067 & alat=-64.78 & alon=-64.11
  compass,lat0,lon0,alat,alon,rng,az
  compass,lat0,lon0,rng,az,nlat,nlon,/to_latlon 
  print,f='(6a13)','alat','alon','rng','az','nlat','nlon' &$
  print,alat,alon,rng,az,nlat,nlon


  author:  Paul Ricchiazzi                            jan93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/compass.pro)


CONFILL

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  confill

 PURPOSE:  display a contour plot with filled contours 

 USEAGE:   confill,z,x,y,xrange=xrange,yrange=yrange,charsize=charsize,$
                   title=title,stitle=stitle,xtitle=xtitle,ytitle=ytitle,$
                   aspect=aspect,colors=colors,range=range,nlevels=nlevels,$
                   rmarg=rmarg,pcharsize=pcharsize,lcharsize=lcharsize,$
                   c_thick=c_thick,c_label=c_label,c_charsize=c_charsize,$
                   c_orientation=c_orientation,c_spacing=c_spacing,$
                   downhill=downhill,xtype=xtype,ytype=ytype,$
                   c_color=c_color,labels=labels,position=position,$
                   levels=levels,rgb_data=rgb_data,noscale=noscale

 INPUT:    
  z
    array of field values

  x
    one or two dimensional array of x axis points

  y
    one or two dimensional array of y axis points

    IF z,x, and y are all one dimensional vectors and all the same
    size, it is assumed that irregularly grided data is being
    supplied.  In this case the routine TRIANGULATE is called to get
    the Delaunay triangulation of the data.  The triangulation info
    is then passed on to CONTOUR


 KEYWORD INPUT:

  title
    plot title

  xtitle
    x axis title
 
  ytitle
    y axis title

  stitle
    color key title (drawn to the right of color scale)

  noscale 
    if set, no color key will be drawn

  rmarg 
    right margin expansion factor to provide more room for extra wide
    color scale annotation (default=1)

  xrange
    x axis range. (default = [0,x_dimension-1])

  yrange
    y axis range. (default = [0,y_dimension-1])

  range
    two element vector indicating physical range over which
    to distribute contour levels. 

  nlevels
    maximum number of contour levels.  If LEVELS is not set the
    actual number of contour levels is determined automatically by
    AUTORANGE.  NLEVELS sets the maximum allowed number of levels,
    the actual number of levels may be less.

  levels
    contour level values (vector).  The default contour levels are
    set by AUTORANGE. The automatically selected levels chosen by
    AUTORANGE can be retrieved by setting LEVELS to a named variable
    which is initially undefined or set to zero.

  labels
     a vector of strings used to label the color key levels.  If not
     set the default color key number labels are used.  If the number
     of elements in LABELS is the same as the number of elements in
     COLORS then the labels will appear in the middle of a given
     color band instead of at the boundary between colors.  If COLORS
     is not set, the number of elements in LABELS should be at least
     as large as the number of color key segments plus one.  

  colors
     an array of color indicies used to fill contours.  The number of
     color values should be one less than the number of levels. The
     default colors are chosen to be uniformally distributed over the
     full color table.  The automatically selected colors chosen by
     CONFILL are:  colors=fix((!d.n_colors-2)*(1+findgen(nclr))/nclr),
     where nclr=n_elements(levels)-1.  If COLORS is set to a negative
     number these automatically chosen colors are reversed so that dark 
     colors are used to represent high intensity areas.

     NOTE: The default color indicies generated by CONFILL never
     include color index 0 or !d.n_colors-1.  These indicies are
     reserved for the overall plot background and foreground colors.
     For best results, color index 0 and !d.n_colors-1 should
     correspond to pure black and white respectively, which is
     usually the case in the predefined color tables supplied by RSI.
     A predefined color table that doesn't follow this rule can be
     redefined using TVLCT to put black and white in these slots,
     without affecting any of the filled contours used in the CONFILL
     plot:   tvlct,0,0,0,0 & tvlct,255,255,255,!d.n_colors-1
     
  c_label 
     integer array indicating which contour lines to label.  For
     example, c_label=[0,0,0,1,0,1] indicates that the contour lines
     which correspond to levels(3) and levels(5) are to be labeled.
     The number of C_LABELs should be the same as the number of
     LEVELS. By default no contour lines are labeled.

  c_thick
     thickness of contour lines (may be a vector of values),
     Default is 1.

  c_color
     color of contour lines (may be a scalor or vector of values).
     If c_color is negative then the color of contour lines is chosen
     to maximize contrast with adjacent fill colors. The default is
     not to drawn contour lines.  This keyword must be set to get 
     contour lines.

     NOTE: The number of contour levels is determined automatically
     if LEVELS is not set.  Hence, it may not be possible to guess
     how many values of LABELS, COLORS, C_LABEL, C_THICK or C_COLOR
     should be specified. It is probably safer not to include these
     parameters unless LEVELS is also specified.
        
  c_orientation
    If the FILL keyword is set, this keyword can be set to the angle,
    in degrees counterclockwise from the horizontal, of the lines
    used to fill contours.  If neither C_ORIENTATION or C_SPACING are
    specified, the contours are solid filled.
        
  c_spacing
    If the FILL keyword is set, this keyword can be used to control
    the distance, in centimeters, between the lines used to fill the
    contours.

  xtype
    Set this keyword to specify a logarithmic X axis.
        
  ytype
    Set this keyword to specify a logarithmic Y axis.
        
  downhill
    Set this keyword to label each contour with short, perpendicular
    tick marks that point in the "downhill" direction, making the
    direction of the grade readily apparent. If this keyword is set,
    the contour following method is used in drawing the contours.

    NOTE: Due to a bug in IDL_3.6,  the concurrent use of C_LABEL and
          DOWNHILL causes an IDL session crash.  For this reason the
          DOWNHILL option is disabled on IDL_3.6.
        
  aspect
    the x over y aspect ratio of the output image. If not set, the 
    aspect ratio is adjusted to fill the available plotting area.

  position
    specifies the lower left and upper right CONFILL frame position in
    normal coordinates.  When set POSITION overides the setting of
    ASPECT.

  pcharsize
    character size of numbers along x and y axis and the title
    (default is !p.charsize if non-zero, 1 otherwise)
 
    NOTE: The character size of the x and y-axis number scale
    annotation may be independently controlled by the !x.charsize or
    !y.charsize system variables.  For example, the x and y axis
    number scale characters may be made invisible by setting these
    variables to a very small non-zero number before calling CONFILL.
    Remember to restore normal character sizes by setting !x.charsize
    and !y.charsize to 1 or zero after the call to CONFILL.

  lcharsize
    character size of color key number or labels (default is
    pcharsize if set, otherwise !p.charsize if non-zero, 1 otherwise)

  barwidth
     width of color key which appears to right of contour plot (default=1).

  rgb_nodata
    if set, regions with field values less then the minimum of LEVELS
    or RANGE will be colored with the RGB values specified in
    RGB_NODATA (a scalor or three element vector).  Color index 1 is
    used for the nodata color.  When RGB_NODATA is set don't use
    color index 1 in the COLORS input vector.  

    NOTE: RGB_NODATA has no effect unless either RANGE or LEVELS is
    set.  This is because the default contour levels are set so that
    the minimum level is less than the minimum field value.

  overplot if set, current field is super imposed over a previous
    confill plot this option only works when z,x, and y are all one
    dimensional vectors and all the same size, in which case it is
    assumed that irregularly grided data is being supplied.  In this
    case the routine TRIANGULATE is called to get the Delaunay
    triangulation of the data.  The triangulation info is then passed
    on to CONTOUR.

 DEPENDENCIES: COLOR_KEY, AUTORANGE

 SIDE EFFECTS: if RGB_NODATA is set the rgb value of color index 1
               is modified

 EXAMPLES:

 loadct,5
 n=128
 zz=randata(n,n,s=4)
 xx=findrng([-120,-100],n)
 yy=findrng([20,50],n)
 confill,zz,xx,yy,title='Plot title',xtitle='x-axis',ytitle='y-axis',$
         stitle='contour levels',c_color=-1

 confill,zz,xx,yy,title='Plot title',xtitle='x-axis',ytitle='y-axis',$
         stitle='contour levels',c_color=-1,rgb_nodata=!p.color/2

; labeled regions

 levels=-3+findgen(6)*2
 labels=[' ocean','  rain!c forrest',' sand',$
         ' old!c snow',' real!c new!c snow']
 confill,zz,xx,yy,title='Plot title',xtitle='x-axis',ytitle='y-axis',$
         stitle='surface types',labels=labels,levels=levels,barwidth=.5

; contour irregularly grided data

 loadct,5
 w8x11
 n=128
 z=randata(n,n,s=4)
 x=findgen(n)
 y=findgen(n)
 !p.multi=[0,1,2]
 confill,z,x,y,title='Regularly Grided',c_color=-1

 ii=randomu(iseed,200)*(n*n-1)         ; random sample points
 zz=z(ii)                              ; random samples
 xx=ii mod n                           ;   (zz,xx,yy are vectors)
 yy=ii / n
 confill,zz,xx,yy,title='Randomly Sampled',c_color=-1

 oplot,xx,yy,psym=4,color=1,symsize=.4 ; show locations of sample points

; overlay three irregular regions in one confill plot

 loadct,5
 w8x11
 n=128
 z=randata(n,n,s=4)
 ii=randomu(iseed,200)*(n*n-1)         ; random sample points
 zz=z(ii)                              ; random samples
 xx=ii mod n                           ;   (zz,xx,yy are vectors)
 yy=ii / n
 confill,zz,xx,yy,xrange=[0,300]
 confill,zz^2,xx+150,yy/2,/overplot
 confill,sqrt(zz>0),xx+150,70+yy/2,/over


 AUTHOR:   Paul Ricchiazzi                        24 May 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/confill.pro)


CONNECTED

[Previous Routine] [Next Routine] [List of Routines]
 routine:      connected

 useage:       connected,image,nstring,view=view

 purpose:      The bi-level image is searched for all pixels which are
               are part a continous set of adjacent pixels. Those pixel
               groupings which contain fewer than NSTRING "on" pixels are
               set to zero.
 input:

   image       a bi-level image array (2d)

   nstring     the number of "on" pixels required for a given cluster of
               adjacent pixels to survive.

 output:
   image       a bi-level image with islands composed of fewer than nstring
               pixels removed.

 EXAMPLE:

   r=randata(128,128,s=2) gt 7
   connected,r,3,/view

 WARNING:      this procedure can take a lot of time for large images.
               for images larger than 64 x 64 computation times goes
               something like 
                               time=c * (NX x NY)^2

               for a DecStation 5000/240, c=7.4e-8, and 
               a 256x256 image takes about 5 minutes.

  author:  Paul Ricchiazzi                            Nov93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/connected.pro)


CONTLEV

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    contlev

 PURPOSE:    find a good set of contour levels 

 USEAGE:     result=contlev(a)

 INPUT:      
   a         an array

 KEYWORD INPUT:
   maxlev    maximum number of levels on the plot.  Setting this keyword to,
             say, 5 does not mean you will get 5 levels.  It just means no
             more than 5 levels will be generated.

 OUTPUT:
   result    a vector of contour levels

 EXAMPLE:    contour,dist(20),levels=contlev(dist(20),maxlev=8)

  author:  Paul Ricchiazzi                            feb94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/contlev.pro)


COSD

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       COSD

 PURPOSE:
       Return the cosine of an angle specified in degrees rather than radians.

 CALLING SEQUENCE:
       x = cosd(deg)

 INPUTS:
       angle   angle in degrees

 OPTIONAL INPUTS:

 OUTPUTS:
       Cosine of angle returned.

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  12/07/93

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/cosd.pro)


COSSCATANG

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       COSSCATANG

 PURPOSE:
       Return the scattering angle of the incident and emerging rays.
       NOTE:  the scattering angle is defined as 180 degrees when
       sza = vza = 0 and phi = 180.

 CALLING SEQUENCE:
       cos_omega = cosscatang(cossza, cosvza, phi)

 INPUTS:
       cossza    cosine of solar (or incident) zenith angle 
       cosvza    cosine of viewing (or emergin or satellite) zenith angle 
       phi       relative azimuth angle; this is defined as the difference
                 between the solar azimuth angle and the viewing azimuth
                 angle; when sat, sun are in the same position in
                 the sky, phi = 0

 OPTIONAL INPUTS:

 OUTPUTS:
       The scattering angle is returned.

 EXAMPLE:
 IDL> print,acosd(cosscatang(cosd(60),cosd(60),0))
       0.00000
 IDL> print,acosd(cosscatang(cosd(60),cosd(60),180))
       120.000

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  1/04/94

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/cosscatang.pro)


COV

[Previous Routine] [Next Routine] [List of Routines]
##################################
 program calculates the coefficiency of var1 and var2
##################################
 Gang He
 ESRG
 Jan. 1, 1993


ro  cov,var1, var2

std1=mstdev(var1,mean1)
std2=mstdev(var2,mean2)

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/cov.pro)


CRYSTAL

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  crystal

 PURPOSE:  compute the radius of an mie-sphere with scattering
           properties equivalent to a irregular crystal shape. 

 USEAGE:   crystal,type,area,volumn,nsph,rsph,geom=geom

 INPUT:    
   type    crystal type      description            Geom parameters
           ------------      -----------            ----------
               1             hollow column          L,a,d
               2             bullet rosette         L,a,t
               3             dendrite on plate      L,a,bb,bt
               4             capped column          L1,L2,L3,a1,a2,a3


 KEYWORD INPUT:
;

   g1,g2...    geometry parameters in order given above, The geometry
               parameters may be an array of values, in which case the
               the output is also an array.
               
   L    g1     column length (1,2) or disk thickness (3)         (um)
   a    g2     hexagonal face width (1,2,3)                      (um)
   d    g3     cavity depth at each end of column (1)            (um)
   t    g3     conical pyramid height on bullet rosettes (2)     (um)
   bb   g3     base width of dendrite (3)                        (um)
   bt   g4     length of dendrite (3)                            (um)
   L1   g1     cap thickness (4)                                 (um) 
   L2   g2     column length (4)                                 (um)
   L3   g3     other cap thickness (4)                           (um)
   a1   g4     cap hexagonal face width (4)                      (um)
   a2   g5     hexagonal face width of column (4)                (um)
   a3   g6     other cap hexagonal face width (4)                (um)

 OUTPUT:
   rsph        radius of equivalent Mie spheres (um)
   nsph        number of equivalent Mie spheres (not required for mie
               parameter calculation)
   area        area in um^2
   volume      volume in um^3


 DISCUSSION:
               According to Warren and Grenfeld, the scattering
               parameters of an irregular the crystal can be
               approximated by those of the set of equivalent Mie
               spheres, such that the both the area and volume of the
               set of spheres match those of the original crystal.

               Say the density of a given crystal type is N per unit volume
               the extinction coefficient, kappa, (per unit distance) is 
               given by,  

                     kappa = N * Q * A / 4 

               where Q is the unknown extinction efficiency and the factor
               of 4 is to turn area into average cross-sectional area.
               According to W&G, kappa is approximately given by,

                     kappa = N * Q_mie(rsph) * (nsph * pi rsph^2)

                           = N * Q_mie(rsph) * A/4

               The single scattering albedo and asymmetry factor are given by,

                     omega = omega_mie(rsph)

                     g = g_mie(rsph)


 EXAMPLE:  
;
        l=findrng(50,200,100)
        crystal,1,r,g1=l,g2=50,g3=50
        plot,l,r


 REVISIONS:

 AUTHOR:   Paul Ricchiazzi                        27 Jul 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/crystal.pro)


CURBOX

[Previous Routine] [Next Routine] [List of Routines]

 INPUTS:
   x1,x2,y1,y2
     coordinates of box edges. If XWIN,YWIN,XRNG,YRNG are set, then
     input is in data coordinates, otherwise in normalized coordinates.

 KEYWORD PARAMETERS:

   init
     If this keyword is set, the initial position of the cursor
     is given by X1,X2,Y1,Y2

   message
     If this keyword is set, print a short message describing
     operation of the cursor.

   xwin,ywin
     two element vectors giving normalized x and y coordinates of window
     subregion, for example that given by !x.window or !y.window
   
   xrng,yrng
     two elements vectors giving data range of window subregion, for 
     example, as given by !x.crange or !y.crange.  When CURBOX is used
     with TVIM (and XRANGE and YRANGE are not used with TVIM), XRNG
     and YRNG represent the total index range of the displayed
     image. X1,X2,Y1,Y2 will then be the array subrange of the
     selected region.

   index
     if set, the XRNG,YRNG,XWIN,YWIN parameters are set to the values of
     the last data window, i.e., !x.crange,!y.crange, !x.window, and
     !y.window respectively.  Setting INDEX causes X1,X2,Y1,Y2 to be
     interpreted as index range coordinates.
     
   inc
     increment by which to change cursor box size when right or left
     mouse button is pressed.  Specified in data index coordinates (i.e.,
     array index coordinate) when XWIN,YWIN,XRNG,YRNG are set, otherwise
     in normalized coordinates.  The x and y increments may be specified
     separately by providing INC as a two element array.

   label
     a string which is used to label the selected region.  The string is
     centered within the region and is sized to ensure that it fits within
     the box.  If LABEL is set the box is not erased after CURBOX returns
     
   color
     color used to label regions

   charsize
     character size used for region labels

   fill
     color used to fill box region, only effective when LABEL is set

 OUTPUTS:
   x1,x2,y1,y2
     normalized coordinates coordinates of box edges.  Howvever, if
     xwin, ywin, xrng, and yrng are set, output is in data index
     coordinates, i.e., x1,x2,y1,y2 provide the index range of the
     boxed region of the image.

     If xwin,ywin,xrng,yrng are set, the output range is clipped to be
     within the limits of xrng and yrng.  

 COMMON BLOCKS:
        None.

 SIDE EFFECTS:
        A box is drawn in the currently active window.  It is erased
        on exit.

 RESTRICTIONS:
        Works only with window system drivers.

 PROCEDURE:
        The graphics function is set to 6 for eXclusive OR.  This
        allows the box to be drawn and erased without disturbing the
        contents of the window.

        Operation is as follows:
   
        Left mouse button:   reduce box size
        Middle mouse button: increase box size
        Right mouse button:  Exit this procedure, returning the 
                             current box parameters.

        NOTE: CURBOX is designed for applications in which the aspect
              ratio of the cursor box is fixed. However, if the
              aspect ratio must be adjusted do the following: jam the
              box against one of the window borders.  If you force
              the box against the left or right borders (while
              keeping the cursor pointer within the window) box size
              is constrained to change only in the height. Similarly
              the box can be made fatter or thiner by pushing the box
              against the top or bottom. As usual the LMB decreases
              size and the MMB increases size.



; EXAMPLE
;
;    use curbox to interactively select subregions from a TVIM image

       w8x11
       !p.multi=[0,1,2]
       f=randata(128,128,s=3)
       tvim,f,/interp
       xw=!x.window & xr=!x.crange
       yw=!y.window & yr=!y.crange
        
       x1=60 & x2=80 & y1=60 & y2=80
       !p.charsize=2
       !p.multi=[4,2,4]
       curbox,x1,x2,y1,y2,xw,yw,xr,yr,/init,inc=4,/mess,label='region 1'
       confill,f(x1:x2,y1:y2),title='region 1'
       curbox,x1,x2,y1,y2,xw,yw,xr,yr,/init,inc=4,/mess,label='region 2'
       confill,f(x1:x2,y1:y2),title='region 2'
       curbox,x1,x2,y1,y2,xw,yw,xr,yr,/init,inc=4,/mess,label='region 3'
       confill,f(x1:x2,y1:y2),title='region 3'
       curbox,x1,x2,y1,y2,xw,yw,xr,yr,/init,inc=4,/mess,label='region 4'
       confill,f(x1:x2,y1:y2),title='region 4'

;    use CURBOX to find the normalized coordinates of a window region
;    of given aspect ratio

        x1=.4 & x2=x1+.3 & y1=.4 & y2=y1+.1
        curbox,x1,x2,y1,y2,/init,/mess
        print,x1,x2,y1,y2

 author   Paul Ricchiazzi      April, 1993

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/curbox.pro)


CURSIM

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:        cursim

 USEAGE:         cursim,a,yy,xx,range=range

 PURPOSE:        Use the graphics cursor to interrogate a TVIM image for
                 pixel values and positions. 

 INPUT:    

    a            image array, same size as used in TVIM image

    yy, xx       2-D arrays of "vertical" and "horizontal" position
                 in the geographical case these would be lat and lon arrays
                 If these arrays are not supplied the x and y data
                 coordinates are used instead.

 OPTIONAL INPUT:
    point        if set, CURSIM will print the range and azimuth 
                 of the cursor from this point. (Palmer = [-64.767,-64.067] )

                 When this option is used the lat,lon coordinates must
                 be available either in the data coordinates of the plot
                 (i.e., as specified by the XRANGE and YRANGE parameter 
                 in the TVIM call) or explicitly as the YY and XX parameters
                 in CURSIM

 EXAMPLE: 
                 tvim,hanning(200,200),xrange=[-180,180],yrange=[-90,90] 
                 map_set,0,0,/cont,/grid,pos=boxpos(/get),/noerase
                 cursim,hanning(200,200),point=[35,-120]

  author:  Paul Ricchiazzi                            sep92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/cursim.pro)


CURSX

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:        cursx

 USEAGE:         cursx,xx,yy,verbose=verbose

 PROCEDURE:      Use the graphics cursor to find xy point on plot.
                 xy point is written to pop-up widget. 

                 If a single argument is supplied (XX) it is interpreted
                 as an image or z value which will be evaluated when
                 the LMB is pressed. This option works with TVIM images
                 or plots drawn with CONTOUR.

                 if two arguments are supplied (XX and YY) they are
                 interpreted as the x and y values of a curve in the xy
                 plane.  The y value of the function is evaluated when
                 the LMB is pressed. This option works with plots drawn
                 with PLOT

                 Hit and drag LMB to retrieve coordinates and values
                 Hit MMB to quit and retain pop-up display
                 Hit RMB to quit and destroy pop-up

 INPUT:          
   xx            x coordinate or image array

   yy            if present this parameter indicates CURSX should be run
                 in curve follow mode (CFM). In this mode the y value at a
                 x coordiate point is indicated with a drawn symbol. The
                 symbol position follows the shape of the drawn curve as
                 the cursor is dragged across the plot.
 
 Keyword input

   psym          symbol used to mark xy point in plot follow mode.
   symsize       symbol size
   color         color of symbol
   silent        if set, pop up window will not contain operating instructions
   interpolate   if set and non-zero, interpolate between defined x and y
                 points in plot follow mode
                 

 EXAMPLE: 
  plot,dist(20)
  cursx

; display value at a point

  f=randata(100,100,s=3)
  tvim,f,xra=[100,120],yra=[30,50],xtitle='longitude',ytitle='latitude',/scale
  cursx,f

; pick values off a plot using curve follow mode

  x=findgen(200)
  y=randf(200,1.5)
  plot,x,y
  loadct,5
  thick,2
  cursx,x,y,psym=1,symsize=2,color=100
  thick,1

  author:  Paul Ricchiazzi                            sep92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/cursx.pro)


DAVERAGE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    daverage

 USEAGE:     daverage,lat,sza,yy

 PURPOSE:
             finds the daylight hour average of yy at each latitude
             point.  Average values are for spring or fall equinox

 INPUT:
   lat       array of latitude points
   sza       solar zenith angle array
   yy        function of solar zenith angle

 OUTPUT:
   result    average of yy over 12 hours (daylight)
 
 EXAMPLE:

   lat=indgen(10)*10
   sza=acos((indgen(11))*.1)/!dtor
   yy=90-sza
   !p.multi=[0,1,2]
   plot,sza,yy
   plot,lat,daverage(lat,sza,yy)



 procedure:  At the spring or fall equinox the solar zenith angle at
             a given latitude is given by,

               cos(sza)=cos(lat)*cos(phi) 

             where phi is the phase angle of the earth's rotation
             [= 2 pi*(time-12)/24)]

             thus for each value of lat we have

                     yave=integral(phi,yv)/!pi
             where,
                     yv=interpol(yy,mu,cos(lat*!dtor)*cos(phi*!dtor))
                     mu=cos(sza*!dtor)


 AUTHOR:   Paul Ricchiazzi                        24 Aug 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/daverage.pro)


DAY2JUL

[Previous Routine] [Next Routine] [List of Routines]

  REQUIRED INPUTS:
         mon         ranges from 1-12
         day         ranges from 1-31
         year        

  OUTPUTS:
         julday      Julian day, ranges from 1-365(366)

  AUTHOR:
         Jeff Hicke

  DATE:
         11/16/93


(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/day2jul.pro)


DAYAVE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    dayave

 PURPOSE:    convert quantities which depend on sza to daily averages for 
             given values of day_of_year and latitude

 USEAGE:     result=dayave(doy,lat,sza,xx)

 INPUT:      
   doy       the day of year (vector)

   lat       latitude (vector)

   sza       a vector of solar zenith angles (degrees) monitonic increasing

   xx        a vector of a quantity which varies with SZA. If
             max(sza) lt 90 then it is assumed that xx=0 when
             (cos(sza) le 0).  If this is not the case, then data
             values for the full SZA angle range [-90,90] must be
             supplied.
             

 KEYWORD INPUT
   dt        averaging interval in hours (default=0.25 hours)

   zenith    zenith angles at each time, doy and lat (24/dt,nday,nlat)
             (returned by first call of DAYAVE, see below)
             if zero or absent, DAYAVE recomputes the zenith angle at 
             each point in the (DOY # LAT) input grid.  This can be
             fairly time consuming when there are lots of grid points.
             By supplying a zero filled named variable to DAYAVE you
             can retrieve the ZENITH grid for the next call to DAYAVE.

   night     if set, the interpolated value of xx is not set to zero 
             when sza is greater than 90.  This should be used for 
             physical quantities which maintain non-zero values even
             after sunset


 OUTPUT:
   result   the integral of xx(t) dt for the given days and latitudes


 EXAMPLE:
      !p.multi=[0,1,2]
      doy=findgen(365/30+1)*30
      lat=findgen(90/10+1)*10
      sza=findgen(90/10)*10
      xx=cos(sza*!dtor)
      zenith=0.                         ; zero filled named variable to 
                                        ; retrieve zenith angle grid 
      
      yy=dayave(doy,lat,sza,xx,zenith=zenith)
      tvim,yy,xrange=doy,yrange=lat,xtitle='day of year',ytitle='latitude',$
           title='daily integral of sup(cos(sza),0)',/scale,/interp

      xx2=xx^2
      yy2=dayave(doy,lat,sza,xx2,zenith=zenith)
      tvim,yy2,xrange=doy,yrange=lat,xtitle='day of year',ytitle='latitude',$
           title='daily average of sup(cos(sza)!a2!n,0)',/scale,/interp
  
  author:  Paul Ricchiazzi                            aug94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/dayave.pro)


DCOLORS

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE         dcolors

 USEAGE          dcolors
                 dcolors,r=r,g=g,b=b,pickc=pickc,squeeze=squeeze,view=view

 INPUT:          none

 Keyword input:  

   pickc         if set, call pickc to adjust discreet colors

   squeeze       if set,  original color table is resampled to fit
                 in remaining color table index space.

   view          if set, draw palette of discreet colors to separate window

   r,g,b         red, green and blue values of discreet color table.
                 default colors:
                  r =  [  0, 255,   0, 150, 255, 196,   3,   0, 150,  98,   0]
                  g =  [  0,   0, 255, 150,   2, 126, 148, 175,   0,  94,   0]
                  b =  [  0,   0,   0, 255, 212,   0, 186,   0, 100, 150, 255]

 OUTPUT:         none
 
 PURPOSE:        loads custom colors in lower part of current color
                 scale.  If SQUEEZE is set pre-existing color scale 
                 is squeezed to fit between color index n_elements(r)
                 and !d.n_colors.
 
  author:  Paul Ricchiazzi                            jan93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/dcolors.pro)


DEGRADE

[Previous Routine] [Next Routine] [List of Routines]
 FUNCTION      degrade

 PURPOSE:      degrade image resolution by a factor of two

 USEAGE:       result=degrade(array)
 
 INPUT:   
   array       an image array of dimension NX x NY, where both nx
               ny are divisible by 2. If nx or ny are not divisible by
               2 a subimage is extracted that leaves off the last row 
               or column and is divisible by 2 in both directions.

 KEYWORD INPUT:

   min         if set the returned value for each superpixel is the min
               of each of the four subpixels

   max         if set the returned value for each superpixel is the max
               of each of the four subpixels

 output:
   result      image array of dimension NX/2 x NY/2 composed of 2 x 2 
               superpixel averages of u (except if MIN or MAX keyword is
               set, see above)

 AUTHOR:       Paul Ricchiazzi                        26 May 95
               Institute for Computational Earth System Science
               University of California, Santa Barbara 

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/degrade.pro)


DENS2D

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE     dens2d,x,y,g,nbins=nbins,xrange=xrange,yrange=yrange,$
               title=title,xtitle=xtitle,ytitle=ytitle,psym=psym,$
               grid=grid,tvim=tvim,scale=scale,contur=contur


 PURPOSE     Compute and/or display the density function of a 2-d scatter
             of points with coordinate x and y

 INPUTS:
     x       array of values
     y       array of values (same size as x)

 OUTPUTS:    
  g          2-d histogram array of size nbins(0) x nbins(1)

 OPTIONAL INPUTS (keyword parameters):
  nbins      1 or 2 element vector, number of bins in x and y direction
             default is (20,20)
  xrange     2 element vector, binning range in x direction
  yrange     2 element vector, binning range in y direction
  charsize   character size
  title      plot title
  xtitle     x axis label
  ytitle     y axis label
  psym       symbol used for scatter plot, if negative don't plot points
  grid       if set, show binning grid 
  contur     if set, draw in density contours (default)
  confill    if set, use CONFILL is used to draw contours
  tvim       if set, use TVIM to display the point density function
             if tvim is set to 1 image is smoothed
             if tvim is set to 2 image is not smoothed 
  scale      if set, draw in a color scale      
                 0=> no color scale
                 1=> regular color scale (default)
                 2=> stepped color scale

 EXAMPLE
     x=randomn(is,2000)
     y=4*randomn(is,2000) + x^3
     dens2d,x,y,g,/tvim,/grid

     dens2d,x,y,/tvim,/contur

     dens2d,x,y,psym=-1,/contur

 AUTHOR:     Paul Ricchiazzi,  Earth Space Research Group, sep92

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/dens2d.pro)


DIGITIZE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    digitize

 PURPOSE:    digitize hardcopy graphical information.

 USEAGE:     digitize,x,y

 INPUT:      none

 KEYWORD INPUT:
   xr        x axis range of hardcopy plot, prompted for if not supplied
   yr        y axis range of hardcopy plot, prompted for if not supplied

 OUTPUT:
   x         vector of x coordinate values
   y         vector of y coordinate values


 PROCEDURE:  1.  make a photo copy of the graph  on tranparency film.

             2.  run DIGITIZE and enter the x and y axis range.

             3.  align the hard copy graph onto the axis drawn by DIGITIZE
                 and use scotch tape to stick the film onto your screen

             4.  click with LMB on the axis end points (will prompt)

             5.  trace over the plot with cursor, LMB adds points, MMB
                 erases points and RMB exits the program

             NOTE: Because the outer glass surface of the screen is not
                   on the same plane as the displayed image their is a 
                   slight parallax effect between the tranparency and the
                   DIGITIZE grid.  The parallax error is minimized by
                   keeping your line of sight normal to the screen.
  
 EXAMPLE:    
             digitize,x,y        ; try it
             plot,x,y

 REVISIONS:

  author:  Paul Ricchiazzi                            sep93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/digitize.pro)


DOC

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    doc

 PURPOSE:    find and display help for a named procedure

 USEAGE:     doc,'name'

 INPUT: 
   name      name of idl .pro file.  Asterisk characters, "*", in NAME
             specify wild card matches to 1 or more arbitrary characters.


 PROCEDURE:  DOC searches through the files /local/idl/help/*.help 
             trying to find matches for the file specification, NAME.  

             if there are no matches a brief failure message is displayed
                  and control returns to the terminal

             if 1 match is found, help for the specified procedure is 
                  displayed and control returns to the terminal

             if 2 or more matches are found a menu is generated 
                  from which selections can be made.  Control returns to 
                  the terminal when the DONE button of the MENUW widget
                  is pressed.


 EXAMPLE:
             doc,'legend'            ; exact match found in ESRG_LOCAL
             
             doc,'tv*'               ; many matches found, browse through
                                     ; choices.  Notice that all procedure
                                     ; libraries are searched


  author:  Paul Ricchiazzi                            may94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/doc.pro)


DOCKEY

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    dockey

 PURPOSE:    display help documententation of file headers which
             contain matches for specified keywords

 USEAGE:     dockey,'name',keyword=keyword,all=all,minmatch=minmatch

 INPUT: 
   keywords  keyword string. Keywords withing the KEYWORDS must be
             separated by blanks. 

 KEYWORD_INPUT

   minmatch  the minimum number of keyword hits required for a procedure
             to be listed in the hit-list menu. 

 PROCEDURE:  DOCKEY searches through the helpfiles in subdirectory
             /local/idl/help, trying to find matches for the keywords.
             If more than one file match is found a menu of procedure
             names is displayed from which the desired procedure
             can be selected.  The parenthisized number next to each
             procedure name is the number of keyword matches, which
             can vary between one to the total number of keywords in
             KEYWORDS. 

             MAN_PROC is used to display the text

 EXAMPLE:
             dockey,'simpson rule integration';  pick group 'numerical'
            
             dockey,'polar orthographic'      ;  pick group 'esrg'

             dockey,'color key image',m=2     ;  pick group 'color'

; 


  author:  Paul Ricchiazzi                            may94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/dockey.pro)


DYDX

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    dydx

 PURPOSE:    compute numerical derivative accurate to second order. 
             In most cases this should be more accurate than the 
             IDL userlib procedure DERIV.

 USEAGE:     dydx(x,y)

 INPUT:
    x        vector of independent variable (monitonic)
    y        vector of dependent variable

 KEYWORD INPUT:
   lin_end   if set, use a one sided linear approximation for end points

 OUTPUT:     numerical derivative dy/dx

 EXAMPLE:    
     !p.multi=[0,1,2]
     x=[0.,1.,3.,8.,10.,13.,17.,19.,22.,25.]
     y=x*(25-x) & yp=25-2*x & labels=['analytic','dydx','deriv']
     plot,x,y,title='quadratic [dydx(x,y) is exact in this case]'
     plot,x,yp & oplot,x,dydx(x,y),psym=2 & oplot,x,deriv(x,y),psym=4
     legend,labels,li=[0,0,0],psym=[0,2,4],pos=[0.5,0.7,0.75,0.98]

     x=[0.0,0.5,1.5,2.,3.,3.6,4.0,5.,6.,6.3]
     y=sin(x) & yp=cos(x) 
     plot,x,y,title='sin(x)'
     plot,x,yp & oplot,x,dydx(x,y),psym=2 & oplot,x,deriv(x,y),psym=4
     legend,labels,li=[0,0,0],psym=[0,2,4],pos=[0.25,0.7,0.50,0.98]

     x=[-2.,-1.,-.7,-.3,-.1,0.,.1,.3,.7,1.,2]
     y=exp(-x^2) & yp=-2*x*y
     plot,x,y,title='gausian'
     plot,x,yp & oplot,x,dydx(x,y),psym=2 & oplot,x,deriv(x,y),psym=4
     legend,labels,li=[0,0,0],psym=[0,2,4],pos=[0.5,0.7,0.75,0.98]
             

 REVISIONS:

  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/dydx.pro)


EARTHDIST

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       EARTHDIST

 PURPOSE:
       Calculate the great circle distance (in km) based on lats and lons.  

 CALLING SEQUENCE:
       dist = earthdist(lat1,lon1,lat2,lon2)

 INPUTS:
      lat1        latitude of first point
      lon1        longitude of first point
      lat2        latitude of second point
      lon2        longitude of second point

 KEYWORD INPUTS:

 OPTIONAL INPUTS:

 OUTPUTS:
       Distance along great circle returned.

 OPTIONAL OUTPUTS:

 EXAMPLE:
  
      print,earthdist(0,0,0,1)
      111.189

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  4/05/94

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/earthdist.pro)


EI

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       EI

 PURPOSE:
       Set the system variable to allow for large pasting of data using
       X.  Only necessary for the alphas.  This has the side effect of 
       not allowing use of the editing (arrow) keys.  This procedure
       toggles this ability on and off.  NOTE:  This is probably a bug
       in IDL and therefore the need for this procedure will disappear in
       the near future.

 CALLING SEQUENCE:
       ei

 INPUTS:

 OPTIONAL INPUTS:

 OUTPUTS:

 EXAMPLE:
     ei
     ... paste in large amts of data ...
     ei

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  1/04/94

 MODIFICATION HISTORY:

     Added change of prompt  Jeff Hicke   05/20/94

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/ei.pro)


ENDPS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       ENDPS

 PURPOSE:
         close postscript file, reopen display

 CALLING SEQUENCE:
       ENDPS

 INPUTS:

 KEYWORD INPUTS:
        notime     don't timestamp

 OPTIONAL INPUTS:

 OUTPUTS:

 OPTIONAL OUTPUTS:

 EXAMPLE:

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  9/22/92

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/endps.pro)


EXPINT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:       expint

 PURPOSE:       compute the exponential integral of x.
                the exponential integral of index n is given by
 
                    integral( exp(-tx)/x^n dx)  

                range of integration is 1 to infinity

 USEAGE:        result=expint(ind,x)

 INPUT:
   ind          order of exponential integral, for example use ind=1
                to get first exponential integral, E1(x)
   x            argument to exponential integral ( 0 < x < infinity)
 OUTPUT:
   result       exponential integral

 SOURCE:        Approximation formula from Abromowitz and Stegun (p 231)

  author:  Paul Ricchiazzi                            9DEC92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/expint.pro)


EYE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  eye

 PURPOSE:  draw an eye symbol to show observer position and look direction

 USEAGE:   eye,x0,y0,angle=angle,size=size,color=color,icolor=icolor,$
               data=data,device=device

 INPUT:    
  x0,y0    coordinates of eye symbol position (normal coordinates by default)

 KEYWORD INPUT:
  angle    angle of symbol wrt due right alignment
  size     symbol size
  color    color index used to draw eye outline
  icolor   color index used to draw iris
  data     if set, x0,y0 in data coordinates
  device   if set, x0,y0 in device coordinates

 EXAMPLE:  
   

  plot,[0,1],/nodata
  arrow,0,1,.5,.5,/data
  eye,.55,.45,/data,size=3,angle=135

; here is a interactive method to place the eye symbol

  !err=0 & angle=0 & x=.5 & y=.5
  tvcrs,.5,.5,/norm & while !err ne 4 do begin &$
   !err=0 &$
   eye,x,y,angle=angle,size=5,color=0 &$
   cursor,x,y,/norm,/nowait  &$
   if !err eq 1 then angle=angle-5 &$
   if !err eq 2 then angle=angle+5 &$
   eye,x,y,angle=angle,size=5 &$
   wait,.05 &$
 endwhile
 cmdstr=string(f='("eye,",2(g10.3,","),"angle=",g10.3)',x,y,angle)
 print,strcompress(cmdstr,/remove_all)

 AUTHOR:   Paul Ricchiazzi                        10 Dec 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/eye.pro)


FIGNUM

[Previous Routine] [Next Routine] [List of Routines]
 routine:        fignum

 useage:         fignum,fig=fig,charsize=charsize,font=font

 input:          none

 keyword input:  
   fig
     if FIG is set to an integer greater than zero figure numbering 
     is enabled and the initial figure number is set to FIG.  If FIG
     is set to zero figure numbering is disabled.  If FIG is set to a
     string scalar then that string will be appended to "Figure" and
     written to as usual.  For example fignum,fig="4a" writes "Figure 4a".

 output:         none

 PURPOSE:
     automatical increment a figure number index and draw the number
     on a sequence of plots.
     

 COMMON BLOCKS: fignum_blk
                       
 EXAMPLE:        

 plot,dist(20)
 fignum,fig=1,font='!3',charsize=2
 for i=1,4 do begin & plot,dist(20) & fignum & pause & end

  author:  Paul Ricchiazzi                            22sep92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/fignum.pro)


FILL_ARR

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:          fill_arr
 
 USEAGE:           fill_arr,a,ii
                   fill_arr,a,ii,niter=niter,omega=omega,tol=tol,po=po

 PURPOSE:          fill in undefined regions of a 2-d array by interpolation

 INPUT:
       a           array with some undefined points
       ii          index array of good image points, 
                   E.G., ii=where(aa ne 999)
 KEYWORD INPUT
       tol         maximum tolerance to achieve before stopping iteration
                   (default=0.001)
       niter       number of smoothing iterations (default=100)
       po          if set print diagnostic print out every PO iterations

 OUTPUT:
       a           image array with initially undefined points replaced
                   with values that vary smoothly in all dimensions
                   Initially defined points are unchanged.

 PROCEDURE:        repeat this sequence

                   
                   asave=a(ii)
                   a=smooth(a,3)
                   a(ii)=asave                   

 AUTHOR            Paul Ricchiazzi               29oct92
                   Earth Space Research Group    UCSB

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/fill_arr.pro)


FILL_IMAGE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:          fill_image
 
 USEAGE:           fill_image,a,ii

 PURPOSE:          fill in undefined regions of a 2-d array by interpolation

 INPUT:
       a           image array with some undefined points
       ii          index array of bad image points, 
                   E.G., ii=where(aa eq 999)

 keyword input
   extrapolate     if set extrapolation is used to fill in bad values outside
                   of region covered by convex hull of good points.
 OUTPUT:
       a           image array with initially undefined points replaced
                   with values that vary smoothly in both the horizontal and 
                   vertical directions.  Initially defined points are
                   unchanged.

 PROCEDURE:        Use TRIANGULATE and TRIGRID to establish a linear
                   interpolation function which is used to fill in
                   the undefined regions.  The points used to
                   generate the triangulation are immediately
                   adjacent to the undefined regions. "Good data" regions
                   are unchanged.  Execution time is increased if a
                   large fraction of the image is undefined.

 EXAMPLE:

   a=fltarr(16,16)
   x=[4,11,4,11]
   y=[4,4,11,11]
   a(x,y)=[1,2,4,3.]
   fill_image,a,where(a eq 0.),/extra
   tvim,a,/scale
   print,a(x,y)

; create a test pattern, splatter on some "no data"
; and fix it back up with FILL_IMAGE
; compare original data with fixed up data

   w8x11
   !p.multi=[0,2,2]
   loadct,5
   a=randata(256,256,s=3) & a=a-min(a) & aa=a
   tvim,a>0,/scale,title='Original Data',clev=clev
   contour,a>0,/overplot,levels=clev
   a(where(smooth(randomu(iseed,256,256),21) gt .51))=-999.; bad values
   tvim,a>0,/scale,title='Missing Data'
   fill_image,a,where(a eq -999)
   tvim,a>0,/scale,title='Restored data'
   contour,a>0,/overplot,levels=clev
   confill,aa-a,levels=[-1,-.1,-.01,.01,.1,1],title='Difference',/asp,c_thic=0

 AUTHOR            Paul Ricchiazzi                          29oct92
                   Institute for Computational Earth System Science
                   University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/fill_image.pro)


FINDEX

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  findex

 PURPOSE:  Compute "floating point index" into a table for use with
           INTERPOLATE.

 USEAGE:   result = findex(u,v)

 INPUT:    
   u       a monitically increasing or decreasing 1-D grid
   v       a scalor, or array of values

 OUTPUT:
   result  Floating point index. Integer part of RESULT(i) gives
           the index into to U such that V(i) is between
           U(RESULT(i)) and U(RESULT(i)+1).  The fractional part
           is the weighting factor

                          V(i)-U(RESULT(i))
                          ---------------------
                     U(RESULT(i)+1)-U(RESULT(i))


 DISCUSSION: 
           This routine is used to expedite one dimensional
           interpolation on irregular 1-d grids.  Using this routine
           with INTERPOLATE is much faster then IDL's INTERPOL
           procedure because it uses a binary instead of linear
           search algorithm.  The speedup is even more dramatic when
           the same independent variable (V) and grid (U) are used
           for several dependent variable interpolations.

  
 EXAMPLE:  

; In this example I found the FINDEX + INTERPOLATE combination
; to be about 60 times faster then INTERPOL.

  u=randomu(iseed,200000) & u=u(sort(u))
  v=randomu(iseed,10)     & v=v(sort(v))
  y=randomu(iseed,200000) & y=y(sort(y))

  t=systime(1) & y1=interpolate(y,findex(u,v)) & print,systime(1)-t
  t=systime(1) & y2=interpol(y,u,v)            & print,systime(1)-t
  print,f='(3(a,10f7.4/))','findex:   ',y1,'interpol: ',y2,'diff:     ',y1-y2

 AUTHOR:   Paul Ricchiazzi                        21 Feb 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/findex.pro)


FINDRNG

[Previous Routine] [Next Routine] [List of Routines]
 useage:      findrng,x1,x2,x3
 purpose:     generates x3 floating point numbers 
                 spanning range x1 to x2 

 KEYWORD
   dx     if set ignor x3 and compute number of elements with 1+(x2-x1)/dx
           where dx is the increment
 
  author:  Paul Ricchiazzi                            jan93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/findrng.pro)


FINTERP

[Previous Routine] [Next Routine] [List of Routines]
 FUNCTION       finterp 

 USEAGE         result=finterp(table,uvar)

 PURPOSE:       Compute the floating point interpolation index of
                UVAR(i,j,k...) into TABLE(*,i,j,k...) or TABLE(*).
                For example, if uvar(i,j) is half way between
                table(4,i,j) and table(5,i,j) then result(i,j)=4.5.

                NOTE: If TABLE is a vector the action of FINTERP is
                the same as INTERPOL(findgen(n),TABLE,UVAR). However,
                FINTERP should be much faster whenever UVAR is large
                and the number of TABLE values (first dimension of
                TABLE) is small.


 INPUT    

    table       A matrix or vector.  If TABLE is not a vector, the 
                first dimension of TABLE is interpreted as a vector
                of values that correspond to each element of UVAR.
                If TABLE is a vector, the action of FINTERP is the
                same as INTERPOL(findgen(n),TABLE,UVAR)


    uvar       a matrix of field values.

 OUTPUT:
    result      the floating point interpolation index of  UVAR(i,j,k...)
                into TABLE(*,i,j,k,...). 
 
; EXAMPLE:

 a=[[5.1,8.4],[6.7,3.1]]
 tbl=fltarr(5,2,2)
 
 tbl(*,0,0)=3+findgen(5)
 tbl(*,1,0)=4+findgen(5)
 tbl(*,0,1)=4+findgen(5)*2
 tbl(*,1,1)=findgen(5)
 fi=finterp(tbl,a)
 print,f='(8a9)',' ','UVAR','/---','----','TBL','----','---\','FI' &$
 print,f='(a9,7f9.2)','(0,0):',a(0,0),tbl(*,0,0),fi(0,0) &$
 print,f='(a9,7f9.2)','(1,0):',a(1,0),tbl(*,1,0),fi(1,0) &$
 print,f='(a9,7f9.2)','(0,1):',a(0,1),tbl(*,0,1),fi(0,1) &$
 print,f='(a9,7f9.2)','(1,1):',a(1,1),tbl(*,1,1),fi(1,1) 
   
 
; EXAMPLE:
                Map surface albedo over some area, given satellite
                radiance measurement on a 2d grid.  Assumptions:

                 1. ff(m,i,j) = irradiance predictions at each point
                    in a 2d grid.  The m index is over different
                    values of surface albedo.  The table values vary
                    from point-to point (the i and j indecies) due to
                    changes in satellite and solar viewing angles as
                    well as surface albedo.

                 2. salb(m) = a vector of different surface albedos
                    used in the model caculations.  

                 3.  aa(i,j) = actual measured values of radiance
                     on the same grid. 

                To retrieve the optical surface albedo at each point
                in the image use INTERPOLATE to compute the surface
                albedo at each point:

                     salb_map=interpolate(salb,finterp(ff,aa))

                or if logrithmic interpolation is desired

                     fndx=finterp(ff,aa)
                     salb_map=interpolate(alog(salb_map+1),fndx)
                     salb_map=exp(salb_map)-1.

 PROCEDURE:     uses WHERE to identify regions for interpolation.
                a separate call to WHERE is used for each table interval.
                The floating point index may extrapolate beyond the
                limits of the TABLE. Hence UVAR values less-to or
                greater-than the corresponding TABLE entries will
                produce return values which are outside the TABLE
                subscript range (INTERPOLATE knows how to handle this).

 RESTRICTIONS:  Table entries (first index of TABLE) must be monitonically 
                increasing. If the table is not monitonically increasing
                FINTERP only finds solutions for that part of the table
                which is monitonically increasing.  In this case, the return
                value for UVAR elements less than the relative minimum of
                TABLE is set to -9999.

  author:  Paul Ricchiazzi                            apr93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/finterp.pro)


FLICKER

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	FLICKER

 PURPOSE:
	Flicker between two output images

 CATEGORY:
	Image display, animation.

 CALLING SEQUENCE:
	FLICKER, A, B

 INPUTS:
	A:	Byte image number 1, scaled from 0 to 255.
	B:	Byte image number 2, scaled from 0 to 255.

       if a and b are not supplied FLICKER will enter interactive mode
       wherin the user will be asked to select two windows (by a LMB
       click inside the chosen window).  These two windows will be read
       using tvrd() and compared.
       
               

 KEYWORD PARAMETERS:
	None.

 OUTPUTS:
	No explicit outputs.

 COMMON BLOCKS:
	None.

 SIDE EFFECTS:
	Sunview: Modifies the display, changes the write mask.
	X and Windows: uses two additional pixmaps.

 RESTRICTIONS:
	None.

 PROCEDURE:
  SunView:
	Image A is written to the bottom 4 bits of the display.
	Image B is written to the top 4 bits.
	Two color tables are created from the current table, one that
	shows the low 4 bits using 16 of the original colors, and one
	that shows the high 4 bits.  The color table is changed to
	switch between images.
  Other window systems:
	two off screen pixmaps are used to contain the images.
       on exit image A is left on the display

 MODIFICATION HISTORY:
	DMS, 3/ 88.
	DMS, 4/92, Added X window and MS window optimizations.
       PJR/ESRG, 1/94, "flicker" control by mouse
       PJR/ESRG, 1/94, put in tvrd() of windows for interactive use


 EXAMPLE:
       window,0,xs=200,ys=200 & plot,sin(dist(10))
       window,1,xs=200,ys=200 & plot,sin(dist(10)+.05)
       window,2,xs=200,ys=200 & plot,sin(dist(10)+.1)
       window,3,xs=200,ys=200 & plot,sin(dist(10)+.15)
       flicker  ; choose two windows to compare
       
  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/flicker.pro)


FLIGHT_ANGLE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  flight_angle

 PURPOSE:  compute zenith and azimuth of a unit vector pointing "up" 
           in coordinate system attached to an aircraft.

 USEAGE:   flight_angle,pitch,roll,heading,zenith,azimuth

 INPUT:    
  pitch    pitch angle (degrees) positive values indicate nose up
  roll     roll angle (degrees) positive values indicate right wing down
  heading  compass direction aircraft is pointed. Positive values
           represent clockwise, with respect to true North.  NOTE:
           This heading is the direction the airplane is pointed, not
           the direction it is moving

 KEYWORD_INPUT

  radians  if set all input and output angles are in radians

 OUTPUT:

  zenith   zenith angle of "up" unit vector
  azimuth  azimuth angle of "up" unit vector.  Positive values 
           represent clockwise, with respect to true North.

 EXAMPLE:  
 
;  compute the solar zenith angle of a airbourne sensor given 
;  (roll,pitch,heading) = (2,3,45) degrees at 10 am today

   doy=julday()-julday(1,0,1994)                          
   zensun,doy,12,34.456,-119.813,z,a,/local
   print,f='(6a13)','z','a','sunzen','sunaz','sunmu','corrected'
   flight_angle,2.,2.,45.,zen,az
   print,zen,az,z,a,cos(z*!dtor),muslope(z,a,zen,az)
   flight_angle,2.,-2.,45.,zen,az
   print,zen,az,z,a,cos(z*!dtor),muslope(z,a,zen,az)
   flight_angle,2.,0.,0.,zen,az
   print,zen,az,z,a,cos(z*!dtor),muslope(z,a,zen,az)
           

 AUTHOR:   Paul Ricchiazzi                        25 Feb 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/flight_angle.pro)


FONTS

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:       fonts

 userage:       fonts,greek=greek,math=math,gothic=gothic,script=script,$
                   italic=italic,all=all

 PURPOSE:       display available fonts in a new window
 INPUTS:        none
  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/fonts.pro)


FORDATA

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:      fordata

 USEAGE:       fordata,name,v,format=format,margin=margin,ng=ng,append=append

 PURPOSE:      print a fortran data statement to file "junk" 
               defining variable NAME with data values v

 input:
   name        name of variable or string to placed between the fortran
               "data" and "/" keywords, as in 
 
               data NAME / ...

   v           vector of values

 keyword input
   format      format specifier (string) of the form 
               x# or x## x#.# x##.# where x = { i, g, f, e } 
               and # is a digit (default = 'g10.4').  Note that
               the format string does not include parenthesis.

   append      append to file "junk"

   margin      number of leading blanks (margin=0 starts at column 7)
               (default=2)

   ng          number of elements written in an implied fortran loop
               for example ng=5 in the following snippit of fortran 

               data (v(i),i=1,5)/10,12,24,11,22/
               data (v(i),i=6,10)/13,44,45,22,33/

               The default value is chosen to produce 20 fortran
               continuation statements.  pick a smaller value if 
               the number of continuations allowed on your fortran
               compiler is less than 20.  Set ng to a large number
               if no implied loops are desired.

 output:       none
 
 Side effects: writes data statement to file "junk"

 EXAMPLE:

   v=sin(findgen(200))
   fordata,'(v(i),i=1,100)',v(0:99),f='f12.6'
   fordata,'(v(i),i=101,200)',v(100:199),f='f12.6',/append

; automatically put in fortran implied do list to avoid an excessive
; number of continuation statements    

   fordata,'v',v
                                  

  author:  Paul Ricchiazzi                            jun92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/fordata.pro)


FORDATIN

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    fordatin

 PURPOSE:    read fortran data statements

 USEAGE:     result=fordatin(file,varname)

 INPUT:      
   file      name of fortran source file containing target
             data statement (string)

   varname   name of fortran variable initialized in data statement 
             (string)

 KEYWORD INPUT:
 pu          the name of the program unit which contains the data
             initialization.  Specify enough of the leading
             characters of the program unit name to make it
             unique. White space and case are ignored.  For example

                    pu='subroutine foo'
                    pu='      subroutine   foobar' 
                    pu='SUBROUTINE FOOBAR(x1,' 

             all match 

                    subroutine foobar(x1,x2,x3)    ! a comment

 help        print this documentation header

 OUTPUT:
   result    array of initial values of variable VARNAME.

 PROCEDURE:  FORDATIN first searches through the fortran source file
             for a program unit matching PU (if this optional
             parameter is provided).  Next it looks for a line
             containing the keywords DATA and the variable name
             VARNAME. It reads all the following characters until it
             finds two matching forward slashes (/).  All characters
             between the matching slashes are scanned and turned into
             either an integer or float array as appropriate.
             

 RESTRICTIONS:
             this routine is designed to extract the part of the data
             block following a typical array initialization such as

                 data varname/ 1,2,3,4,5,5
                &          7,8,9/

             if the data statement looks like 

                 data (varname(i),i=1,3) /1,2,3/        
                 data (varname(i),i=4,6) /3,2,4/

             you can read the data as

                 v1=fordatin('file.f','(varname(i),i=1,3)')
                 v2=fordatin('file.f','(varname(i),i=4,6)')
                 v=[v1,v2]

             but beware, FORDATIN will read all the numbers between
             slashes in a multi-variable data statement such as

                 data v1,v2,v3/12,24,25/ 

 EXAMPLE:
             
; plot temperature profile of TROPICAL standard atmosphere

             z1=fordatin('/home/paul/rtmodel/atms.f','z1')
             t1=fordatin('/home/paul/rtmodel/atms.f','t1')
             plot,z1,t1

; plot coalbedo of ice particles as a function of wavelength

             wl=.29*(333.33/.29)^(findgen(400)/399)
             w=fordatin('/home/paul/rtmodel/cloudpar.f','(ww(i,14),i=1,mxwv)')
             plot,wl,1.-w,xrange=[0,4]

 REVISIONS:

  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/fordatin.pro)


FORM_FEED

[Previous Routine] [Next Routine] [List of Routines]
 routine       write a form feed (ascii 12) to file connected to LUN
 useage        form_feed,lun
 input         
   lun         unit number

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/form_feed.pro)


FREE_ALL

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  free_all

 PURPOSE:  free up all logical units

 USEAGE:   free_all

 OUTPUT:   none

 DISCUSSION:
           Produces a list of all open files.  For each item in the
           list the user may enter one of the following reponses:

           quit -- do not close this file, quit free_all
           view -- do not close this file, view list of remaining open files
           all  -- close this file and all remaining open files
           yes  -- close this file
           no   -- do not close this file

           Note: only the first letter of the response is actually used in
           free_all.

 SIDE EFFECTS:
           closes open files
  
 EXAMPLE:  
         IDL> openw,/get_lun,lun1,'junk1'
         IDL> openw,/get_lun,lun2,'junk2'
         IDL> openw,/get_lun,lun3,'junk3'
         IDL> openw,/get_lun,lun4,'junk4'
         IDL> openw,/get_lun,lun5,'junk5'
         IDL> free_all
         Close junk1, logical unit 101 (quit,view/all/yes/no)?: y
         Close junk2, logical unit 102 (quit,view/all/yes/no)?: y
         Close junk3, logical unit 103 (quit,view/all/yes/no)?: a 
         Close junk4, logical unit 104 
         Close junk5, logical unit 105 
         

 AUTHOR:   Paul Ricchiazzi                        17 Mar 98
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/free_all.pro)


GENGRID

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE      gengrid
 USEAGE       gengrid,a0,a1,a2,a3,a4
 PURPOSE      convert the input quantities from vectors to arrays
              of dimension (nn0,nn1,nn2,nn3,nn4) where nn0=n_elements(a0),
              etc. 

                 a0(i) => a0(i,*,*,*,*) for i=0,nn0-1
                 a1(i) => a1(*,i,*,*,*) for i=0,nn1-1
                 a2(i) => a2(*,*,i,*,*) for i=0,nn2-1
                 a3(i) => a3(*,*,*,i,*) for i=0,nn3-1
                 a4(i) => a4(*,*,*,*,i) for i=0,nn4-1

 INPUT:
   a0         input vector or scalor array size of the first index
   a1         input vector or scalor array size of the second index
   a2         input vector or scalor array size of the third index
   a3         input vector or scalor array size of the fourth index
   a4         input vector or scalor array size of the fifth index

              if one of these arguments is set to a scalor, then that
              value is used to set the dimension of corresponding 
              array subscript

 EXAMPLE:    
              a0=[1,2,3,4,5]
              a1=[10,20,30]
              gengrid,a0,a1
              print,a0
              
                         1  2  3  4  5
                         1  2  3  4  5
                         1  2  3  4  5
              print,a1
                        10 10 10 10 10
                        20 20 20 20 20
                        30 30 30 30 30

              here are some other examples:

              ;turn a 5 element vector into a 5x6 array

              x=findgen(3)
              gengrid,x,6
              print,x

                   0.00000      1.00000      2.00000
                   0.00000      1.00000      2.00000
                   0.00000      1.00000      2.00000
                   0.00000      1.00000      2.00000
                   0.00000      1.00000      2.00000
                   0.00000      1.00000      2.00000

              ;turn a 5 element vector into a 6x5 array

              x=findgen(3)
              gengrid,4,x
              print,x

		    0.00000      0.00000      0.00000      0.00000 
		    1.00000      1.00000      1.00000      1.00000 
		    2.00000      2.00000      2.00000      2.00000 
               

  author:  Paul Ricchiazzi                            mar93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/gengrid.pro)


GEN_COASTLINE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  GEN_COASTLINE

 USEAGE:   gen_coastline
           gen_coastline,alat,alon,file=file,image=image

 PURPOSE:  generate coastal outline map for satellite images

 INPUTS:   ALAT         2-D array of image latitude values (one value for
                        each image pixel)
           ALON         2-D array of image longitude values

                        if ALON and ALAT are not provided,
                        GEN_COASTLINE assumes a linear mapping of lat
                        and lon to the current x and y ploting range.

           FILE         Name of map coordinate data file. If FILE is
                        not provided, GEN_COASTLINE queries for an
                        output file name.  FILE is written in portable
                        XDR binary format which can be read by the 
                        companion procedure COASTLINE.

 OPTIONAL KEYWORD INPUT:
           image        Image from which to infer coastal outline.
                        If an image array is not provided, it is assumed
                        that an image has already been displayed using
                        the TVIM procedure.
           
 SIDE EFFECT:           writes map file in current working directory

 PROCEDURE:
  Before entering input mode the following pop-up menu appears,
 
 1. DEFINE AN OPEN CURVE                 Start a new coastal outline segment

 2. DEFINE A CLOSED CURVE                Start an island outline segment

 3. QUIT                                 Flush buffers and quit.  
 
 After option 1 or 2 is selected, coastline coordinates are input by 
 using the mouse to click on coastal features from an image in the 
 default window.  The mouse buttons perform the following actions:

 LMB: left mouse button connects points along coastline
 MMB: middle mouse erases most recent point(s)
 RMB: right mouse button finishes a coastline segment.
    
 If a coastal outline is intended to represent an island (option 2), 
 pressing the RMB causes the last point on the curve to be connected 
 to the first.

 The collection of [latitude, longitude] coordinates are written to the
 file FILE.  This map data file can be used as input for the companion
 procedure,  COASTLINE.PRO which plots the coast line data onto arbitrarily
 oriented image files. 


 EXAMPLE:
          x=findgen(128)
          y=findgen(128)
          gengrid,x,y
          d=randata(128,128,s=4)
          d=d gt 3
          gen_coastline,y,x,file='junk.dat',image=d
          coastline,file='junk.dat',/view

 AUTHOR:     Paul Ricchiazzi    oct92 
             Earth Space Research Group, UCSB

 REVISIONS
 29oct92: accomodate TRACE revision of 29oct92

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/gen_coastline.pro)


GIF_READ

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:      gif_read

 PURPOSE:      copy image on current window to a gif image file

 USEAGE:       gif_read,file

 INPUT:
   file        gif file name

 KEYWORD INPUT:
  view         if set display the image 

 OUTPUT:       
   im          image array
   r,g,b       color vectors

 SIDE EFFECTS: if VIEW is set, the color table is altered to match the
               RGB settings read from the file

 EXAMPLE:
               loadct,5
               window,0
               tvim,sin(hanning(200,200))
               gif_write,'test_image.gif'
               wdelete,0
               gif_read,'test_image.gif',/view

  author:  Paul Ricchiazzi                            feb94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/gif_read.pro)


GIF_WRITE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:      gif_write

 PURPOSE:      copy image on current window to a gif image file

 USEAGE:       gif_write,file

 INPUT:
   file        output file name, image will be written in gif image format

 KEYWORD INPUT:
   wid         index of the idl window from which to copy the image,
               if not set gif_write copies from current default window

   bgc         background color.  sets color index 0 of gif image to 
               specified RGB value.  Does not affect current color table.
               A scalor value of BGC is automatically turned into a color
               triplet, i.e., bgc=255   =>  RGB=[255,255,255]

   fgc         foreground color.  sets color index 255 of gif image to 
               specified RGB value.  Does not affect current color table.
               A scalor value of FGC is automatically turned into a color
               triplet, i.e., fgc=0   =>  RGB=[0,0,0]

 OUTPUT:       none

 EXAMPLE:
           loadct,5
           window,0
           tvim,sin(20*hanning(200,200)*dist(200)),title='GIF test image',/sc
           gif_write,'test_image.gif',fgc=0,bgc=[210,255,210]
           exit

           xv test_image.gif

  author:  Paul Ricchiazzi                            feb94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/gif_write.pro)


GLOBE_IMAGE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE   globe_image

 AUTHOR:                 Terry Figel, ESRG, UCSB 10-21-92

 USEAGE:   globe_image,image

           globe_image,image,animation,title=title,limits=limits,$
                    windowsize=windowsize


 PURPOSE:             Display an image on a rotating globe


 INPUT    input           image quantity
 OUTPUT   output          3d array containg output images for animation

 Optional keyword input:

          title       plot title
          windowsize  Controls the size of the window, Directly responsible
                      for memory usage
          limits      4 item array [min lat,min lon,max lat,max lon] of
                      input image, if omitted presumed global 
                      coverage [-90,0,90,360]
			whole      treats image as whole world for map_image

 SIDE EFFECTS:        Uses a LOT of MEMORY ~30-50 MEGS, takes a few minutes
                      to set up animation
                      If windowsize left at 300 approx 13 megs used on DEC

 PROCEDURE            GLOBE_IMAGE first map an image to a globe
                      Then it saves the image, rotates 10 degrees and repeats
                      Then it animates the saved images

 LOCAL PROCEDURES:    None

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/globe_image.pro)


GLOBE_IMAGE2

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE   globe_image

 AUTHOR:                 Terry Figel, ESRG, UCSB 10-21-92

 USEAGE:   globe_image,image

           globe_image,image,animation,title=title,limits=limits,$
                    windowsize=windowsize


 PURPOSE:             Display an image on a rotating globe


 INPUT    input           image quantity

 Optional keyword input:

          title       plot title
          windowsize  Controls the size of the window, Directly responsible
                      for memory usage
          limits      4 item array [min lat,min lon,max lat,max lon] of
                      input image, if omitted presumed global 
                      coverage [-90,0,90,360]
			whole      treats image as whole world for map_image

 SIDE EFFECTS:        Uses a LOT of MEMORY ~30-50 MEGS, takes a few minutes
                      to set up animation
                      If windowsize left at 300 approx 13 megs used on DEC

 PROCEDURE            GLOBE_IMAGE first map an image to a globe
                      Then it saves the image, rotates 10 degrees and repeats
                      Then it animates the saved images

 LOCAL PROCEDURES:    None

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/globe_image2.pro)


H2OSAT

[Previous Routine] [Next Routine] [List of Routines]
 routine:      h2osat

 purpose:      compute saturated density of water vapor

 useage:       result=h2osat(t)

 input:
   temp        air temperature in kelvin

 output:
   result      water vapor density at 100% saturation (g/m3)
               if keyword vp is set result is saturated water 
               vapor pressure (mb).  

                            
      NOTE:         h2osat(t)=h2osat(t,/vp)/Mkt

               where M is the molecular mass of h2o, and k
               is boltzman's constant.

 reference:    Here is how I came up with the polynomial fit you see below

               1. copy out table of saturated water vapor pressure 
                  vs temparature from Handbook of Chemistry and Physics 
               2. find a polynomial fit of log(P) vs (1/t) 
                  (Clausius-Clapeyron equation has P = Po exp(-to/t))
               3. convert vapor pressure to density using the molecular mass
                  of H2O (standard isotope mix)

 EXAMPLE:                                              

;  compute water density at a relative humidity of 50% and
;  an air temperature of 25 C.

               k=1.38e-23 & rh=.5 & t=25.0+273.15 & p=101325.
               wdens=h2osat(25.0+273.15)
               wden=rh*wdens/(1.-k*t*wdens*(1.-rh)/p)

; at pressures greater than ~300mb this is well approximated by

               wden=rh*wdens



; compute water density (g/m3) corresponding to a dew point
; temperature of 10 C and ambient temperature of 25 C.
; The dew point is the temperature to which air must be 
; cooled at constant pressure and constant mixing ratio to
; reach 100% saturation with respect to a plane water surface
;
;      by definition    mixing ratio ~ Nw/(N-Nw) = SVP(Tdew)/(P-SVP(Tdew))
;
;          Nw kT/(P-Nw kT) = SVP(Tdew)/(P-SVP(Tdew))
;
;          Nw = SVP(Tdew)/kT

;
; where SVP is the saturated vapor pressure

               tdew=10.+273.15
               t=25+273.15
               
               Pvap=h2osat(tdew)
               wden=h2osat(tdew)*tdew/t    ; mass density   (g/m3)


  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/h2osat.pro)


HILIGHT

[Previous Routine] [Next Routine] [List of Routines]
 FUNCTION: This procedure 
           - select values according to a user defined criterion
           - display the selected values.
           - display the histogram of the selected values in the
             array tab.

 INPUTS  : tab1     --> 2 or 3 dimensional array (NO DEFAULT)
         : thresmin --> minimum value for which the value 
                        is selected (NO DEFAULT if use - see OPTIONS)
         : thresmax --> maximum value for which the value 
                        is selected (NO DEFAULT if use - see OPTIONS)

 OPTIONS : select  --> if thresmin and thresmax are ommitted 
                       allows to specify the criterion based on a 
                       different array features.
           binsize --> defines the size of the bin for the
                       histogram (DEFAULT = 1.)

 USE     : HILIGHT, ARRAY1, 10., 20., BINSIZE=1 : 
               select and display on the the values in arrray1
               between 10. and 20. 

           HILIGHT, ARRAY1, SELECT=WHERE(ARRAY2 LE 5.43) :
               select and display the values in the array1 where
               array2 is less or equal than 5.43  


 CONTACT : Didier JOURDAN   didier@esrg.ucsb.edu

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/hilight.pro)


HILITE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:     hilite,im,select

 EXAMPLE:     hilite,avhrr1,where(avhrr3-avhrr4 lt 5.)

 PURPOSE:     To hilite a region which satifies a specified set of 
              conditions

 INPUT:       im          2-D image array (any type but string)
              select      Index array of points to hilite.  These may be
                          generated with the WHERE proceedure.
              rate        rate of flicker

 KEYWORD INPUT:
              keep        do not destroy window on exit
              zoom        2 element vector which specifies zoom factor
                          in x and y direction

 OUTPUT:                  NONE
 COMMON BLOCKS:           NONE
 SIDE EFFECTS:            Creates and uses a new window 
 
 PROCEEDURE:  Selected region is hilighted by use of the FLICK proceedure.

 EXAMPLE

    c=cmplxgen(100,100,/cent)/20
    s=sin(float(c+c^2))
    mve,c
    hilite,s,where(float(c+c^4) gt 1. and imaginary(c+c^4) lt 1.),zoom=2

  author:  Paul Ricchiazzi                            sep92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/hilite.pro)


HIST

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       HIST

 PURPOSE:
         call histo procedure to plot a histogram with
         correct values along the x-axis.  Calculates min, max for you.
         If binsz is set, uses it, otherwise = 1.
       

 CALLING SEQUENCE:
       hist,variable

 INPUTS:
         arr    array to be plotted

 KEYWORD INPUTS:

 OPTIONAL INPUTS:
         binsz         bin size of histogram
         /abs      --> compute the histogram in number of values
         /cumul    --> compute the cumulative histogram
         /overplot --> overplot the histogram

 OUTPUTS:

 OPTIONAL OUTPUTS:

 EXAMPLE:

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  9/22/92

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/hist.pro)


HIST2D

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       HIST2D

 PURPOSE:
       Plot a 2-dimensional histogram.

 CALLING SEQUENCE:
       hist2d,x_values,y_values

 INPUTS:
       x_variable     self-explanatory
       y_variable     self-explanatory

 KEYWORD INPUTS:
       bindim         number of bins on one side
       tvim           plot image rather than contour
       xtitle         title for x axis
       ytitle         title for y axis
       title          title for plot
       nlevels        number of levels for contouring
       follow         keyword to contour to select algorithm allowing labeling
       c_charsize     contour charsize

 OPTIONAL INPUTS:

 OUTPUTS:

 OPTIONAL OUTPUTS:

 EXAMPLE:

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  3/15/94

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/hist2d.pro)


HISTO

[Previous Routine] [Next Routine] [List of Routines]
 FUNCTION: This procedure displays the histogram of 
           the array tab1.

 INPUTS  : tab1 --> array
         : mini --> minimum value 
         : maxi --> maximum value 
         : bin  --> size of bin 

 OUTPUTS : diplay

 keyword Input:
           default   --> percentage 
           /abs      --> compute the histogram in number of values
           /cumul    --> compute the cumulative histogram 
           /overplot --> overplot the histogram  
           title     --> title of plot
           xtitle    --> xtitle of plot
           ytitle    --> ytitle of plot
           xrange    --> xrange of plot
           yrange    --> yrange of plot

 USE     : histo, array1,0,500,1, /cumul

 CONTACT : Didier JOURDAN   didier@esrg.ucsb.edu

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/histo.pro)


HMS

[Previous Routine] [Next Routine] [List of Routines]
 NAME:         hms

 PURPOSE:      convert time in seconds to a time string in hh:mm:ss format

 USEAGE:       time_string=hms(time)
 
 INPUTS:       time (seconds)

 RESTRICTIONS  time must be positive

 KEYWORDS:     none

 OUTPUTS:      return time string

 AUTHOR:       Paul Ricchiazzi       4jan94
               Earth Space Research Group, UC Santa Barabara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/hms.pro)


IMAGE_IT

[Previous Routine] [Next Routine] [List of Routines]
 This routine plots an image onto a predifined coordinate system.
 The calling order would be
 map_set,/cont
 image_it,bytscl(image),lat,lon
 map_set,/cont


Notice I used the bytscl of image, to take up the full color map

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/image_it.pro)


INSIDE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:       inside

 USEAGE:        RESULT = inside(xx,yy)
                RESULT = inside(xx,yy,xpoly,ypoly,nbin=nbin)

 PURPOSE:       find the indices of the data quantities xx and yy which
                lie inside a given polygonal region

 INPUT: 
   xx           vector of quantity x, ploted on x axis of scatter plot
   yy           vector of quantity y, ploted on y axis of scatter plot

 OPTIONAL INPUT:

   xpoly        vector of x coordinates vertices of polygon
   ypoly        vector of y coordinates vertices of polygon
 
 OPTIONAL KEYWORD INPUT:

   psym         if set, selected points are marked with symbol psym.
                if psym=3, the screen is erased and a new plot is drawn.
                this only works if the boundaries are specified 
                interactively.

   nbin         number of bins with which to resolve the polygon.
                A two element vector may be used to specify number 
                in x and y directions seperately.  (DEFAULT = 100)

 OUTPUT:
                returned value = vector of array indecies inside polygon

 PROCEDURE:     If xpoly and ypoly are not supplied, the operator 
                specifies the region using the interactive graphics
                procedure, TRACE.
                

 EXAMPLE
          x=randomn(seed,20,20)
          y=sin(5*x)+.8*randomn(seed,20,20)
          plot,x,y,psym=3
          i1=inside(x,y,psym=4)         ; the indecies of the data points
          i2=inside(x,y,psym=5)         ; which are inside polygonal area
          

 AUTHOR:              Paul Ricchiazzi    oct92 
                      Earth Space Research Group, UCSB

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/inside.pro)


INTEGRAL

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:        integral

 USEAGE:         result=integral(x,y,xrange=xrange,accumulate=accumulate)

 PURPOSE:        integration by trapezoid rule

 INPUT:
   x             vector of x axis points. If XRANGE is not set,
                 limits of integration will be from x(0) to x(n_elements(x)-1)
                 If XRANGE is not set, X need not be monitonic.

   y             vector of corresponding y axis points

 KEYWORD_INPUT:

   xrange        2 element vector, lower and upper limit of integration
                 The use of XRANGE with a non-monitonic variation in x may
                 produce incorrect results.

   accumulate    if set, return value is a vector giving the accumulated
                 integral at each value of x. XRANGE can't be used when
                 this option is set.

 OUTPUT:         result of integration

 EXAMPLE:
;                 /4
; find            |  x dx
;                 /0 
  x=findgen(5) & y=x
  print,integral(x,y)     
  8.00000                             ; answer for linear integrand is exact


;                 /5.5
; find            |  x^2 dx
;                 /0 

  x=findgen(7) & y=x^2               &$
  print,"    numerical     analytic" &$
  print,integral(x,y,xrange=[0,5.5]), 5.5^3/3
     56.3750      55.4583             

; use more resolution in x to improve answer

  x=findgen(551)/100. & y=x^2        &$
  print,"    numerical     analytic" &$
  print,integral(x,y), 5.5^3/3
     55.4584      55.4583             ; much better

  author:  Paul Ricchiazzi                            3NOV92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

 REVISIONS:
 sep93: fixed error in treatment of xrange, added examples
 apr96: allow use of xrange with monitonically decreasing x

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/integral.pro)


INTERP

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    interp

 PURPOSE:    interpolate on a table of up to 5 dimensions

 USEAGE:     result=interp(table,utab,u,[vtab,v,[xtab,x,[ytab,y,[ztab,z]]]])

 INPUT:
   table     table of values depending on upto 5 parameters

   utab      1-d  (monitonically increasing) table of 1st parameter 
   u         array of values of 1st parameter
   vtab      1-d  (monitonically increasing) table of 2nd parameter
   v         array of values of 2nd parameter
   xtab      1-d  (monitonically increasing) table of 3rd parameter
   x         array of values of 3rd parameter
   ytab      1-d  (monitonically increasing) table of 4th parameter
   y         array of values of 4th parameter
   ztab      1-d  (monitonically increasing) table of 5th parameter
   z         array of values of 5th parameter

   NOTE:     the number of input parameters must be appropriate to
             the size of the look-up table.  For example for a 3-d table,
             parameters ytab,y,ztab, and z should not be supplied.

 KEYWORD INPUT:
  GRID       if set the input parameters are used to create a grid of
             parameter values.  In this case the input parameters need not
             be all the same size but should all be vectors.  If GRID is
             not set all input arrays (u,v,x,y,z) and the returned value
             are of the same size and dimensionality.

  MISSING    The value to return for ARRAY elements outside the bounds 
             of TABLE.  If MISSING is not set return value is either
             the nearest value of TABLE or an extrapolated value, depending
             on how CLIP is set. 

  CLIP       If this keyword is set, locations less than the minimum or 
             greater than the maximum corresponding subscript of TABLE
             are set to the nearest element of TABLE.  The effect of 
             MISSING is disabled when CLIP is set.

   i1...i5
   f1...f5   these keywords are used in conjunction with the use_if
             keyword.  If use_if is not set, the i's and f's are
             calculated and returned.  If use_if is set, the i's and
             f's are not calculated but taken from the keywords.
             This is useful when there exists multiple TABLEs based
             on the same dimensions and variables, and one wishes to
             improve the performance.  In this case, the first time
             INTERP is called, the i's and f's are specified in the
             call but use_if is not set.  In subsequent calls, use_if
             is set.

   use_if    keyword to indicate that i's and f's should not be calculated
             but rather are input by user
 
 OUTPUT:
   result    interpolated value

 PROCEDURE:  FINDEX is used to compute the floating point interpolation
             factors into lookup table TABLE. When the dimensionality 
             of TABLE is 3 or less and either CLIP or MISSING is set,
             then IDL library procedure INTERPOLATE is used to perform the
             actual interpolations.  Otherwise the interpolations are
             explicitly carried out as mono-, bi-, tri-, tetra- or
             penta-linear interpolation, depending on the
             dimensionality of TABLE.

 EXAMPLE:

; Here is an example of how to interpolate into a large DISORT
; radiance lookup table to find radiance at given values of optical
; depth, surface albedo, relative azimuth, satellite zenith
; angle and solar zenith angle.

  file='~paul/palmer/runs/0901a.dat'
  readrt20,file,winf,wsup,phidw,topdn,topup,topdir,botdn,botup,botdir,$
                   phi,theta,rad,tau,salb,sza

  phi=phi(*,0,0,0)
  theta=theta(*,0,0,0)
  tauv=alog(1.25^findgen(20)+1.)
  taut=alog(tau+1.)
  sa0=findgen(10)*.1

;   rel azimuth    sat_zen   surface_albedo
      p0=130 &      t0=20 &      s0=60
  buf=interp(rad,phi,p0,theta,t0,taut,tauv,salb,sa0,sza,s0,/grid)
  plot,exp(tauv)-1.,buf(0,0,*,9)
  for i=0,8 do oplot,exp(tauv)-1.,buf(0,0,*,i)

  An example for use_if:

    DISORT is used to build two look up tables, RTM_bb_botdn and RTM_bb_topdn,
    based on the same parameters of tau, sza, wv, and o3.  Given measurements
    of these variables, BOTDN and TOPDN can be interpolated.  However, since
    the measurements are the same, and the LUTs are built similarly, it is
    redundant to calculate the i's and f's twice.

  bb_botdn = interp(RTM_bb_botdn,    $
                    RTM_bb_tau,       all_tau_arr, $
                    RTM_bb_sza,       all_sza_arr, $
                    RTM_bb_wv,        all_wv_arr , $
                    RTM_bb_o3,        all_o3_arr, $
                    i1=i1,f1=f1,i2=i2,f2=f2,i3=i3,f3=f3,i4=i4,f4=f4)
  bb_topdn = interp(RTM_bb_topdn,    $
                    RTM_bb_tau,       all_tau_arr, $
                    RTM_bb_sza,       all_sza_arr, $
                    RTM_bb_wv,        all_wv_arr , $
                    RTM_bb_o3,        all_o3_arr, $
                    i1=i1,f1=f1,i2=i2,f2=f2,i3=i3,f3=f3,i4=i4,f4=f4,/use_if)

  
  author:  Paul Ricchiazzi                            sep93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/interp.pro)


INTERSECT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	INTERSECT

 PURPOSE:
	Return the an array that is the intersection of the two input arrays.

 CATEGORY:
	Array manipulation.

 CALLING SEQUENCE:
	x = INTERSECT(array1, array2)

 INPUTS:
  Arrays    The arrays to be scanned.  The type and number of dimensions
            of the array are not important.  

 OPTIONAL INPUTS:
   nodata:  This is the value returned if no value in the both of the
            arrays.  The default is -1.

   xor_flag if this keyword is set, only values are returned that belong
            to one array or the other, but not both,
            i.e., the complement of the set of intersection.
            

 OUTPUTS:
	     result = An array of the values

 EXAMPLE:

     x = [0,2,3,4,6,7,9]
     y = [3,6,10,12,20]

; print intersection of x and y

     print,intersect(x,y)
          3        6

; print xor elements

     print,intersect(x,y,/xor_flag)
          0       2       4       7       9      10      12      20

; print values in x that are not in y        

     xyu=intersect(x,y,/xor_flag) & print,intersect(x,xyu)
          0       2       4       7       9     


 COMMON BLOCKS:
	None.
 
 AUTHOR and DATE:
     Jeff Hicke     12/16/92

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/intersect.pro)


JD2YMD

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       JD2YMD
 PURPOSE:
       Find year, month, day from julian day number.
 CATEGORY:
 CALLING SEQUENCE:
       jd2ymd, jd, y, m, d
 INPUTS:
       jd = Julian day number (like 2447000).     in
 KEYWORD PARAMETERS:
 OUTPUTS:
       y = year (like 1987).                      out
       m = month number (like 7).                 out
       d = day of month (like 23).                out
 COMMON BLOCKS:
 NOTES:
 MODIFICATION HISTORY:
       R. Sterner.  21 Aug, 1986.
       Johns Hopkins Applied Physics Lab.
       RES 18 Sep, 1989 --- converted to SUN
       R. Sterner, 30 Apr, 1993 --- cleaned up and allowed arrays.

 Copyright (C) 1986, Johns Hopkins University/Applied Physics Laboratory
 This software may be used, copied, or redistributed as long as it is not
 sold and this copyright notice is reproduced on each copy made.  This
 routine is provided as is without any express or implied warranties
 whatsoever.  Other limitations apply as described in the file disclaimer.txt.

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/jd2ymd.pro)


JUL2DAY

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       JUL2DAY

 PURPOSE:
       Convert the inputted Julian day of year to year, month, day.

 CALLING SEQUENCE:
       jul2day,julday,year,mon,day

 INPUTS:
         julday      Julian day, ranges from 1-365(366)
         year

 KEYWORD INPUTS:

 OPTIONAL INPUTS:

 OUTPUTS:
         mon         ranges from 1-12
         day         ranges from 1-31

 OPTIONAL OUTPUTS:
         outyear     output year; if different from input year (when julday
                     > 365/366 or < 1)

 EXAMPLE:

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES
         The input variable julday can be zero or negative.  Zero indicates
         the last day of the previous year (12/31), -1 indicates 12/30,
         and so on.

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  10/25/92

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/jul2day.pro)


KERNEL

[Previous Routine] [Next Routine] [List of Routines]
 routine:     kernel
 useage:      kernel(ksize,angle)

 purpose:     create a digital filter to detect image streaks
              oriented at angle ANGLE.  The IDL procedure CONVOL 
              can be used to do the convolutions.
              
 input:
   ksize      frame size of kernel. 
   angle      select for streaks at angle ANGLE 

 EXAMPLE:

 print,kernel(3,0)

  0 0 0
  1 1 1
  0 0 0

 print,kernel(5,45)

 0 0 0 0 1
 0 0 0 1 0
 0 0 1 0 0
 0 1 0 0 0
 1 0 0 0 0

  author:  Paul Ricchiazzi                            oct93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/kernel.pro)


LANGLEY

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  longley

 PURPOSE:  find TOA direct beam flux and atmospheric optical depth using
           the Langley procedure. Additionally, produce Langley scatter
           plot of direct beam flux vs airmass and show fit.

 USEAGE:   langley,sza,flx,flx0,tau,sigma,minmass=minmass,maxmass,
                   view=view,psym=psym,color=color,$
                   overplot=overplot,am=am,pm=pm,hw=hw

 INPUT:    

  sza      solar zenith angle array

  flx      direct normal flux (direct beam irradiance divided by cos(sza))
  
 KEYWORD INPUT:

  am       if set morning hours are used in Langley regression
  pm       if set afternoon hours are used Langley regression

           NOTE: it is assumed that data is organized in
           chronological order so that morning hours are those with
           decreasing sza and afternoon hours are those with
           increasing sza

  minmass  minimum air mass limit.  points with air mass less then 
           MINMASS are not used in regression. (default=2)

  maxmass  maximum air mass limit.  points with air mass greater then 
           MAXMASS are not used in regression. (default=6)
           Default limits are as suggested by Harrison and Michalsky (1994)

  clrfilt  if set values alog(flx)-smooth(alog(flx),n) gt CLRFILT are 
           removed from the regression computation

  view     display scatter plot and fitted regression line

  psym     symbol used for scatter plot

  color    color used for regression line 

  overplot if set, overplot results on existing plot frame

  hw       if set use histogram weighting in regression computation.
           This causes the regression to weigh all increments of air
           mass equally.  Fractional values of HW (between 0 and 1)
           causes the weighting factor to be raised to the HW
           power. In some cases histogram weighting can improve the
           accuracy of retrievals.

 OUTPUT:

  flx0     intensity at zero airmass

  tau      optical depth 

  sigma    standard deviation of log (flx) from fitted line.  This is
           an estimate of the fractional error.  For example sigma=.01
           means the linear regression fits the data to within about 1%.
           see example.

 DISCUSSION:
  use langley procedure to fit direct normal flux by an equation of form

          ln(I(m)) = ln(I(0)) - tau * m
 
  where I(m) is the direct normal flux at airmass m and tau is the 
  optical depth.  Assumes direct beam transmission obeys Beers law.


 EXAMPLE:  

    nn=200 &  doy=281 & lat=35. & lon=0. & time=findrng(7,17,nn)
    zensun,doy,time,lat,lon,sza,az
    szamx=80. & sza=sza(where(sza lt szamx)) & az=az(where(sza lt szamx))
    flx=(100.+randomn(iseed,nn))*exp(-.1*airmass(sza))

    w8x11 & !p.multi=[0,1,3] & set_charsize,1.5
    langley,sza,flx,flx0,tau,sigma,/view,title='Morning, hw=1',/hw,am=az
    langley,sza,flx,flx0,tau,sigma,/view,title='Morning',am=az
    langley,sza,flx,flx0,tau,sigma,/view,title='Afternoon',pm=az
    

 AUTHOR:   Paul Ricchiazzi                        09 Jan 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/langley.pro)


LATLON

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	LATLON

 PURPOSE:
	If the current window has map coordinates (i.e., MAP_SET has been used
	to set up a map projection), LATLON tracks the longitude and latitude 
	of the mouse location and displays them in a separate window. 

	To activate tracking, click on the left mouse button while the cursor 
	is in the plotting window. To stop, position the cursor in the 
	plotting  window and press the right button.

 CATEGORY:
	Mapping.

 CALLING SEQUENCE:
	LATLON 

 INPUTS:
	None.

 KEYWORD PARAMETERS:
	None.

 OUTPUTS:
	Latitude and longitude values are printed in a new window.

 COMMON BLOCKS:
	None.

 SIDE EFFECTS:
	A new window is created.

 RESTRICTIONS:
	The window must have map coordinates.

 EXAMPLE:
	Set up a Mercator map projection by entering the following command:
		MAP_SET, /MERCATOR, /GRID, /CONTINENT

	Invoke LATLON by entering:
		LATLON

	A new window labeled "Latitude/Longitude" should appear.  Put the mouse
	cursor in the map window and press the left mouse button to begin
	tracking the position of the cursor.  Press the right mouse button 
	over the map to end LATLON.

 MODIFICATION HISTORY:
	Written by Ann Bateson, June 1990

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/latlonrdpix.pro)


LCT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  lct

 PURPOSE:  try all predefined color tables

 USEAGE:   lct,index

 INPUT:    
   index   if set index specifies the first color table to try

 OUTPUT:
   index   final color table index

 DISCUSSION:
   With each click of the left mouse button a new color table is loaded.
   The MMB scans up the list of color tables and LMB scans down the list.
   The RMB exits the procedure.

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
   Loads new color tables
  
 EXAMPLE:  
   
   tvim,replicate(1,2) # indgen(!p.color),/scale,range=[0,!p.color],/asp & lct

 AUTHOR:   Paul Ricchiazzi                        30 Aug 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/lct.pro)


LEGEND

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE: legend

 PURPOSE: draws a plot legend 

 USEAGE:  legend,labels,pos=pos,linestyle=linestyle,psym=psym,clrbox=clrbox,$
                 color=color,thick=thick,fg_color=fg_color,bg_color=bg_color,$
                 box=box,numsym=numsym,ystretch=ystretch,silent=silent,$
                 center=center,fill=fill,right=right,norm=norm,spos=spos,$
                 charsize=charsize
               
 INPUT:

 labels	
     an array of labels (required). Elements of LABELS which do not
     begin with the characters ".l",".f",".c", or ".r" are treated as
     legend labels.  These elements are drawn to the right of a line
     or symbol of given LINESTYLE, PSYM, COLOR or THICK type. The
     total number of labels in LABELS (i.e., not counting legend
     titles) should correspond to the number of elements in those
     input parameters.
     
     If any of the label strings start with the characters
     ".l",".f",".c", or ".r" that element of the LABELS array is
     treated as a legend title.  Legend titles appear as left
     justified (".l"), filled (".f") centered (".c") or right
     justified (".r") strings in the legend box and do not correspond
     to elements of LINESTYLE, PSYM, COLOR or THICK.  Null strings
     ("") or blank strings (" ") are also treated as legend
     titles. Lines or symbols are not drawn to the right of legend
     titles.
     
     If none of the keywords, LINESTYPE, PSYM, COLOR or THICK are
     set, then all elements of LABELS will be treated as legend
     titles and will be left justified unless prepended by ".f", ".c"
     or ".r".  or unless one of the keywords keywords "center",
     "fill" "right" are set.  These keywords set the default, string
     justification but may always be overridden by one of the
     justification flags.
     
     Consider,
     
            labels=['.ctitle','1','2','.lsecond title,'a','b']
            linestyle= [1,2,3,4]
     
     In this example LABELS contains 4 legend labels and 2 legend
     titles. The correspondence with the linestyle input parameter is
     as follows:
     
                      labels(1) <==> linestyle(0)
                      labels(2) <==> linestyle(1)
                      labels(4) <==> linestyle(2)
                      labels(5) <==> linestyle(3)
     
     To simplify input, LABELS may also be specified as a single
     string with the different LABEL elements separated by
     backslashes (\) (E.g., labels='.cCloud height\\1\2\3\4\5'

 KEYWORD INPUT:

 pos
     position and size of legend area in normalized data 
     coordinates.  Format of this four element vector is
     [x0,y0,x1,y1] where x0,y0 is the position of lower
     left corner and x1,y1 is the position of the upper
     right corner.  For example pos=[.5,.5,.9,.9] specifies
     a legend in the upper right quadrant of the data 
     window.  If the POS parameter is not set or if POS is
     set to zero, then the CURBOX procedure is called to
     set the legend position interactively.  
     
     NOTE: the value of POS can be retrieved by setting POS
     to a named variable which has an initial value of zero.

 linestyle   
     an array of linestyle types, one for each label in LABELS

 psym	
     an array of symbol types, one for each label in LABELS. 
     PSYM can be either a integer or string array.  If PSYM is a
     string array then the library routine USERSYMBOL is used to
     create the symbols.  In this case if the symbol specifier is
     appended with '_f' then a filled symbol will be generated

 clrbox
     if set, a color-filled box appears to the left of each legend
     label.  The number of boxes drawn can be changed with NUMSYM.
     If clrbox is set to 2, a color-filled circle appears to the left
     of each legend label.

 color       
     an array of color indices, one for each label in LABELS.
     Any elements of COLOR set to -1 causes the default color,
     !P.COLOR, to be used.

 thick       
     an array of line thicknesses, one for each label in LABELS
     (default=!p.thick)

 numsym      
     number of symbol nodes used to indicate linestyle or symbol
     type.  The length of the line is measured in units of LENFAC
     character widths so that the length of the line
     = LENFAC*(NUMSYM-1) * X_CHARSIZE
     (default=2 when linestyle, color or thick set, otherwise default=1)

 lenfac
     factor which controls length of line between symbols (see numsym)
     (default=5)

 fg_color    
     color of box and legend titles (default=!P.COLOR)

 bg_color    
     background color. Setting BG_COLOR erases the area covered by
     the legend (filling it with color BG_COLOR) prior to writing the
     legend.  If both BG_COLOR and !p.color are zero then the
     background color is reset to 255 to gaurantee a readability.
               
 box         
     if set draw a box around the legend text

 silent      
     if not set, print box position string to the terminal
     and show popup help on the CURBOX cursor routine
     
     silent=1 don't print position string
     
     silent=2 don't print position string, don't show help widget

 center
     if set, default action is to center legend labels

 fill
    if set, default action is to fill legend labels

 right
    if set, default action is to right justify labels

 norm
    if set, normalized coordinates are used to specify POS both
    on input and printed output.  This option allows placement
    of the legend outside of a plot region. 

 ystretch    
     factor by which to increase vertical spacing of legend 
     entries. This parameter is particularly useful when used
     with the SPOS keyword.  (default = 1)  
     
     NOTE: the aspect ratio of the legend box can be
     modified on the fly by pushing the cursor box against
     one of the window boundaries and pressing the middle
     button.  

 spos
    string value which specifies legend position to one of a set of
    standard positions.  if spos is set, it supercedes the value of pos

                'bl' = bottom left
                'br' = bottom right
                'tl' = top left
                'tr' = top right
                'top'= top center
                'bot'= bottom center

 charsize
    character size used when legend position specified with SPOS.  
    CHARSIZE has no effect when POS is used to set position.

 OUTPUT:       none

 PROCEDURE:
    When called without the POS keyword, the legend position and size
    is set with the CURBOX routine.  The legend is positioned by
    dragging the box where you want the legend to appear.  The size
    of the legend area can be decreased/increased by the left/middle
    mouse buttons.  When the right mouse button is pressed the legend
    is drawn and a numerical positioning string giving the current
    value of the POS keyword is written to the terminal (nothing
    printed if SILENT is set).  You can run LEGEND in batch mode by
    pasting this value of POS into the LEGEND command line.  The best
    way to get good-looking legends on your hardcopies is to size
    your graphics window to the approximate shape of the output
    media.  For example a plot which is to be printed in landscape
    mode should be previewed on a window which is approximately 1.4
    times as wide as it is tall.

    NOTE:    The values returned for the POS keyword are based on a
    computation of the length of the text strings in your legend.  If
    you change the contents of the legend titles or if you change the
    default text font, you must rerun LEGEND in interactive mode to
    determine new values for the POS paramter.
                     


; EXAMPLE       interactive mode (put the box anywhere you want and press
;               the right mouse button)

   dcolors
   plot,6*randf(20,3),/nodata 
   for i=1,6 do oplot,i*randf(20,3),li=i-1,color=i
   lb='.cFirst bunch\\First\Second\Third\\.cSecond bunch\\forth\fifth\sixth'
   legend,lb,li=[0,1,2,3,4,5],/box,bg=0,color=[1,2,3,4,5,6]

; EXAMPLE       interactive mode. retrieve the value of POS for later calls:

   !p.multi=[0,1,2]
   plot,[0,.4],yrange=[0,1],li=0 & oplot,[0,.6],li=2 & oplot,[0,.9],li=3
   legpos=0
   lb=['.cLegend Demo','','one','two','three']
   legend,lb,pos=legpos,li=[0,2,3]
   plot,[0,.4],yrange=[0,1],li=0 & oplot,[0,.6],li=2 & oplot,[0,.9],li=3
   legend,lb,pos=legpos,li=[0,2,3]
   !p.multi=0


; EXAMPLE       use fill mode to print a figure caption

  w11x8
  !p.multi=[0,1,2]
  plot,dist(20)
  t=$
   'When called without the POS keyword, the legend position and size is\'+$
   'set with the CURBOX routine.  The legend is positioned by dragging the\'+$
   'box where you want the legend to appear.  The size of the legend area\'+$
   'can be decreased/increased by the left/middle mouse buttons.  When the\'+$
   'right mouse button is pressed the legend is drawn and a numerical\'+$
   'positioning string giving the current value of the POS keyword is\'+$
   'written to the terminal (nothing printed if SILENT is set).'

   legend,t,bg=0,pos=[0.00,-0.52,0.47,-0.18]         ; default left justified
   legend,t,bg=0,/right,pos=[0.53,-0.52,1.00,-0.18]  ; right justified
   legend,t,bg=0,/center,pos=[0.27,-1.00,0.74,-0.66] ; centered

; NOTE: procedure PFILL provides more elaborate text formatting capability
   
; EXAMPLE       batch mode:

   plot,[-50,50],[0,1.5],/nodata & x=findgen(101)-50.
   li=indgen(6) & pos=[0.66,0.54,0.91,0.89] 
   for i=0,5 do oplot,x,1./(1.+(x/(i+2))^2),li=li(i) 
   labels='.cPlot Key\\First\Second\Third\Fourth\Fifth\Sixth'
   legend,' ',bg=80,pos=pos+.02,/box
   legend,labels,li=li,pos=pos,bg=40,/box
                
; EXAMPLE       batch mode with symbols generated by USERSYMBOL:

   plot,[-50,50],[0,1.5],/nodata & x=findgen(101)-50.
   psym=['TRIANGLE','DIAMOND','PENTAGON','CIRCLE','SQUARE','SPADE']
   pos=[0.66,0.54,0.91,0.89] 
   for i=0,5 do begin &$
     usersymbol,psym(i) &$
     oplot,x,1./(1.+(x/(i+2))^2),psym=8,symsize=2 &$
   endfor
   labels='.cPlot Key\\First\Second\Third\Fourth\Fifth\Sixth'
   legend,' ',bg=4,pos=pos+.02,/box
   legend,labels,psym=psym,pos=pos,bg=10,/box
                

  author:  Paul Ricchiazzi                            4dec92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

 REVISIONS
 15dec92: added legend titles, and CHARSIZE parameter
 11jan93: added numsym parameter
 20jan93: added thick parameter
  2feb93: fixed positioning bug  legend titles
 25mar93: removed the NOBOX option, now you set BOX to get a box
 29mar93: added the bg_color option to blank out legend area before writing
  8apr93: use CURBOX for cursor control and LENSTR for exact string size
 27apr93: improved alignment symbol and label (ylab=yy-.3*charsize*cnvrty)
  9jun93: center legend labels when legend titles are longer (see dxcen)
 17jun93: added ystretch option to increase vertical spacing
 17jun93: default line thickness read from !p.thick
 30sep93: .l implied when LINESTYLE, PSYM, COLOR, THICK  not set. see NOLINES
 28Jun94: LABELS is now normal input param, not a keyword.
 28Jun94: legend "titles" don't correspond to LINESTYLE, PSYM, COLOR, THICK
          vector elements; no need to put in dummy values. see examples
 18Aug94: added USYM option
 28Jun95: added the .f format option
  8Sep95: added CLRBOX option
  5oct95: added charsize adjustment for Y axis
   sep96: added spos keyword, numsym default = 1 unless linestyle or color set
   nov96: CLRBOX=2 yields filled circles instead of boxes

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/legend.pro)


LEGENDRE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  legendre

 PURPOSE:  compute legendre polynomial

 USEAGE:   result=legendre(n,x)

 INPUT:    
  n        order of polynomial
  x        argument of polynomial


 DISCUSSION:
           use recursion relation to compute legendre polynomial
           for orders greater than 2:

           n*P(n,x)=(2n-1)*x*P(n-1,x)-(n-1)*P(n-2,x)

           P(0,x)=1.  P(1,x)=x

  
 EXAMPLE:  

    x=findrng(-1,1,10000)
    f=legendre(20,x)
    plot,x,f

; find zeroes of legendre polynomial

    r=roots(f,0.) & xxx=interpolate(x,r) & fff=interpolate(f,r)
    oplot,xxx,fff,psym=2
    print,xxx

; print zeroes of rescaled legendre polynomial n=10,20,2

    for n=10,20,2 do begin & f=legendre(n,x) & r=roots(f,0.) & print,n,min(abs(cos(!dtor*39.)-(interpolate(x,r)+1.)/2.)) & endfor

 AUTHOR:   Paul Ricchiazzi                        06 Apr 98
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/legendre.pro)


LENSTR

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:         lenstr
 USEAGE:          result=lenstr(str)

 input:
  str             a single string or string array.
 
 output:
  result          length of the string(s) in normalized units
                  the number of elements of RESULT matches the number of 
                  elements of STRING. 

 procedure:
                  This function returns the physical length of the
                  string on the output device, not the number of
                  characters.  This is done by first switching to 'X'
                  and writing the string(s) with XYOUTS in graphics
                  mode 5, which disables display to the screen but
                  does not interfere with operation of XYOUTS.  The
                  WIDTH keyword parameter of XYOUTS is used to
                  retrieve the physical length of the string(s).

  author:  Paul Ricchiazzi                            7apr93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/lenstr.pro)


LESS

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    less

 PURPOSE:    print interactively selected portions of arrays or vectors

 USEAGE:     less,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,index=index

             

 INPUT:      
  p1,p2,...  a set of vector quantities to print. all vectors must
             be of the same length



 KEYWORD INPUT:

   index     if set, the array indicies of the first parameter, p1,
             are printed.  This only has effect when p1 has dimension
             greater than two.  Indicies for array dimensions greater
             than 5 are not printed. This option disables the 2-D display
             mode.
             

 DISCUSSION:
             When the size of the array is greater than can be viewed
             in one display screen, LESS enters an interactive mode
             which allows the user to page through the array(s). Many
             of the movement commands are similar to the unix command
             "less".  While in the interactive display mode type "h"
             to get a listing of accepted interactive commands.

             If only one input parameter is specified, LESS will
             display it as 2-D table with the values of the first
             index shown across the screen and the values of the
             second index shown down the screen.  The number of rows
             and columns are chosen to fit the screen.  Up to 5
             dimensions can be accomodated.  Movement in the 3rd,4th,
             and 5th is accomplished by entering index values while
             in display mode.

 EXAMPLE:

    x=sqrt(findgen(20)+23)
    y=sin(.1*x)

    less,x,y                                            ; 
    less,x,y,x+y,x-y,x*y,(x+y)*(x-y),x/y
    less,rebin(x,4,5),y,/index

    less,dist(20,500)

  author:  Paul Ricchiazzi                            may94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/less.pro)


LOCATE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:     locate
 
 USEAGE:      locate,lat,lon,alat,alon,x,y

 PURPOSE:     
    This routine is used by COASTLINE to find the array indices 
    of a given geographical point within irregular latitude and
    longitude arrays.  Given the coordinate arrays alat(i,j) and
    alon(i,j), LOCATE finds the "floating point" indices x,y such
    that,

            interpolate(alat,x,y)=lat 
            interpolate(alon,x,y)=lon 

    Stated more abstractly, LOCATE solves two simultaneous non-linear
    equations of the form
    
            f(x,y)=u
            g(x,y)=v
    
    where the functions f and g are actually arrays of values
    indexed by x and y.
              
 INPUT:
    lat       a vector of geographic latitudes 
    lon       a vector of geographic longitudes
    alat      array of image latitudes 
    alon      array of image longitudes
 OUTPUT:
    x,y       "floating point" array indicies such that 

                  lat=interpolate(alat,x,y)

                  lon=interpolate(alon,x,y)

 EXAMPLE:

 c=(cmplxgen(100,100)+complex(20,20))/50 & c=c+c^2+c^3
 alon=imaginary(c) & alat=float(c)
 !p.multi=[0,1,2]
 xo=fix(54+(20+25*(findgen(21) mod 2))*cos(2*!pi*findgen(21)/20))
 yo=fix(54+(20+25*(findgen(21) mod 2))*sin(2*!pi*findgen(21)/20))
 lon=alon(xo,yo)       & lat=alat(xo,yo)
 plot,alon,alat,/noda,ytit='latitude',xtit='longitude',/xstyle,/ystyle
 oplot,alon,alat,psym=3
 oplot,lon,lat,psym=-4
 delvar,x,y
 locate,lat,lon,alat,alon,x,y
 contour,alat,levels=contlev(alat,maxlev=30),/follow,c_color=150
 contour,alon,levels=contlev(alon,maxlev=30),/follow,/over,c_color=80
 oplot,x,y,psym=-4
 table,lat,interpolate(alat,x,y),lon,interpolate(alon,x,y),x,xo,y,yo


 DISCUSSION:
    LOCATE uses Newton-Raphson iteration of the linearized equations
    for latitude and longitude.  The equation is itereated repeatedly
    only for those elements of the input vectors which have not
    satisfied the convergence criterion, 

             (lat-alati)^2+(lon-aloni)^2 lt (.001)^2

    where alati and aloni are the values of ALAT and ALON interpolated
    to the current estimates of X and Y.  This procedure will probably
    fail if the gradients of ALAT and ALON arrays do not form linearly
    independent vector fields.  You have trouble if somewhere in
    the grid grad(ALAT) is proportional to grad(alon)

 AUTHOR:      Paul Ricchiazzi             oct92 
              Earth Space Research Group, UCSB
 

 REVISIONS:
 27oct92   Provide default initial guesses for x and y. This allows the
           user to call LOCATE without pre-defining x and y.
 12jun95   allow LOCATE to accept a vectors of LAT-LON points, improves speed
           
           

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/locate.pro)


LOOPIND

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  loopind

 PURPOSE:  evaluate a sequence of nested indicies

 USEAGE:   loopind,ii,n1,i1,n2,i2,n3,i3,n4,i4,n5,i5,n6,i6

 INPUT:    
   n1      number of elements in first dimension
   n2      number of elements in second dimension

   etc

 keyword input:
   ind     one dimensional index.  If this keyword is set, evaluate
           i1,i2... only for the elements contained in IND
 OUTPUT:
   i1      index for first dimension
   i2      index for second dimension
   etc
  
 EXAMPLE:  

  loopind,4,i1,5,i2,2,i3
  f=randomn(iseed,4,5,2)
  table,i1,i2,i3,f

 AUTHOR:   Paul Ricchiazzi                        22 Sep 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/loopind.pro)


LS

[Previous Routine] [Next Routine] [List of Routines]
 routine    ls
 useage:    ls
            ls,filt
 input:
   filt     a valid unix filename specification or wild card (not required)

 purpose    print files in current working directory
  author:  Paul Ricchiazzi                            jan93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/ls.pro)


MAP_CITIES

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  map_cities

 PURPOSE:  plot city locations and print city names form cities.dat database

 USEAGE:   map_cities

 INPUT:    none

 KEYWORD INPUT:
   file    
     city data base file, each record contains tab delimited values
     of latitude, longitude and city_name.
;
   charsize
     character size (a multiplier of !p.charsize)

   color
     color used to draw city mark and name

 OUTPUT: none

 DISCUSSION:

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  
;
   dcolors
   map_set3,0,-94.8814,/cyl,/cont,limit=[16.75,-130.05,56.95,-59.71],$
            /usa,s_color=4
   
   map_cities,color=1

 AUTHOR:   Paul Ricchiazzi                        25 Apr 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/map_cities.pro)


MAP_LAMBERT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    map_lambert

 PURPOSE:    transformation into lambert azimuthal map projection

 USEAGE:     map_lambert,lat0,lon0,lat,lon,u,v

 INPUT:
   lat0      latitude of tangent point
   lon0      longitude of tangent point
   lat       array of latitudes
   lon       array of longitues

 OUTPUT:
   u         horizontal projection coordinates (km)
   v         vertical projection coordinates (km)

 EXAMPLE:    
             lat=[ 23.5837576, 22.4793919, 46.7048989, 48.4030555]
             lon=[ -119.9722899, -75.4163527, -65.3946489, -128.5300591]
             map_lambert,45,-100,lat,lon,u,v
             print,u,v

 REVISIONS:

  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/map_lambert.pro)


MEAN

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:                mean

 AUTHOR:                 Terry Figel, ESRG, UCSB 2-21-93

 CALLING SEQUENCE:        mean,var

 INPUT:   
              var         an array

 PURPOSE:                 return the mean of var

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/mean.pro)


MENUW

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    menuw 

 PURPOSE:    create a menu widget and return a selection

 USEAGE:     w=menuw(choices,title=title,group=group,$
                     font=font,ysize=ysize,done=done)

             result=menuw(w) 

             while menus(w,ii) do (something that depends on ii)

 PROCEDURE:
             The value returned from MENUW is either a widget id or a
             selection index, depending on the variable type of its
             first argument.  If the argument is a string array then
             MENUW sets up a menu, based on an IDL list widget, and
             returns a structure of widget identifiers of the
             component widgets.  If the argument is a structure then
             MENUW returns the index of the selected menu choice.

             Set up the widget with          w=MENUW(choices)
             Return choices with             result=MENUW(w)
             where 
                choices = a string array of menu choices 
                w       = a structure variable containing the widget id.
                result  = index of the selected menu choice 

 INPUT:
  choices    string array containing choices
  w          widget id (returned by setup call to MENUW)
  

 KEYWORD INPUT:
  title      title of the widget

  prompt     string array of prompt message. each element of string
             array appears on a new line.

  ysize      the number of lines to show in the list widget.  If the
             number of choices is greater than ysize the list widget
             creates a vertical slider to allow the user to scan all
             selections.

  font       String specifying font type. If omitted use the default
             fixed width font:
             "-misc-fixed-bold-r-normal--13-120-75-75-c-80-iso8859-1"

  done       if set, a "DONE" button is created.  If a "DONE" button
             is not present the MENUW widget is destroyed the first
             time result=MENUW(w) is executed.

 OUTPUT, SETUP MODE:

  w          widget indentifier used in subsequent calls to MENUW
             When multiple copies of the MENUW widget exist, a call to
             to MENUW(w) will interact only with the widget which
             set W.

 OUTPUT, SELECTION MODE:

  selection  If selection parameter is included in parameter list it
             will contain the index of the selection and the function
             return value will be set to -1 or 1 depending on whether
             the DONE button was/was_not pressed.  When used in a
             while loop (see examples), the last selected value is
             available even after DONE is pressed.  If the SELECTION
             parameter is not in the argument list the function
             return value will be set to....

  result     if the DONE button is pressed =>  -1
             otherwise the index of the list widget 
             (0 -- n_elements(choices)-1)


 EXAMPLES:

; use MENUW in one-shot mode

       items=findfile('/local/idl/user_contrib/esrg/t*.pro')
       prompt='choose a file to display'
       print,items(menuw(menuw(items,prompt=prompt)))


; use MENUW to make a sequence of menu selections

       items=findfile('/local/idl/user_contrib/esrg/t*.pro')
       prompt='choose a file to display'
       w2=menuw(items,prompt=prompt,/done)
       k=menuw(w2) 
       while k ne -1 do begin & print,items(k) & k=menuw(w2) & end

       while menuw(w2,k) do print,items(k)
       print,items(k)


  author:  Paul Ricchiazzi                            may94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/menuw.pro)


MENUWS

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    menuws

 PURPOSE:    create a multiple value menu widget and return a selections

 USEAGE:     w=menuws(choices,title=title,group=group,$
                     font=font,ysize=ysize)

 INPUT:
  choices    string array containing choices

 KEYWORD INPUT:
  title      title of the widget

  prompt     string array of prompt message. each element of string
             array appears on a new line.

  ysize      the number of lines to show in the list widget.  If the
             number of choices is greater than ysize the list widget
             creates a vertical slider to allow the user to scan all
             selections.  

  font       String specifying font type. If omitted use the default
             fixed width font:
             "-misc-fixed-bold-r-normal--13-120-75-75-c-80-iso8859-1"


 OUTPUT

  result     the indecies of the selected items.  (-1 if no selections)

 EXAMPLES:


; use MENUWS to make a sequence of menu selections

       f=findfile('/home/paul/idl/esrg/[r-z]*.pro')
       table,f(menuws(f))

 DISCUSSION:
       MENUWS calls MENUW to do the widget setup and selection of
       individual items.  MENUWS keeps track of which items have been
       selected and updates the item labels to graphically indicate
       active selections. When the operator makes a selection by
       clicking with the LMB, the entire selection list is rewritten to
       the menu widget.  Selected items are indicated with an
       asterisk (*) prefix.  Selected items may be de-selected by
       clicking on them again with the LMB.  The list of selected
       items is not locked in until the operator hits the DONE button.

 BUGS:
       Because MENUWS uses WIDGET_CONTROL to update the item list
       there is a problem which only occurs when the the list is long
       and you are selecting something near the bottom of the
       scrolled list.  In this case, when WIDGET_CONTROL re-writes
       the item list the widget display jumps up to the top of the
       list.  This is disturbing but not disasterous: the selection
       is recorded even though you have to scroll back down to see
       it. The only fix I know is to make sure YSIZE is greater than
       or equal to the number of menu items.  Right now YSIZE is 
       defaulted to the min of the number of menu items and 60, which
       is as many items as will fit on my screen when using the
       default font.

  author:  Paul Ricchiazzi                            may94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/menuws.pro)


MIN_CURVE_SURF

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	MIN_CURVE_SURF

 PURPOSE:
	Interpolate a regular or irregularly gridded set of points
	with a minimum curvature spline surface.
 CATEGORY:
	Interpolation, Surface Fitting
 CALLING SEQUENCE:
	Result = min_curve_surf(z [, x, y])
 INPUTS:
	X, Y, Z = arrays containing the x, y, and z locations of the
		data points on the surface.  Need not necessarily be
		regularly gridded.  For regularly gridded input data,
		X and Y are not used, the grid spacing is specified
		via the XGRID or XVALUES, and YGRID or YVALUES,
		keywords, and Z must be a two dimensional array.
		For irregular grids, all three parameters must be present
		and have the same number of elements.
 KEYWORD PARAMETERS:
  Input grid description:
	REGULAR = if set, the Z parameter is a two dimensional array,
		of dimensions (N,M), containing measurements over a
		regular grid.  If any of XGRID, YGRID, XVALUES, YVALUES
		are specified, REGULAR is implied.  REGULAR is also
		implied if there is only one parameter, Z.  If REGULAR is
		set, and no grid (_VALUE or _GRID) specifications are present,
		the respective grid is set to (0, 1, 2, ...).
	XGRID = contains a two element array, [xstart, xspacing],
		defining the input grid in the X direction.  Do not specify
		both XGRID and XVALUES.
	XVALUES = if present, Xvalues(i) contains the X location
		of Z(i,j).  Xvalues must be dimensioned with N elements.
	YGRID, YVALUES = same meaning as XGRID, XVALUES except for the
		Y locations of the input points.
  Output grid description:

	GS =  spacing of output grid.
		If present, GS a two-element vector 
	        [XS, YS], where XS is the horizontal spacing between 
        	grid points and YS is the vertical spacing. The 
        	default is based on the extents of X and Y. If the 
        	grid starts at X value Xmin and ends at Xmax, then the 
        	default horizontal spacing is  (Xmax - Xmin)/(NX-1).
	        YS is computed in the same way. The default grid
		size, if neither NX or NY are specified, is 26 by 26.
	BOUNDS = a four element array containing the grid limits in X and
		Y of the output grid:  [ Xmin, Ymin, Xmax, Ymax].
		If not specified, the grid limits are set to the extend
		of X and Y.
	NX = Output grid size in the X direction.  Default = 26, need
		not be specified if the size can be inferred by
		GS and BOUNDS.
	NY = Output grid size in the Y direction.  See NX.
	XOUT = a vector containing the output grid X values.  If this
		parameter is supplied, GS, BOUNDS, and NX are ignored
		for the X output grid.  Use this parameter to specify
		irregular spaced output grids.
	YOUT = a vector containing the output grid in the Y direction.
		If this	parameter is supplied, GS, BOUNDS, and NY are 
		ignored	for the Y output grid.
	XPOUT, YPOUT = arrays containing X and Y values for the output
		points.  With these keywords, the output grid need not
		be regular, and all other output grid parameters are
		ignored.  XPOUT and YPOUT must have the same number of
		points, which is also the number of points returned in
		the result.
 OUTPUTS:
	A two dimensional floating point array containing the interpolated
	surface, sampled at the grid points.
 COMMON BLOCKS:
	None.
 SIDE EFFECTS:
	None.
 RESTRICTIONS:
	Limited by the single precision floating point accuracy of the
	machine.
		SAMPLE EXECUTION TIMES  (measured on a Sun IPX)
	# of input points	# of output points	Seconds
	16			676			0.19
	32			676			0.42
	64			676			1.27
	128			676			4.84
	256			676			24.6
	64			256			1.12
	64			1024			1.50
	64			4096			1.97
	64			16384			3.32

 PROCEDURE:
	A minimum curvature spline surface is fitted to the data points
	described by X,Y, and Z.  The basis function:
		C(x0,x1, y0,y1) = d^2 log(d),
	where d is the distance between (x0,y0), (x1,y1), is used,
	as described by Franke, R., Smooth interpolation of scattered
	data by local thin plate splines: Computers Math With Applic.,
	v.8, no. 4, p. 273-281, 1982.  For N data points, a system of N+3 
	simultaneous equations are solved for the coefficients of the 
	surface.  For any interpolation point, the interpolated value
	is:
	  F(x,y) = b(0) + b(1)*x + b(2)*y + Sum(a(i)*C(X(i),x,Y(i),y))

 EXAMPLE:  IRREGULARLY GRIDDED CASES
	Make a random set of points that lie on a gaussian:
	n = 15		;# random points
	x = RANDOMU(seed, n)
	y = RANDOMU(seed, n)
	z = exp(-2 * ((x-.5)^2 + (y-.5)^2))  ;The gaussian

 get a 26 by 26 grid over the rectangle bounding x and y:
	r = min_curve_surf(z, x, y)	;Get the surface.
 Or: get a surface over the unit square, with spacing of 0.05:
	r = min_curve_surf(z, x, y, GS=[0.05, 0.05], BOUNDS=[0,0,1,1])
 Or: get a 10 by 10 surface over the rectangle bounding x and y:
	r = min_curve_surf(z, x, y, NX=10, NY=10)

		REGULARLY GRIDDED CASES
	z = randomu(seed, 5, 6)		;Make some random data
		interpolate to a 26 x 26 grid:
	CONTOUR, min_curve_surf(z, /REGULAR)

 MODIFICATION HISTORY:
	DMS, RSI, March, 1993.  Written.
	DMS, RSI, July, 1993.   Added XOUT and YOUT.

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/min_curve_surf.pro)


MODCT

[Previous Routine] [Next Routine] [List of Routines]
 name:
	modct

 purpose:
	modify the image display color tables so the full range 
	runs from one color index to another.

 category:
	image processing, point operations.

 calling sequence:
	modct, ct, low=low, high=high, gamma=gamma, ct=ct,bar=bar

 input:
      ct       color table index.  if not supplied current color table
               is modified.

 keyword inputs:
	low:	starting point of color range interpolation
               as a fraction of the current color table. 
               use keyword clrbar to see current table.
               default=0

	high:	ending point of color range interpolation as
               a fraction of current color table.
               default=1. if high

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/modct.pro)


MODE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       MODE

 PURPOSE:
       Return the mode of an array.

 CALLING SEQUENCE:
       mod = mode(x)

 INPUTS:
       array    the array of interest

 OPTIONAL INPUTS:
       binsz    if set, the size of the histogram bins.  Default = 1

 OUTPUTS:
       The value of the array where the maximum number of elements of 
       array are located given the bin size.

 PROCEDURE
       Uses histogram, stolen code from histo.pro

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     11/21/93

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/mode.pro)


MODTRNS

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    modtrns

 PURPOSE:    extract transmission from modtran tape8, display transmission
             plots

 USEAGE:     modtrns,buf,archive=archive,file=file,xrange=xrange,$
                     title=title,sort=sort

 KEYWORD INPUT:
   file      input file name (defaults to "tape8")

   archive   archive data set name, if this keyword is present and both 
             FILE and BUF are not set, input is read from specified
             modtran data set which has been previously benn saved
             in machine independent XDL format.  IF either BUF or
             FILE are set, the data in FILE or BUF are written to
             ARCHIVE.


   title     string which specifies title of transmission plot

   xrange    wavelength range (defaults to wavelength range of modtran run)

   sort      if set, plot four most opaque species in order of
             increasing band opacity.  Otherwise order is
             (total,h2o,co2,o3,o2, ch4+n2o+co+no2+so2+nh3+no)

 INPUT/OUTPUT:
   buf       modtran transmission data fltarr(12,*)

              0  wavenumber
              1  H2O
              2  O3
              3  CO2
              4  CO
              5  CH4
              6  N2O
              7  O2
              8  NH3
              9  NO
             10  NO2
             11  SO2
                  
 DISCUSSION

     if none of BUF, FILE and ARCHIVE are specified MODTRNS opens and
     reads /local/idl/user_contrib/esrg/modsaw.xdr

 EXAMPLE:

;;   read default archive file and plot 

    modtrns

;;   read tape8 and make plot

    modtrns,buf,title='Subarctic Winter Atmosphere',file='tape8'

;;   save this run in an XDR archive to expedite data retrievals for
;;   other IDL sessions.  

    modtrns,buf,archive='~/yourdirectory/modsaw.xdr'

;;  retrieve an archived run (this archive file really exists, so try it)

    delvar,buf
    modtrns,buf,archive='/local/idl/user_contrib/esrg/modsaw.xdr'

;;   Here, the ZOOMBAR command is used in a WHILE loop to zoom in on 
;;   a region of interest. Use previously retrieved value of buf to 
;;   quicken plots.  Window 0 is used to show whole wavelength range
;;   while window 2 shows the zoomed in region.

    delvar,buf
    window,2,xs=600,ys=900 & window,0,xs=600,ys=900
    modtrns,buf & xs=!x & r=0
    while zoombar(r,/mess,init=r) do begin &$
      wset,2 & modtrns,buf,xrange=r & !x=xs & wset,0 & end

 REVISIONS:

  author:  Paul Ricchiazzi                            feb95
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/modtrns.pro)


MON2STR

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       MON2STR

 PURPOSE:
       Return a string containing a month's name.

 CALLING SEQUENCE:
       mon_name = mon2str(1)

 INPUTS:
       mon      month desired. NOTE:  mon is 1-based (e.g., January = 1)

 OPTIONAL INPUTS:
       type     string defining type of string desired:
                   undefined:   full string, first letter capitalized
                                e.g., 'December'
                   'short':     abbreviated string, uncapitalized; three
                                letter abbreviations except September
                                e.g., 'dec', 'sept'
                'capshort':     abbreviated string, capitalized; three
                                letter abbreviations e.g., 'Dec', 'Sep'

 OUTPUTS:
       An string is returned.

 EXAMPLE:
      print,mon2str(12)
      December

      print,mon2str(12,'short')
      dec

      print,mon2str(9,'short')
      sept

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  12/03/93

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/mon2str.pro)


MOYENVERT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       MOYENVERT

 PURPOSE:
       Return the an array that is the "vertical" average of a stack of
       arrays.

 CATEGORY:
       Array manipulation.

 CALLING SEQUENCE:
       moyenvert, tab, moy, stdv, nb

 INPUTS:
       tab     the array to be averaged

 OPTIONAL INPUTS:
       quiet   don't print messages
       nodata  use this value when searching for nodata values

 OUTPUTS:
       moy    average of tab through third dimension
       stdv   standard deviation
       nb     number of values used in average at each pixel

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Didier Jourdan     Earth Space Research Group, UCSB  12/03/93

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/moyenvert.pro)


MPRANK

[Previous Routine] [Next Routine] [List of Routines]
 routine       mprank

 purpose       compute the nth percentile value in each of a number of a
               image superpixel subregions
 input:

   image       image array

   perc        percentile threshold ( measured from the top, 
               ie perc=7 => the pixel value which is at the 93% percentile))

   binsize     size of subregions (assumed square)

 keyword input:

   interp      if set use, interpolation is used to resize results up
               to the input image size. A boxy result is ofter produced
               when INTERP is not set.
 output:

   result=     value of pixels which are at the PERC percentilie in the
               subarea.  Values are CONGRIDed up to the size of image.

 procedure:    MPRANK looks at each subregion in the image and seperately
               evaluates the value within that subregion which is in the
               upper PERC percentile.  The result of the function are
               these values CONGRIDed up to the size of the original image.
 

 EXAMPLE:
               n=256
               xs=sqrt(findgen(n))                  
               ys=sqrt(findgen(n))                  ; xss and yss are used
               xss=xs # replicate(1,n_elements(ys)) ; to give the random
               yss=replicate(1,n_elements(xs)) # ys ; data a nice shape
               f=randata(n,n,s=4)
               !p.multi=[0,2,2]
               tvim,f,title='original data'
               tvim,mprank(f,5,32),title='no interp'
               tvim,mprank(f,5,32,/interp),title='with interp'

  author:  Paul Ricchiazzi                            Nov93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/mprank.pro)


MSTDEV

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	MSTDEV

 PURPOSE:
	Compute the standard deviation and, optionally, the
	mean of any array.

 CATEGORY:
	G1- Simple calculations on statistical data.

 CALLING SEQUENCE:
	Result = STDEV(Array [, Mean])

 INPUTS:
	Array:	The data array.  Array may be any type except string.

 OUTPUTS:
	STDEV returns the standard deviation (sample variance
	because the divisor is N-1) of Array.
		
 OPTIONAL OUTPUT PARAMETERS:
	Mean:	Upon return, this parameter contains the mean of the values
		in the data array.

 COMMON BLOCKS:
	None.

 SIDE EFFECTS:
	None.

 RESTRICTIONS:
	None.

 PROCEDURE:
	Mean = TOTAL(Array)/N_ELEMENTS(Array)
	Stdev = SQRT(TOTAL((Array-Mean)^2/(N)))

 MODIFICATION HISTORY:
	DMS, RSI, Sept. 1983.

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/mstdev.pro)


MUSLOPE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  muslope

 PURPOSE:  compute dot product of surface normal to incomming solar ray

 USEAGE:   result=muslope(sunzen,sunaz,nrmzen,nrmaz)

 INPUT:    

   sunzen  solar zenith angle (degrees)

   sunaz   solar azimuth angle (clockwise from due north, degrees) 

   nrmzen  zenith angle of surface normal vector
           (nrmzen=0 for a horizontal surface)

   nrmaz   azimuth angle of surface normal vector (nrmaz=45 degrees
           for a surface that slopes down in the north-east direction)

 OUTPUT:
   result  the dot product of the surface-to-sun unit vector
           and the surface normal unit vector. 

 EXAMPLE:  

;  find the solar zenith and azimuth for 3 pm, january 8

   zensun,8,15.,34.456,-119.813,sunzen,sunaz,/local

;  compute surface solar flux onto a surface inclined
;  5 degrees to the north-east

   print,f='(3a15/3g15.4)','solar zenith','cos(sunzen)','muslope', $
      sunzen,cos(sunzen*!dtor),muslope(sunzen,sunaz,5.,45.)

 AUTHOR:   Paul Ricchiazzi                        08 Jan 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/muslope.pro)


MVE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:                 mve

 AUTHOR:                 Terry Figel, ESRG, UCSB 10-21-92

 CALLING SEQUENCE:        mve,var

 INPUT:   
              var         an array

 PURPOSE:                 print out the max min mean and std deviation of var

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/mve.pro)


NCDF_GET_1FIELD

[Previous Routine] [Next Routine] [List of Routines]
 Get a variable and its metadata from a NetCDF file

 Written 1 April 1993 by William Weibel, UCLA Atmospheric Sciences

 Source code control Id %W%	%G%

 USEAGE:    ncdf_get_1field, file, varname, z, name

 arguments
	file		string containing the name of the NetCDF file
	varname		name of the variable to read (string)
	z		dependent field variable, any data type
       name            ?

 bugs
	only gets data, doesn't slice yet
	assumes the field is rectilinear.
	The way multiple coordinate arrays are allocated is not pretty
	  passes only up to nine dimensions

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/ncdf_get_1field.pro)


NCDF_GET_FIELD

[Previous Routine] [Next Routine] [List of Routines]
ROUTINE: NCDF_GET_FIELD
 
Get a variable and its metadata from a NetCDF file.
 
Calling Sequence
        ncdf_get_field, File, Varname, Z, Name, C0, C1, C2, ...
 
Arguments
 
        File
 
                A string containing the name of an existing NetCDF file.
 
        Varname
                A string containing the name of the variable you want to
                read, or an integer corresponding to a NetCDF variable
                identifier.  
 
        Z
                An array output by ncdf_get_field containing the dependent
                variable given in Varname.  The procedure will determine the
                data type and dimensions of the array from the information
                in the NetCDF file.
 
        Name
                An array of strings containing names for the coordinate axes,
                i.e. the names of the independent variables.
 
        C0, C1, C2, ...
                Arrays output by ncdf_get_field containing the coordinates,
                i.e. independent variables, of the field.
 
Example
 
        Suppose you have a file called stuff.cdf, and you know it contains
        a four-dimensional scalar variable called 't'.  You would read the
        data this way.
 
              IDL> ncdf_get_field, 'stuff.cdf', 't', t, titles, x, y, z, time
        
        If you examine your IDL memory contents, you find the following
 
              IDL>help,t
                T               FLOAT     = Array(60, 60, 10, 3)
 
        The data could be sliced and displayed like so
 
              IDL>sst = t(*,*,0,2)
              IDL>contour,sst,x,y,max_value=9000
 
Bugs
        only gets entire field, doesn't slice yet
        The way multiple coordinate arrays are allocated is not pretty
          passes only up to nine dimensions
        Has not been tested on irregular fields
 
Author
        William Weibel, UCLA Atmospheric Sciences
 
Last Revision Date
 
        1 April 1993  

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/ncdf_get_field.pro)


NCDF_INFO

[Previous Routine] [Next Routine] [List of Routines]

ROUTINE: NCDF_INFO
 
PURPOSE: Summarize the information from a NetCDF file
 
USEAGE:  NCDF_INFO, File
 
INPUT:
 
 file    A string containing the name of an existing NetCDF file.

KEYWORD_INPUT:

 dir     if set to one (an integer) the current directory is scanned
         for any files with a .cdf suffix.  If instead dir is set to
         a directory name (a string) then that directory is scanned
         for NetCDF files.  The list of files is presented as a menu,
         and information for a selected file is displayed.  If
         present, the command line argument, FILE, is set to the
         selected file, and can be used in subsequent commands.

 noless  0 view info file with less (default)
         1 do not view info file with less 
         2 view info file with xless

 Keyword OUTPUT:

 names   array of variable names

Example
 
; Review information for a specific netcdf file
 
    ncdf_info,'stuff.cdf'
 

; Review information for one of many files in a directory

    ncdf_info,file,/dir            ; defines file on output

; Retrieve a list of variable names and use in a menu to retrieve values

    ncdf_info,file,/dir,/no,na=n & ncdf_get_1field,file,n(wmenu(n)),z
 
Bugs:
 
    Although this algorithm follows NetCDF conventions, it is inappropriate
    for irregularly gridded data.
  
Author:
 
        William Weibel, Department of Atmospheric Sciences, UCLA
        
 
Revisions:

 may98:PJR correct do loop index range (WW forgot to start at 0)
 may98:PJR return variable names to caller
 apr98:PJR pipe info into less
 apr93:WW  Summarize the information from a NetCDF file


 Bugs:

    Although this algorithm follows NetCDF conventions, it is inappropriate
    for irregularly gridded data.

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/ncdf_info.pro)


NEWCOV

[Previous Routine] [Next Routine] [List of Routines]
##################################
 program calculates the coefficiency of var1 and var2
##################################

ro  newcov,var1, var2,cov

std1=mstdev(var1,mean1)
std2=mstdev(var2,mean2)

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/newcov.pro)


NOT_SET

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       NOT_SET

  otherwise known as 'set...NOT!' thanks to Paul Ricchiazzi

 PURPOSE:
       Return the values of array2 that are not in array1.  If array2 
       not defined, use lindgen(max(array1+1))

 CATEGORY:
       Array manipulation.

 CALLING SEQUENCE:
       array3 = not_set(array1, array2)

 INPUTS:
       array1     

 OPTIONAL INPUTS:
       array2       See PURPOSE.
       maxarr       If array2 not defined, use this length rather 
                    than max(array1+1))    

 OUTPUTS:
       See PURPOSE.

 EXAMPLE:
     x = [0,2,3,4,6,7,9]
     y = [3,6,10,12,20]

     print,intersect(x,y)
      3       6

     print,intersect(x,y,/xor_flag)
      0       2       4       7       9      10      12      20

     print,not_set(x,y)
       0       2       4       7       9     

     print,not_set(x)
           1           5           8

     print,not_set(x,maxarr=15)
           1           5           8          10          11          12
         13          14

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  12/03/93

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/not_set.pro)


N_LINES

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  n_lines

 PURPOSE:  count number of lines in a file

 USEAGE:   result=numlines(file,nw)

 INPUT:    
   file    file name

 OUTPUT:
   result  number of lines in file
   nw      number of words in file

 EXAMPLE: 

  file='/local/idl/user_contrib/esrg/n_lines.pro
  print,'number of lines   =',n_lines(file,nw) ,$
        'number of words   =',nw

 AUTHOR:   Paul Ricchiazzi                        29 Feb 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/n_lines.pro)


O2O2CONT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  o2o2cont

 PURPOSE:  plot o2*o2 continuum optical depth

 USEAGE:   o2o2cont

 INPUT:    

 KEYWORD INPUT:

 OUTPUT:

 DISCUSSION:

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  

 AUTHOR:   Paul Ricchiazzi                        27 Jul 98
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/o2o2cont.pro)


OBAND

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:   oband

 USEAGE:    oband,x,y1,y2,border=border,color=color,spacing=spacing,$
                  fill_pattern=fill_pattern,line_fill=line_fill,$
                  pattern=pattern,orientation=orientation
                  

 PURPOSE:   Over plot shaded band on an x-y plot.  Shaded region is
            between y1 and y2 as a function of x.  This is useful for
            indicating an error bounds on an x-y plot.  

 INPUTS:

 x          vector of x values (data coordinates)
 y1         vector of lower y values (data coordinates)
 y2         vector of upper y values (data coordinates)
 
            NOTE: y1 need not be smaller than y2. The shaded region
                  always extends from y1 to y2 no matter which one is
                  greater.

            NOTE: If y1 or y2 is a scalor it will be used internally
                  as if it were a constant value vector of the same
                  length as x.

 OPTIONAL KEYWORDS:

   border
        if set, draw a border around the filled region, the numerical
        value of BORDER is the color index used to draw the border
    

 Keywords recognized by the POLYFILL procedure:

   COLOR
        color index used to fill region

   LINE_FILL
        Set this keyword to indicate that polygons are 
        to be filled with parallel lines, rather than using 
        solid or patterned filling methods.When using the 
        line-drawing method of filling, the thickness, line-
        style, orientation, and spacing of the lines may be 
        specified with keywords.
        
   PATTERN
        A rectangular array of pixels giving the fill 
        pattern. If this keyword parameter is omitted, POLY-
        FILL fills the area with a solid color. The pattern 
        array may be of any size; if it is smaller than the 
        filled area the pattern array is cyclically 
        repeated.

   SPACING
        The spacing, in centimeters, between the parallel
        lines used to fill polygons.
        
   ORIENTATION
        Orientation angle of lines used to fill region.
        
Graphics Keywords Accepted

        See Chapter 2, Graphics Keywords and System Variables, 
        for the description of graphics and ploting keywords not 
        listed above. CHANNEL CLIP DATA DEVICE LINE NOCLIP NORMAL 
        T3D THICK Z.
 
 EXAMPLE:

        x=indgen(200)
        y=randf(200,3)
        y1=y+.1*(1.+randf(200,2)^2)
        y2=y-.1*(1.+randf(200,2)^2)
        plot,x,y
        oband,x,y1,y2,color=100
        oplot,x,y

        plot,x,y
        oband,x,y,0,/line_fill,orien=45,border=100


 DISCUSSION: If y1 and y2 are more than 1 element, make sure their
             array lengths are the same as x.
     

  author:  Paul Ricchiazzi                            12apr93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/oband.pro)


PAUSE

[Previous Routine] [Next Routine] [List of Routines]
 routine:        pause

 useage:         pause
                 pause,up=up,xcrs=xcrs,ycrs=ycrs,on_screen=on_screen

 input:          none

 keyword input:  
   up
     if set, don't return until a upward button transition is
     detected.  This is useful when pause is used between plots which
     draw quickly.  Setting this keyword ensures that no plots are
     skipped but also requires that each new plot be accompanied by a
     downward and upward button transition.  The default is to skip
     to the next plot as long a mouse button is pressed down.


 xcrs,ycrs
     pixel location to put cursor while waiting

 on_screen
     if set, don't pause if cursor not in plot window

 output:         none

 PURPOSE:
     Momentarily stop execution until a mouse key is pressed.  While
     in the paused state the cursor is changed to what looks like an
     arrow pointing down on a button.  When any of the mouse buttons
     are pressed the cursor returns to its original form and
     execution continues.
     
     PAUSE will only interrupt execution if the output device is 'X'
     and plot system variable !p.multi(0) eq 0.  The first condition
     disables PAUSE when output is directed to a postscript file.
     The second condition ensures that pauses occur only just before
     the screen is erased for a new plot.
     
     NOTE: After PAUSE returns to the calling program different
     actions can be performed depending on whether the left, middle
     or right mouse button was pressed.  Just test on the !err system
     variable: !err=1 => left !err=2 => middle !err=4 => right.

 COMMON BLOCKS: pause_blk
                       
 EXAMPLE:        

x=findgen(201)/10.-10. 
for a=-2.,2.,.1 do begin & plot,x,1/(x^2*10.^a+1),tit=string(a) & pause & end

for a=-2.,2.,.1 do begin & plot,x,1/(x^2*10.^a+1),tit=string(a) &$
   pause,/u & end

  author:  Paul Ricchiazzi                            22sep92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/pause.pro)


PCA

[Previous Routine] [Next Routine] [List of Routines]
	PCA

 PURPOSE:
	Carry out a Principal Components Analysis (Karhunen-Loeve Transform)

 CALLING SEQUENCE:
	PCA, data, eigenval, eigenvect, percentages, proj_obj, proj_atr, 
		[MATRIX =, TEXTOUT = ,/COVARIANCE, /SSQ, /SILENT ]

 INPUT PARAMETERS:
	data -  2-d data matrix, data(i,j) contains the ith sample of the
               jth variable.  DATA shoud be dimensioned (NSAMP,NVAR), where
               NSAMP is the total number of samples and NVAR is the total
               number of variable parameters.  For example, consider
               a scatter plot of temperature vs relative humidity.
               The first index of DATA cycles over all measurments and the
               second index cycles over two parameters: T and Rh.  IF
               T and Rh are 1-D arrays containing all sampled values then
               DATA may be constructed as DATA=[[T],[Rh]].

 OPTIONAL INPUT KEYWORD PARAMETERS:
	/COVARIANCE - if this keyword set, then the PCA will be carried out
		on the covariance matrix (rare), the default is to use the
		correlation matrix
	/SSQ - if this keyword is set, then the PCA will be carried out on
		on the sums-of-squares & cross-products matrix (rare)

 OPTIONAL OUTPUT PARAMETERS:
 eigenval	NVAR element vector containing the sorted eigenvalues
	
 eigenvect 	NVAR x NVAR matrix containing the corresponding 
		eigenvectors, first index cycles over different eigenvectors
               second index cycles over original coordinate directions
	
 percentages	NVAR element vector containing the cumulative percentage 
		variances associated with the principal components
	
 proj_obj 	NSAMP by NVAR matrix containing the projections of the 
		objects on the principal components
	
 proj_atr	NVAR by NVAR	matrix containing the projections of 
		the attributes on the principal components
 	
 MATRIX	analysed matrix, either the covariance matrix if
               /COVARIANCE is set, the "sum of squares and
               cross-products" matrix if /SSQ is set, or the (by
               default) correlation matrix.  MATRIX will have
               dimensions NVAR x NVAR

 NOTES:
	This procedure performs Principal Components Analysis (Karhunen-Loeve
	Transform) according to the method described in "Multivariate Data 
	Analysis" by Murtagh & Heck [Reidel : Dordrecht 1987], pp. 33-48. 

	Keywords /COVARIANCE and /SSQ are mutually exclusive.

	The printout contains only (at most) the first seven principle 
	eigenvectors.    However, the output variables EIGENVECT contain 
	all the eigenvectors
	
       Different authors scale the covariance matrix in different ways.
	The eigenvalues output by PCA may have to be scaled by 1/NSAMP or
	1/(NSAMP-1) to agree with other author's calculations when /COVAR is 
	set.

	Users of V3.5.0 or later could change the calls to TQLI and TRED2
	to NR_TQLI and NR_TRED2

 EXAMPLE:
;	PCA analysis on a scatter plot of two variable, t1,t2, which we
;      will assume are linearly dependent on 2 random gaussian variables
;      x1,x2 as follows,
;
    nsamp=10000
    x1=randomn(iseed,nsamp)   
    x2=randomn(iseed,nsamp)
    t1=5*x1+2*x2             ;  =  = 25*+4* = 29
    t2=5*x1-2*x2             ;  = 25*-4* = 21
                             ; 
    data=[[t1],[t2]]         ; nsamp measurements of 2 parameters
    pca,data,eval,evec,per   ;  
                             ;  |1-ev    21/29|       eigenvalue 
    print,eval               ;  |             | = 0   equation on  
    print,evec               ;  |21/29   1-ev |       correlation matrix
    print,per                ; 
                             ; ev=1+-(21/29) = 1.7248, .2752

    t=findrng(0,2*!pi,100)
    xx1=evec(0,0)*20                       ; 1st eigenvector
    yy1=evec(0,1)*20
    xx2=sqrt(eval(1)/eval(0))*evec(1,0)*20 ; 2nd eigenvector
    yy2=sqrt(eval(1)/eval(0))*evec(1,1)*20
    plot,t1,t2,psym=3,xra=[-20,20],yra=[-20,20],pos=boxpos(/asp)        
    oplot,xx1*[-1,1],yy1*[-1,1] & oplot,xx2*[-1,1],yy2*[-1,1]
    oplot,cos(t)*xx1+sin(t)*xx2, cos(t)*yy1+sin(t)*yy2
    putstr,'eigenvector 1',11.,16.6,chars=1.3
    putstr,'eigenvector 2',5.4,-7.1,chars=1.3


 COPYRIGHT:
	Copyright 1993, Hughes STX Corporation, Lanham MD 20706.

 REVISION HISTORY:
	Immanuel Freedman (after Murtagh F. and Heck A.).     December 1993
       code cleanup and corrected output description (PJR)   June     1997

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/pca.pro)


PFILL

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  pfill

 PURPOSE:  break a long string consisting of many blank-separated
           words into a paragraph that consists of several lines each
           with a given number of characters (60 character default).
           This procedure can be use used with LEGEND and CAPTION to
           produce nicely formated figure captions.  The nice thing
           about PFILL is that it will properly compute the length of
           lines which contain text escape sequences such as a =
           !7d!x!ai!b.

 USEAGE: result=pfill(string,nchars=nchars,exdent=exdent,cr=cr,nlines=nlines)

 INPUT:    
  string   a string which consists of words separated by blanks
           Note that the !9K!x maps to a hardwired space

 KEYWORD INPUT:

  nchars   maximum number of characters per line (default=60)

  exdent   if set, EXDENT specifies the number of characters with
           which to indent all but the first line.  Use this to make
           a "hanging indent."  You can indent the first line by
           simply adding some spaces to the beginning of the string.

  cr       if set, replace instances of "\" in output string with "!c".  
           This allows formatted string to be used with XYOUTS or PUTSTR.

 OUTPUT:
  result   a paragraph string which consists of several lines each 
           with a given number of characters (60 character default).
           Lines are separated by the character "\", which is
           understood by LEGEND to indicate a newline.  You can turn
           the string into a string array, with each array element
           corresponding to one line in the paragraph by using
           STR_SEP.  For example, t=str_sep(pfill(t,n=30),'\').

 KEYWORD OUTPUT:

  nlines   number of lines in result


 EXAMPLE:  

 
 t='PURPOSE: break a long string consisting of many blank-separated '+$
   'words into a paragraph that consists of several lines each with '+$
   'a given number of characters (60 character default).  This procedure'+$
   ' can be used with LEGEND to produce nicely formated figure'+$
   ' captions.  The nice thing about PFILL is that it will properly'+$
   ' compute the length of lines which contain text escape sequences'+$
   ' such as x = !7d!xa!a2!n / !7d!xb!bi!n * (!13A - B!x) * (!13C -'+$
   ' D!3).  Text editors do not understand that all those extra exclamation'+$
   ' points should not be included in the character count of each line.'
 
 w8x11

 legend,pfill(t),/fill,/box,/norm,pos=[0.14,0.71,0.82,0.98]

 legend,pfill(t,nchar=80),/fill,/box,/norm,pos=[0.05,0.48,0.96,0.68]

 legend,pfill(t,n=80,exdent=11),/fill,/norm,pos=[0.11,0.28,0.85,0.46]

 legend,pfill('        '+t,n=80),bg=0,/fill,/norm,pos=[0.11,0.04,0.89,0.22]

 AUTHOR:   Paul Ricchiazzi                        03 Jul 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/pfill.pro)


PHIST

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       PHIST

 PURPOSE:
       plot histogram

 CALLING SEQUENCE:
       phist,variable

 INPUTS:
   arr    	  array to be plotted

 KEYWORD INPUTS:

   numbin        number of histogram bins
   binsize       size of bins (nullifies effect NUMBIN)
   xrange        x value range on plot (implies xstyle=1)
   yrange        y value range on plot 
   percent       show percentage histogram
   cumulative    show cumulative histogram
   overplot      plot this histogram over a previous plot
   xtitle        x title on plot
   ytitle        y title on plot
   title         title on plot
   width         width of the histogram bars (1 causes vertical bars
                 to fill the horizontal space, values less than 1 leave
                 space between bars)


 EXAMPLE:

   !p.multi=[0,2,2]
   r=randomn(seed,2000)
   phist,r
   phist,r,/perc
   phist,r,/perc,/cum
   phist,r,yrange=[0,.5],binsize=.5,color=100,/per
   phist,r^3,yrange=[0,.5],binsize=.5,color=150,/per,/over,width=.3
 
 AUTHOR and DATE:
  author:  Paul Ricchiazzi                            feb95
           Institute for Computational Earth System Science
           University of California, Santa Barbara

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/phist.pro)


PICKC

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:   pickc

 PURPOSE:   interactive adjustment of a series of discreet color values

 USEAGE:    pickc,colrng,labels=labels,group=group

 INPUT:
  colrng    2 element vector specifying the color index range accessable
            to pickc (default=[0,!d.n_colors-1])
 
 KEYWORD INPUT:
  labels    names to be associated with particular color indecies.
            if labels are provided NN is reset to n_elements(LABELS).

  group     widget id of widget procedure that calls PICKC

 OUTPUT:    none

 PROCEDURE:
            When first called, PICKC will create a new IDL window
            named "PICKC".  A color wheel is drawn with hue values
            varying from 1 - 360 degrees around the circle and
            saturation values varying from 0 at the center to 1 at
            the outer edge of the circle.
             
            Motion of the cursor inside the PICKC window with the
            with a mouse button pressed down adjusts the Hue and Saturation
            values and leaves the brigtness unchanged.

            Use the intensity slider to change the brightness.

            Use the color index slider to select a new color index

 BUTTONS:

      DONE: save new RGB values and quit

    CANCEL: restore old RGB values and quit
 
   XLOADCT: call the XLOADCT widget
    
   DIFFUSE: smear the current color to adjacent color indicies
            repeated clicks on DIFFUSE button causes the current
            color to diffuse further along the color scale.

      HELP: print this text


 EXAMPLE:
            Make a color plot and use PICKC to adjust color values:

  plot, [0,100],[-3,3],/nodata
  d=findgen(100)
  efac=exp(-((d-50)/20)^2)
  oplot,3*sin(d/2)*efac,color=1,thick=3 
  oplot,sin(d/3)*efac,color=2,thick=3  
  oplot,sin(d/2)*efac,color=3,thick=3  
  oplot,3*efac,color=4,thick=3
  oplot,efac,color=5,thick=3
  oplot,-3*efac,color=4,thick=3
  oplot,-efac,color=5,thick=3
  r=[0,0,127,255,0,127] & g=[0,127,255,0,127,255] & b=[0,255,0,127,255,0]
  tvlct,r,g,b
  pickc,[1,5]

  loadct,0
  pickc            ;  choose a color index, change its RGB value, smear it


  author:  Paul Ricchiazzi                            5feb93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/pickc.pro)


PICK_CURSOR

[Previous Routine] [Next Routine] [List of Routines]
 routine:   pick_cursor
 useage:    pick_cursor
 inputs:    none
 outputs:   none
 side effects:
            changes the graphics cursor

 procedure  cycle through different cursor types by hitting the
            the left or middle mouse button.  Hit the right mouse button
            to exit
 
  author:  Paul Ricchiazzi                            aug93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/pick_cursor.pro)


PLACETEXT

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       PLACETEXT

 PURPOSE:
       Put text on a plot using LEGEND.PRO.

 CALLING SEQUENCE:
       placetext,'this is a test'

 INPUTS:
       text        text to be written to screen.  May either be string
                   array or string with different lines separated by '\'.

 OPTIONAL INPUTS:
   center      lines are centered rather than left justified

   (below are taken from legend.pro)

   pos         position and size of legend area in normalized data
               coordinates.  Format of this four element vector is
               [x0,y0,x1,y1] where x0,y0 is the position of lower
               left corner and x1,y1 is the position of the upper
               right corner.  For example pos=[.5,.5,.9,.9] specifies
               a legend in the upper right quadrant of the data
               window.  If the POS parameter is not set or if POS is
               set to zero, then the CURBOX procedure is called to
               set the legend position interactively.

               NOTE: the value of POS can be retrieved by setting POS
               to a named variable which has an initial value of zero.

   linestyle   an array of linestyle types, one for each element of LABELS

   psym    an array of symbol types, one for each element of LABELS

   color       an array of color indices, one for each element of LABELS.
               Any elements of COLOR set to -1 causes the default color,
               !P.COLOR, to be used.

   thick       an array of line thicknesses, one for each element of LABELS
               (default=!p.thick)

   numsym      number of symbol nodes used to indicate linestyle or symbol
               type.  The length of the line is measured in units of 4
               character widths so that the length of the line
               = 4*(NUMSYM-1) * X_CHARSIZE    (default=3)

   fg_color    color of box and legend titles (default=!P.COLOR)

   bg_color    background color. Setting BG_COLOR erases the area
               covered by the legend (filling it with color BG_COLOR)
               prior to writing the legend.  If both BG_COLOR and !p.color
               are zero then the background color is reset to 255 to
               gaurantee a readability.


   box         if set draw a box around the legend text

   ystretch    factor by which to increase vertical spacing of legend
               entries. (default = 1)

   silent      if set, don't print anything to the terminal

 OUTPUTS:

 EXAMPLE:

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  2/22/94

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/placetext.pro)


PLANCK

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:     planck

 USEAGE:      result=planck(ww,t [,/microns])

 INPUT:

   ww         wavenumber (cm-1) or wavelength (microns) if /microns set,
              can be either scalar or vector

   t          temperature (degrees K), can be scalar or vector.

 OUTPUT:

   result     black body spectral intensity, commonly known as the 
              Planck function

                               microns set         microns not set
                               -----------         ---------------
                units:        W/m2/sr/micron         W/m2/sr/cm-1

              

 UNIT CONVERSION FACTORS:

               W/m2/sr/cm-1    x 1000 = erg/s/cm2/sr/cm-1
               W/m2/sr/micron  x 1000 = erg/s/cm2/sr/micron
               W/m2/sr/micron         = erg/s/cm2/sr/nm

 the spectral flux generated by a black body surface is =   pi * planck

; EXAMPLE
 
; plot black body curve for a 300, 280 and 260 degrees K.

 w=findrng(10000/333.33,10000/4.,200)
 plot,w,planck(w,300),xtitle='wavenumber (cm!a-1!n)',ymargin=[10,2],$
        ytitle='W/m!a2!n/sr/cm!a-1!n',title='Black Body Radiance'
 AXIS,0,4*!d.y_ch_size,XAX=0,/dev,xtickv=[0,10000./[50,20,13,10,8,6,5,4]],$
       xticks=8,xtickn=[' ','50','20','13','10','8','6','5','4'],$
       xtitle='wavelength (microns)'
 
 oplot,w,planck(w,280),li=3
 oplot,w,planck(w,260),li=4
 legend,'.cBlack Body\.cTemperature\\300\280\260',li=[0,3,4],pos=[.7,.6,.9,.9]

; planck function for one of the sbdart standard atmospheres

 atmosz,idatm=4,zz,pp,tt
 !p.multi=[0,2,2] & yt='Altititude (km)' & xt='W/m!a2!n/sr'
 plot,planck(3,tt,/mic),zz,title='!7k!x = 3um',ytit=yt
 plot,planck(4,tt,/mic),zz,title='!7k!x = 4um'
 plot,planck(5,tt,/mic),zz,title='!7k!x = 5um',ytit=yt,xtit=xt
 plot,planck(15,tt,/mic),zz,title='!7k!x = 15um',xtit=xt


  author:  Paul Ricchiazzi                            3dec92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/planck.pro)


PLOT3D_ROT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  plot3d_rot

 PURPOSE:  plot a 3-D trajectory and rotate plot interactively

 USEAGE:   plot3d_rot,xx,yy,zz

 INPUT:    
   xx,yy,zz
     vector trajectory of path

 KEYWORD INPUT:

   title
     title string

   dang
     angle increment between successive rotations (default=5)

   cang
     constant angle of rotation of the xyz coordinate axis about z-axis.
     (default=30)

 OUTPUT:

 DISCUSSION:

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  

  x=randf(30,3)
  y=randf(30,3)
  z=randf(30,3)

  plot3d_rot,x,y,z

  plot3d_rot,x,y,z,/continuous


 AUTHOR:   Paul Ricchiazzi                        11 Apr 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/plot3d_rot.pro)


PLOTCOMPARE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       PLOTCOMPARE

 PURPOSE:
       Scatter plot two similar variables, print statistics.

 CALLING SEQUENCE:
       plotcompare,xquantity,yquantity

 INPUTS:
      xquantity      variable to plot along x-axis
      yquantity      variable to plot along y-axis

 KEYWORD INPUTS:
      hist        plot as 2D histogram (xrange, yrange turned off)
      bindim      number of bins on one side for 2D histogram
      tvim        display 2D histogram as image (default is contour plot)
      interactive interactively set the statistics legend
      pos         after locating legend with interactive keyword, specify 
                  legend location with this
      bigtext     print statistics with bigger font
      widetext    print statistics with wider font for use in printouts

   below are plot keywords:
      title          
      ymargin        
      xtitle         
      ytitle         
      xrange
      yrange
      psym

 OPTIONAL INPUTS:

 OUTPUTS:

 OPTIONAL OUTPUTS:

 EXAMPLE:

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  1/04/94

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/plotcompare.pro)


PLOTPAGE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  plotpage

 PURPOSE:  

 USEAGE:   plotpage,x,y,npage=npage

 INPUT:    
   x       variable ploted along x-axis
   y       variable ploted along y-axis, 
           if y is an 2-d array then 
           plot,x,y(*,0) 
           oplot,x,y(*,1)
           oplot,x,y(*,2)...

 KEYWORD INPUT:

   npage   suggested number of pages into which horizontal range of
           plot is broken.  the actual number of pages is chosen to
           make the x range values come out to nice even numbers.

   xrange  x axis range which will be broken up into pages

   yrange  either a vector specifying y range, or a scalor.  If
           yrange is set to a scalor (e.g., /yrange) then the yrange
           adapts to the y variable range appropriate to each page.

           All other plot keywords are also accepted and passed to
           the plot procedure.

 KEYWORD OUTPUT:

   xrng    the x-axis range that corresponds to the last active page 
           before plotpage is terminated.

 DISCUSSION:
          use plotpage to page through pages of a very high density 
          plot.  New pages (i.e., the next increment in the x-range
          of the plot) are selected by the middle (forward) or left
          (backward) mouse button.  The number of plot pages in which
          to break the horizontal range of the plot is selected with
          the keyword parameter npage.

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  

 solar,x,y
 plotpage,x,y,npage=100

 AUTHOR:   Paul Ricchiazzi                        24 Feb 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/plotpage.pro)


PLOTSYM

[Previous Routine] [Next Routine] [List of Routines]
 routine:    plotsym

 usage:      plotsym,x,y,xsym,ysym

 purpose:    overlays plot symbols on the last data window.  A single
             call can create symbols of varying size, fill color, and
             outline color and thickness.  Symbols of arbitrary shape
             can be created.  Note that the symbols may be filled
             with a different color then the outline color.  This can
             dramatically unclutter the appearance of densely packed
             scatter plots.  See example.
              

 input:
   x         x coordinates of symbol centers on plot
   y         y coordinates of symbol centers on plot 
   xsym      x coordinantes of symbol outline with respect to symbol center
   ysym      y coordinantes of symbol outline with respect to symbol center

   NOTE:     if TYPE or XSYM and YSYM are not supplied a circular symbol
             is assumed

 keyword input:
   ocolor    outline color of symbol 
   fcolor    fill color of symbol
   thick     line thickness of symbol outline
   size   symbol size multiplier
   type      symbol type, a string matching one of 

                       'DIAMOND',   'PENTAGON',  'CLOVER',   'PACMAN',
                       'SPIRAL',    'BIGX',      'CIRCLE',   'SQUARE',
                       'TRIANGLE',  'STAR',      'HEXAGON',  'HEART',
                       'SPADE',     'CLUB'
             
   NOTE:     OCOLOR, FCOLOR, THICK and SIZEE may be specified as
             single values or vector of values, one for each element 
             of x and y

   device    if set, coordinates are in device units
   normal    if set, coordinates are in normalized units
   data      if set, coordinates are in data units (default)


   NOTE:

   the OCOLOR, FCOLOR, THICK and SIZE parameters may be specified as 
   vectors quantities, one value for each point on the plot

 SIDE EFFECTS:
   changes the shape of user-defined plot symbol (accessed with psym=8).

 EXAMPLE:

   x=randomu(iseed,400)                                                 
   y=randomu(iseed,400)                                                 
   z=1.-x-y                                                             
   fcolor=bytscl(z,top=!p.color)                                        
   ocolor=5*!p.color                                                    
   loadct,5                                                             
   plot,x,y,/nodata                                                     
   plotsym,x,y,type='square',fcolor=fcolor,ocolor=ocolor,thick=1,size=1.5

;  In this example note how PLOTSYM unclutters the scatter plot

   !p.multi=[0,1,2]
   x=randomn(iseed,400)                                                 
   y=randomn(iseed,400)                                                 
   plot,x,y,/nodata                                                     
   plotsym,x,y,size=2

   plot,x,y,psym=8
          
  author:  Paul Ricchiazzi                            jan93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/plotsym.pro)


PLOT_CYCLE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE
   plot_cycle

 PURPOSE:
   set the position of new plots so that they fill the frame in a given
   order.  New plots cause only a single subframe to be overwritten.  Old
   frames are left for comparison.

 USEAGE:	
   plot_cycle,nx,ny,icycle,i

 INPUT:
   nx       
    number of horizontal frames

   ny
     number of vertical frames 

   icycle
     index array specifying the order frames are overwritten, upper left
     frame is 1.

   i
     index into icycle (incremented after each call)

 OUTPUT: i

 EXAMPLE:	

     !p.multi=[0,1,2]
     f=randata(128,128,s=3)
     tvim,f,/interp
     xw=!x.window & xr=!x.crange
     yw=!y.window & yr=!y.crange
      
     x1=60 & x2=80 & y1=60 & y2=80
     !p.charsize=2
     while y1 gt 0 do begin &$
       plot_cycle,2,4,[5,6,7,8],i &$
       xx=x1+indgen(x2-x1+1) &$
       yy=y1+indgen(y2-y1+1) &$
       contour,f(x1:x2,y1:y2),xx,yy &$
       wait,.5 &$
       curbox,x1,x2,y1,y2,xw,yw,xr,yr,/init,inc=4,/mess &$
     endwhile
      
      

 REVISIONS:

  author:  Paul Ricchiazzi                            date>
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/plot_cycle.pro)


PM

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       PM

 PURPOSE:
       Shorthand way of setting !p.multi.

 CALLING SEQUENCE:
       PM,1,2

 INPUTS:

 OPTIONAL INPUTS:
   row     Sets number of plots per row
   col     Sets number of plots per col

 OUTPUTS:

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  12/03/93

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/pm.pro)


PMOM

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  pmom

 PURPOSE:  compute legendre moments of scattering phase function

 USEAGE:   pmom,mu,phase,nm,pm

 INPUT:    
   mu      cosine of polar angle, in range -1, 1
   phase   phase function at each polar angle, normalization is arbitrary
           
           NOTE: the accuracy of the integration depends on the
                 number values provided for mu and phase.  For
                 example, 10000 steps were required to obtain better
                 than 1% accuracy for all 21 moments of the
                 Henyey-Greenstein function with g=0.7.  More steps
                 may be required when higher moments or more sharply
                 peaked functions are considered.

   nm      number of of legendre moments. moments are numbered from 0 to nm
           for a total of nm+1 values.

 OUTPUT:
   pm      legendre moments (nm+1) values

 DISCUSSION:
   This procedure generates the legendre moments of an arbitrary
   function defined in the range -1 to 1.  These coefficients are
   the input quantities required by DISORT for the specification of 
   of scattering phase function or BRDF.  The output quantity, pm,
   is defined as,

           /                      /  /
   pm(i) = | f(mu) P(i,mu) d mu  /   | f(mu) d mu
           /                    /    /

   where P(i,mu) is the legendre polynomial, f is the phase function, and
   the range of the integrals are from -1 to 1.


 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  find moments of Henyey-Greenstein phase function
           The analytic result has pmom=1/g^indgen(nm+1)
           
           ns=10000 & g=.7 & nm=20

           mu=findrng(-1,1,ns)
           phase=(1.-g^2)/(1.+g^2-2*g*mu)^1.5
           pmom,mu,phase,nm,pm,/view
           print,f='(a/(10f8.4))','pmom',pm(1:*)
           print,f='(a/(10f8.4))','pmom/g^i',pm(1:*)/g^(1+indgen(nm))


 EXAMPLE:  find moments of Rayleigh scattering phase function
           the analytic result has pmom(0)=1 and pmom(2)=.1
           
           ns=1000 & nm=10

           mu=findrng(-1,1,ns)
           phase=(1.+mu^2)
           pmom,mu,phase,nm,pm
           print,f='(a/10f8.4)','pmom',pm

           phs=phase<0.
           norm=integral(mu,phase)
           for i=0,nm do phs=phs+.5*norm*(2*i+1)*pm(i)*legendre(i,mu)
           plot,mu,phase
           oplot,mu,phs

 AUTHOR:   Paul Ricchiazzi                        29 Jul 98
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/pmom.pro)


PNTS_NEAR

[Previous Routine] [Next Routine] [List of Routines]
 routine:       pnts_near
 purpose:       return index array of points within radius

 useage:        pnts_near,plon,plat,lonrng,latrng,nx,ny,radius,ii,nc

 input:
   plon         longitude of point
   plat         latitude of point
   lonrng       longitude range (two element vector)
   latrng       latitude range
   nx           number of points across lonrng
   ny           number of points across latrng
   radius       radius of region
 
 output:
   ii           index array of point within disk
   nc           number of points within disk

  author:  Paul Ricchiazzi                            jan93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/pnts_near.pro)


POLAR_ORTHO

[Previous Routine] [Next Routine] [List of Routines]
 routine          polar_ortho
 input:
   alat           latitude array
   alon           longitude array
   outer_lat      outer latitude limit

 output:
   xn       x coordinate to which (alat,alon) maps (normalized 0-1)
   yn       y coordinate to which (alat,alon) maps (normalized 0-1)

 purpose:         use this map projection procedure with regrid.pro

 EXAMPLE:

; polar projection
  
  window,/free,xs=400,ys=1000
  !p.multi=[0,1,3]
  latrng=[30,70] & lonrng=[-110,-70] & nnx=200 & nny=150
  alon=(float(c)-min(float(c)))/(max(float(c))-min(float(c)))
  alat=(imaginary(c)-min(imaginary(c)))/(max(imaginary(c))-min(imaginary(c)))
  alon=lonrng(0)+(lonrng(1)-lonrng(0))*alon
  alat=latrng(0)+(latrng(1)-latrng(0))*alat
  im=sqrt(abs(sin(alon*!pi)*sin(alat*!pi)))^.3
  tvim,im,/scale,title='image'
  contour,alat,/overplot,levels=[40,60],thick=4,color=0
  contour,alon,/overplot,levels=[-100,-80],thick=4,color=0

  regrid,alat,alon,nnx,nny,kx,ky,proj='polar_ortho',extras=30,degree=2
  imm=poly_2d(im,kx,ky,0,nnx,nny,missing=0)
  tvim,imm,/scale,xr=[-5517,5517],yr=[5517,5517],title='regrided image, d=2'

  regrid,alat,alon,nnx,nny,kx,ky,proj='polar_ortho',extras=30,degree=3
  imm=poly_2d(im,kx,ky,0,nnx,nny,missing=0)
  tvim,imm,/scale,xr=[-5517,5517],yr=[5517,5517],title='regrided image, d=3'
  
 AUTHOR:       Paul Ricchiazzi    feb94 
               Earth Space Research Group, UCSB

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/polar_ortho.pro)


POLY_XY

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:          poly_xy

 CALLING SEQUENCE:
                   RESULT=POLY_XY(X,Y,K)
 
 PURPOSE:     Evaluate the bivariate polynomial function of x and y
              where poly_xy = SUM [ k(i,j) * x^i * y^j ]
              the sum extends over i and j

 INPUT:  x    Vector of x values
         y    Vector of y values
         k    Array of polynomial coefficients (as computed by the
              the companion procedure POLY_XY_FIT.PRO)

  author:  Paul Ricchiazzi                            1mar93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/poly_xy.pro)


POLY_XYZ

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:          poly_xyz

 CALLING SEQUENCE:
                   RESULT=POLY_XY(X,Y,Z,K)
 
 PURPOSE:     Evaluate the trivariate polynomial function of x,y,z
              where poly_xyz = SUM [ k(i,j,k) * x^i * y^j * z^k]
              the sum extends over i,j,k

 INPUT:  x    Vector of x independent variable
         y    Vector of y independent variable
         z    Vector of z independent variable
         k    Array of polynomial coefficients (as computed by the
              the companion procedure POLY_XYZ_FIT.PRO)

  author:  Paul Ricchiazzi                            1mar93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/poly_xyz.pro)


POLY_XYZ_FIT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:          poly_xyz_fit

 CALLING SEQUENCE:
                   result=poly_xyz_fit(x,y,z,u,degree)
                   result=poly_xyz_fit(x,y,z,u,degree,ufit)
 
 PURPOSE:     Find the least square polynomial coefficients fitting the 
              dependent variable u to three independent variables x,y and z.
              The trivariate polynomial function of x,y,z is defined as
              ufit=SUM [ k(i,j,k) * x^i * y^j * z^k] (summed over i,j and k)

 INPUT:  
  x           Vector of x values (independent variable)
  y           Vector of y values (independent variable)
  z           Vector of z values (independent variable)
  u           vector of u values (dependent variable)
  degree      3 element vector specifying polynomial order.
              The fitting polynomial will be of order DEGREE(0) in x
              DEGREE(1) in y and DEGREE(2) in z

 OUTPUT:
  result      Array of polynomial coefficients (can be used directly
              in the companion procedure POLY_XYZ)

 Optional OUTPUT:
  ufit        polynomial evaluated at (x,y,z) input points

  author:  Paul Ricchiazzi                            1mar93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/poly_xyz_fit.pro)


POLY_XY_FIT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:          poly_xy_fit

 CALLING SEQUENCE:
                   result=poly_xy_fit(x,y,u,degree)
                   result=poly_xy_fit(x,y,u,degree,ufit)
 
 PURPOSE:     Find the least square polynomial coefficients fitting the 
              dependent variable u to the independent variables x and y.
              The bivariate polynomial function of x and y is defined as
              ufit=SUM [ k(i,j) * x^i * y^j ] (summed over i and j)

 INPUT:  
  x           Vector of x independent variable
  y           Vector of y independent variable
  u           Vector of dependent variable
  degree      2 element vector polynomial order.
              The fitting polynomial will be of order DEGREE(0) in x
              and of order DEGREE(1) in y

 OUTPUT:
  result      Array of polynomial coefficients (can be used directly
              in the companion procedure POLY_XY)

 Optional OUTPUT:
  ufit        polynomial evaluated at x and y points
  usig        standard deviation of (u-ufit)

 Example:

    x=randomu(iseed,100)
    y=randomu(iseed,100)
    u=1.+x+y+x*y+x^2+y^2
    k=poly_xy_fit(x,y,u,[2,2],ufit,usig)
    print, usig
    print, k
    

    xx=double(x)
    yy=double(y)
    uu=1.+xx+yy+xx*yy+xx^2+yy^2
    kk=poly_xy_fit(xx,yy,uu,[2,2],ufit,usig)
    print,usig,kk

  author:  Paul Ricchiazzi                            1mar93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/poly_xy_fit.pro)


PRANK

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    prank

 PURPOSE:    compute the value in ARRAY which is at a given 
             percentile ranking within ARRAY.  For example,
             median_of_array=prank(array,50)

 USEAGE:     result=prank(array,percentile)

 INPUT:
   array     an array of values, any type but string or complex
   p         percentile rank (0-100), may be a vector of ranks


 OUTPUT:     result=prank(array,percentile)
             result=value within array which is at the specified percentile
             rank

 EXAMPLE:	

    	 	r=10.^(randf(1000,2))*randomn(seed,1000)
               
               plot,r,psym=3
               plot,r,yrange=prank(r,[5,95]),psym=3

; print a set of percentile rankings within r

;      percentile rank 0   =>  min
;      percentile rank 50  =>  median
;      percentile rank 100 =>  max

               print,prank(r,[0,5,50,95,100])
               

 REVISIONS:

  author:  Paul Ricchiazzi                            feb95
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/prank.pro)


PRINCAX

[Previous Routine] [Next Routine] [List of Routines]
 NAME:         princax

 PURPOSE:      principle axis decomposion of a 2d distribution of points

 USEAGE:       princax,xx,yy,ev1,ev2,v1,v2
 
 INPUTS:       
  xx, yy       coordinate posititions

 KEYWORD INPUTS:
  view         if set, draw a scatter plot and draw the major and minor
               axis of the characteristic elipsoid with the half length
               of the axis equal to the square root of the eigenvalue
               
 
 OUTPUTS:      
  xcm,ycm      coordinates of the center of mass

  ev1,ev2      eigenvalues

  v1,v2        principle axis

 PROCEDURE:    solves the following eigenvalue equation
 
               A v = L v        where A is the moment of inertia tensor
                                of the object, and L are the eigenvalues.

                                /      \
                         A =    |               |          
                                \      /

                                the angled brackets indicate averages over
                                the point distribution
 EXAMPLE:      

 u=5*randomn(iseed,50)
 v=randomn(iseed,50)
 x=u-v
 y=u+v
 princax,x,y,xcen,ycen,ev1,ev2,v1,v2,/view

 AUTHOR:       Paul Ricchiazzi                                nov93
               Earth Space Research Group, UC Santa Barabara

 REVISIONS:    

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/princax.pro)


PSD

[Previous Routine] [Next Routine] [List of Routines]
ROUTINE:      psd
               
USEAGE:       psd,image,wavenum,power,scale=scale,view=view,$
                      unit=unit,title=title,binpower=binpower,$
                      xrange=xrange,density=density

               
PURPOSE:      compute angle averaged power spectral density of an image
               
INPUT:        

   image
       a one or two dimensional data array
               
OUTPUT:
       
   wavenum     
       The spatial wave number of the scene (averaged over angle if
       image is 2-D).  WAVENUM ranges from a minimum value of about
       2/max(NX,NY) cycle/pixel (i.e., the zero frequency component
       should not be included) to a maximum value of 1 cycle/pixel,
       i.e, the Nyquist frequency of the scene.  If SCALE is set,
       WAVENUM has units of cycles/unit where unit is the physical
       units used to set SCALE (see UNIT and SCALE, below).  If you
       want to have WAVENUM expressed in units of cycles/frame,
       (which only makes sense when NX=NY) set
       SCALE=[1./fix(NX/2),1./fix(NY/2)]
               
               
   power       
       energy spectra of scene.  if image has only one dimension POWER
       is the squared modulus of the fourier transform.  If image is
       two dimensional POWER is the angular integration of the
       squared modulus of fourier transform coeficients, P, over the
       anulus defined by a given value of k=sqrt(kx^2+ky^2).
               
       total power = integral(2 pi P k dk) = integral(POWER(k) dk),

KEYWORD INPUT:

   scale
       physical resolution of image, i.e., the size of a single picture
       element in physical units such as kilometers.  If SCALE is set
       to a two element vector, the two values specify the resolution
       in the x and y directions, respectively.  When SCALE is set, the
       units of WAVENUM are cycles/unit where UNIT are the physical
       units (see below) in which SCALE is specified.
               
   unit
       string variable specifying the physical units used to specify
       SCALE (used in xtitle of plot)
               
   view
       if set, plot log-log plot of psd
               
       if VIEW=2, WAVENUM and POWER are taken as input parameters
       (i.e., psd is not computed) for the PSD plot option.  In this
       case the IMAGE parameter is not used, but a dummy value must be
       supplied.
               
   title
       plot title
               
   binpower
       If set, changes the default bin size used for 2-D wavevector
       binning.  Normally wavevector binning is set up to put one
       unit of the scalor wavevector in each wavenumber bin:
     
             k = sqrt(kx^2+ky^2)         scalor wavenumber
       
             n < k < n+1
     
       where n is an integer index for each wavenuber bin.  anulus. The
       kx and ky wavenumbers run from 0 to NX/2 and 0 to NY/2,
       respectively, (NX/2 and NY/2 represent the Nyquist frequency) If
       BINPOWER is set, the size of the wavenumber bins can be made to
       increase as a power of the wavenumber so that
     
             binsize = wavenumber^BINPOWER
     
       for example setting binpower gt 0 causes more averaging at large
       wavenumber and can be used to smooth out noisy power spectra.
       A value of BINPOWER between .1 and .5 seems to be sufficient to
       smooth out high frequency noise.  (default: binpower=0)
               
   xrange
       XRANGE sets the min and max wavenumber included in power
       spectrum plot. XRANGE is used to clip off noisy high frequency
       part of psd which sometimes occurs beyond 1 cycle per pixel in
       the horizontal or vertical direction.  XRANGE does not affect
       the returned values of WAVENUM and POWER, but it does affect the
       value of BETA.
     
       NOTE: For a square uniform grid the maximum wavenumber is
       sqrt(2) x 1 cycle/pixel.
               
   density 
       if set, plot spectral power density instead of spectral power.
       This is equivalent to dividing the power spectra by the
       wavenumber.
               

EXAMPLE:

; PSD of a scaling field

     w8x11
     !p.multi=[0,1,2]
     n=512                                          ; 
     slope=3                                        ; power law slope
     power=1./(1.>(dist(n)^(slope+1)))
     gg=sqrt(power)                                 ; fourier modulus
     gg=gg*exp(complex(0,2*!pi*randomu(iseed,n,n))) ; randomized phase
     ff=float(fft(gg,1))                              ; realization
     tvim,ff
     psd,ff,/view

; Spectra of a 1-d data

     n=2^14
     f=randf(n,2)
     !p.multi=[0,1,2]
     plot,w,f
     psd,f,w,p,/view
                                        
     
; PSD of a submatrix of a scene with spatially varying spectral structure, 
;
;     1. lower left quandrant:  scaling scene (SS) with spectral slope -2.5
;     2. upper left quandrant:  SS plus structure at 0.125 nyq
;     3. upper right quandrant: SS plus structure at .25 and 0.125 nyq
;     4. upper left quandrant:  SS plus structure at .25  nyq
;
;        where nyq = 1.4141 cycles/(horizontal or vertical pixel)
;
;        to stop looping this example, put box in lower frame and click RMB

   w8x11
   !p.multi=[0,1,2]
   nx=512 & ny=512
   ff=randata(nx,ny,s=2.5)
   ff=5*cos(0.125*!pi*findgen(nx))#cos(0.125*!pi*findgen(ny))*$
       (((replicate(1,nx)#findgen(ny)/(ny-1))-.5)>0)+ff
   ff=5*cos(0.25*!pi*findgen(nx))#cos(0.25*!pi*findgen(ny))*$
       (((findgen(ny)/(ny-1))#replicate(1,ny)-.5)>0)+ff
   tvim,ff
   xwin=!x.window & xrng=!x.crange
   ywin=!y.window & yrng=!y.crange
   x1=nx/4 & x2=x1+nx/2
   y1=ny/4 & y2=y1+ny/2

   !p.multi=[4,2,4]
   curbox,x1,x2,y1,y2,xwin,ywin,xrng,yrng,inc=8,/init,/mess,label='region 1'
   psd,ff(x1:x2,y1:y2),/view,title='region 1'
   curbox,x1,x2,y1,y2,xwin,ywin,xrng,yrng,inc=8,/init,/mess,label='region 2'
   psd,ff(x1:x2,y1:y2),/view,title='region 2'
   curbox,x1,x2,y1,y2,xwin,ywin,xrng,yrng,inc=8,/init,/mess,label='region 3'
   psd,ff(x1:x2,y1:y2),/view,title='region 3'
   curbox,x1,x2,y1,y2,xwin,ywin,xrng,yrng,inc=8,/init,/mess,label='region 4'
   psd,ff(x1:x2,y1:y2),/view,title='region 4'

 

  author:  Paul Ricchiazzi                            may93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/psd.pro)


PUTSTR

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:
   putstr
 
 PURPOSE:
   use cursor to position and orient text on a plot

 USEAGE:
   putstr,label,xs,ys,orient=orient,charsize=charsize,color=color,$
           subnorm=subnorm,norm=norm,align=align,contrast=contrast, $
           bg_color=bg_color,box=box,valign=valign

 INPUT:

  label
    text label, type string

  xs
    x position of string (data coordinates, default)

  ys
    y position of string (data coordinates, default)


 KEYWORD INPUT:

  orient
    orientation in degrees

  charsize
    character size parameter.  The character size is the value of 
    CHARSIZE * !p.charsize.  (default=1)

  subnorm
    if set, x and y positions are specified in data window
    sub-normalized coordinates, i.e, the range 0 to 1 spans the entire
    data coordinate range.  Note that this is different then the
    usual IDL normalized coordinates.  When SUBNORM is set, a
    given x,y coordinate causes the text to appear in the same
    data window region regardless of how the x and y axes are
    scaled. LEGEND also uses this coordinate system.

  norm
    if set, x and y positions are specified in usual IDL normalized
    coordinates, i.e, the range 0 to 1 spans the entire window
    display range.

  align
    the text alignment point.  

    ALIGN=0.0 =>  text is left justified to x,y
    ALIGN=0.5 =>  text is centered at x,y
    ALIGN=1.0 =>  text is right justified to x,y
    
    The use of ALIGN is particularly useful to center or justify a
    multiline text string (see example).  Also, keep in mind the
    length of a string isn't always predictable when written to a
    hardcopy device. ALIGN should be used if you want to center or
    right justify a string to line up with something.
               
  valign
    vertical offset in character units. This keyword has no effect
    in interactive mode.
  
  contrast
    if set, PUTSTR writes the string twice; the first time the string
    will be drawn with very thick lines and in a contrasting color.
    The second time it will be drawn at the standard line thickness
    (from !p.thick) and with the color set by the color keyword.  You
    can control the thickness and the background color by setting
    CONTRAST to a two element vector, [thick,color]. This option
    should be used to draw annotation within image areas, where the
    legibility may otherwise suffer due to lack of contrast.

 KEYWORD INPUT:
 
 OUTPUT:
    none
 
 DESCRIPTION:
   Use PUTSTR to interactively position a text label on a plot.  The
   size and orientation of the text label are adjusted by pressing
   the left or middle mouse buttons.  Initially the LMB and MMB
   control the size of the label.  To enable the use of the LMB and
   MMB to control the label orientation angle, press the RMB and
   select the ANGLE menu item.
               
   To quit the proceedure press RMB and select the "QUIT" menu item.
   
   On exit, the PUTSTR command line options which will reproduce the
   text in the final position and orientation is printed to the
   terminal.  This string may be appended to the original PUTSTR
   comand using xwindows cut and paste.
   
   For similar text annotation capabiltiy see LEGEND.PRO

 EXAMPLE:

;; interactive placement of text strings:

 plot,randf(200,2)
 t1='Use PUTSTR to interactively position a text label!c'
 t2='on a plot.   The size and orientation of the text label!c'
 t3='are adjusted by pressing the left or middle mouse buttons.'
 text=t1+t2+t3
 putstr,text
 putstr,text,align=.5
 putstr,text,align=1

;; use putstr in non-interactive mode

 !p.multi=[0,1,2]
 window,0,xs=600,ys=900
 plot,randf(200,2),ymargin=[10,2]
 text='Figure 1. Dew point temperature as a function of!c' + $
      '          foobar position relative to mordant.'
 putstr,text,/subnorm,0.0,-0.2,charsize=2.0,orient=0.0
 plot,randf(200,3),ymargin=[10,2]
 text='Figure 2. Triple point temperature as a function of!c' + $
      '          mordant position relative to foobar.'
 putstr,text,/subnorm,0.0,-0.2,charsize=2.0,orient=0.0
 

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/putstr.pro)


PWD

[Previous Routine] [Next Routine] [List of Routines]
 routine    pwd
 purpose    print the current working directory

 output:
   cwd     directory name string. if present in argument list
           directory string is not printed to terminal.

  author:  Paul Ricchiazzi                            jan93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/pwd.pro)


QUEUE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:      queue

 PURPOSE:      display print queues

 USEAGE:       queue

 PROCEDURE:    choose print queue from pop up menu

 AUTHOR:   Paul Ricchiazzi                        01 Jun 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/queue.pro)


RADTEMP

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  radtemp

 PURPOSE:  compute radiation temperature from a radiance distribution

 USEAGE:   radtemp,w,r,microns=microns

 INPUT:    
   w       wavelength in microns or wavenumber in cm-1
   r       radiance in w/m2/um/str or w/m2/cm-1/str
           divide irradiance by pi 

 KEYWORD INPUT:

  microns  set to one for micron units

 OUTPUT:
   result  radiation temperature in kelvin

  
 EXAMPLE:  

 AUTHOR:   Paul Ricchiazzi                        20 Nov 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/radtemp.pro)


RANDATA

[Previous Routine] [Next Routine] [List of Routines]
 routine:      randata
 
 purpose:      generate a random field of data with given power spectrum
               and array size

 useage:       randata,n,slope,nx=nx,ny=ny

 inputs:
   nx          size of output grid in x direction

   ny          size of output grid in y direction, must be less than n.

               Since an FFT is used to create the random data,
               RANDATA runs faster if max(NX,NY) is a power of 2

 Keyword input:
   
   s           power law slope of power spectrum (default=4)
   
   locked      phases of fourier components locked to grid centers

 Keyword input/output

   iseed       the seed used to randomize the phases

 EXAMPLE:      
               n=64
               xs=sqrt(findgen(n))                  
               ys=sqrt(findgen(n))                  ; xss and yss are used
               xss=xs # replicate(1,n_elements(ys)) ; to give the random
               yss=replicate(1,n_elements(xs)) # ys ; data a nice shape

               shade_surf,randata(n,n,s=4)*xss*yss,az=10,ax=40

  author:  Paul Ricchiazzi                            27oct93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/randata.pro)


RANDF

[Previous Routine] [Next Routine] [List of Routines]
 routine:      randf
 
 purpose:      generate random time history data with given power spectrum

 useage:       randf,n,slope

 inputs:
   slope       power law slope of power spectrum (default=4)

   n           number of elements in time history. Since an fft is used
               to compute the random numbers powers of 2 are most efficient.

 EXAMPLE:      

; simple plot
               plot,randf(256,2)

; demonstrate use of frequency domain filtering

               f=randf(512,2)
               gf=exp(-.005*(findgen(256)-1)^2) & gf=[gf,reverse(gf)]
               ff=fft(gf*fft(f,1),-1)
               fac=total(abs(f))/total(abs(ff))
               plot,f
               oplot,ff*fac,color=100


 method:       a power law is used to set the spectral power as a
               function of frequency (i.e., p=1/w^s).  After the phase of
               the fourier components are randomized, the temporal
               realization is generated by taking the inverse FFT.
               

  author:  Paul Ricchiazzi                            27oct93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/randf.pro)


RAYLEIGH

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  rayleigh

 PURPOSE:  compute rayleigh optical depth at a give wavelength

 USEAGE:   result=rayleigh(wl,ps=ps,idatm=idatm)

 INPUT:    
   wl     wavelength in microns
 
 KEYWORD INPUT:
   ps       surface pressure in mb
   idatm    index of standard atmosphere
            1=tropical
            2=midlat summer
            3=midlat winter
            4=sub arctic summer
            5=sub arctic winter
            6=us62

 OUTPUT:   rayleigh optical depth

 DISCUSSION:

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  

   wl=[.414,.499,.609,.665,.860,.938]
   print,rayleigh(wl,idatm=4)

;  0.311728     0.144443    0.0640821    0.0448406    0.0158600    0.0111786

 AUTHOR:   Paul Ricchiazzi                        13 Apr 98
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/rayleigh.pro)


READBUF

[Previous Routine] [Next Routine] [List of Routines]
 purpose:    read a multi-dimension data buffer from a named ASCII file

 USEAGE:     readbuf,file,buf
             readbuf,file,buf,tag=tag,ntag=ntag,nskip=nskip,point=point,$
                     err=err,nc=nc,nl=nl,awk=awk
 input:  

   file      file name. If file name ends in a .gz or .Z suffix, the file
             is first uncompressed by running it through zcat.

             NOTE: make sure your shell knows where to find the zcat
                   utility.  Also note that the generic unix version
                   of zcat does not uncompress files created by the
                   gnu compression algorithm.  These files usually
                   have a .gz suffix.  The best bet is to set up a
                   link in your bin directory pointing to the gnu
                   version of zcat which uncompresses both .gz and .Z
                   type compressed files.  (e.g.,
                   /home/user13/frew/gnu/alpha-osf/bin/zcat)

   buf       a named array or structure set up to match the 
             data structure of FILE.
             

 optional keyword input:

   tag       string to search before reading begins.
             READBUF will scan through FILE looking for a line
             containing the string TAG. Data input starts on the
             next record (or NSKIP records later, if NSKIP is set)

   ntag      number of times TAG string is searched before reading input
             (default=1 when TAG is set, otherwise zero)

   nskip     number of records to skip before reading data.
             If TAG is set, data input starts NSKIP records after the 
             NTAG'th occurance of the TAG string in the file.
             If TAG is not set, data input starts NSKIP records 
             after the begining of the file. (default=0)

   point     byte offset into file after which reading begins

   nc        if set, buf is dimensioned fltarr(nc,nl) where nl is
             either set with the NL keyword, or is set automatically
             as the number of lines remaining in the file after tag,
             ntag and nskip actions.  This option doesn't work when
             POINT is specified.  Setting nc to zero causes both the
             number of columns and the number of lines to be set
             automatically by the file's line and word count (using the
             unix wc utility). This specification is only useful if the
             data is in the form of a rectangular array. The nc=0 option
             does not work with the nskip, point, ntag, and tag options.
             

   nl        if set buf is dimensioned fltarr(nc,nl) where nl is set
             with the NL keyword.

   awk       an awk command string used to preprocess the file.  if
             the input file is compressed (indicated by a .gz or .Z
             suffix) the results of 'zcat file' is piped into awk.
             Otherwise, awk reads the input file directly.  In either
             case the awk command string is used by awk to extract
             information from file and write the results to
             readbuf_tmp~.  This temporary file is subsequently read
             by readbuf, and deleted after processing.
             
 output:

  buf        data array 

 keyword output:

  point      byte offset into file at which reading stopped,
             can be used as input to next call of READBUF

  err        returns 1 if an io read error is detected.
             returns 0 if read is successful.

 EXAMPLE:
;       following a bunch of uninteresting output a fortran code 
;       writes to file junk.dat as follows
;
;        write(*,'(a)') 'bufout:'
;        do 20 k=1,3
;         do 10 j=1,6
;           write(*,'(1p11e11.3)') (buf(i,j,k), i=1,11) 
;    10   continue
;    20 continue
;
;      the buf array could be read with
 
        buf=fltarr(11,6,3)
        readbuf,'junk.dat',buf,tag='bufout:'
 
;      if the fortran code listed above were executed twice
;      it is possible to read the second occurance of buf as follows
 
        point=0                              
        buf0=fltarr(1)
        readbuf,'junk.dat',buf0,tag='bufout:',point=point 
        buf=fltarr(11,6,3)
        readbuf,'junk.dat',buf,tag='bufout:',point=point
 
;      In this case the first call to READBUF is used to find the
;      point (byte offset) in the file just past the first instance
;      of the string 'bufout:'.  The second call to READBUF starts 
;      where the previous READBUF left off, scanning the file until
;      just after the second  occurance of 'bufout:'. At this point
;      the second buf is read.
 
;      another way of doing the same thing is with the NTAG parameter,
 
        buf=fltarr(11,6,3)
        readbuf,'junk.dat',buf,ntag=2,tag='bufout:',
       
       NOTE: care must be taken that the TAG string is unique.

; Use awk to preprocess a file (which happens to be compressed)
; The awk command does the following:
;
;  1. change the file seperator character to a comma
;  2. select records for which column three = 272,273,276 or 277
;  3. print columns 3,6,7,8 and 9

        awk='BEGIN {FS=","};int($3) ~ /27[2367]/ {print $3 $6 $7 $8 $9}'
        readbuf,'a_D97.sgp.gz',buf,nc=0,awk=awk
        print,buf

  author:  Paul Ricchiazzi                            8JAN93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/readbuf.pro)


READ_TEXT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  read_text

 PURPOSE:  read text from a file

 USEAGE:   result=read_text(file,tag)

 INPUT:    
   file    name of input file (string).  if only one argument is
           supplied it is interpreted as the tag value and
           "captions.txt" is used as the default file.

   tag     search string.  READ_TEXT scans forward in the file until
           a line containing the TAG string is found.  From there
           READ_TEXT reads forward until an empty line is found.

           You can also tag the text block with a special invisible
           tag, i.e., a tag string which will not appear in the
           output string.  This special tag is composed of any NUMBER
           surrounded by the semicolon character ";".  In this case
           the value of tag supplied to READ_TEXT should be an integer
           For example if FILE contains the lines,

       ;1;this is an example

       ;2;this is the second line 

          then read_text(FILE,1) would yield, "this is an example".

          NOTE: Since a semicolon is interpreted by IDL as a comment
                you can put your caption text inside your IDL scripts.


 OUTPUT:
   result  matched text in FILE.

 DISCUSSION:
   READ_TEXT can be used to read text blocks from a file.  READ_TEXT
   opens the named file and scans forward in the file until a line
   containing the TAG string is found.  READ_TEXT reads forward until
   until a record containing no characters is found. (i.e., a
   carriage return with no characters or spaces in the line).  All
   text between the TAGed record and the blank line are returned.
   READ_TEXT can be used with CAPTION to write figure captions onto
   plots.

 EXAMPLE:  

  suppose file captions.txt contains ("|" indicates zeroeth column):

  |figure 1. some stuff
  |
  |figure 2. some other stuff
  |test test test
  |
  |figure 3. some more stuff

 caption,read_text('captions.txt','figure 2.')

 AUTHOR:   Paul Ricchiazzi                        13 Mar 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/read_text.pro)


READ_TOMS

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  read_toms,file,ozone

 PURPOSE:  read toms ascii data files 

 USEAGE:   read_toms,ozone,lons,lats

 INPUT:    
  file     Name of the toms archive data file.

 OUTPUT:
  ozone    ozone in dobson units in an global output grid
           Longitudes:  288 bins centered on 179.375 W to 179.375 E  
           (1.25 degree steps)  
           Latitudes :  180 bins centered on  89.5   S to  89.5   N  
           (1.00 degree steps)  

  lons     vector of longitudes (degrees)
  lats     vector of latitudes  (degrees)


 DISCUSSION:

   TOMS ozone data files from the Earth Probe satellite may be
   obtained via anonymous ftp from:

   /anonymous@jwocky.gsfc.nasa.gov:/pub/eptoms

   Each file contains global noon time measurements of total column 
   ozone for one day.  The data format is directly readable by this 
   procedure.  Data is available for 1996, 1997 and 1998 (in
   directories  oz96, oz97 and oz98)

 EXAMPLE:  

           read_toms,'ga970930.ept',ozone,lons,lats
           tvim,ozone,xrange=lons,yrange=lats,/scale
           map_set,0,0,/cont,/cyl,/noerase,pos=boxpos(/get)

; find toms ozone at sgp site for each day in
; september and october of 1997

           files=findfile('ozone/*.ept')
           lat=36.605 & lon=-97.485
           oz=fltarr(n_elements(files))
           for i=0,n_elements(files)-1 do begin &$
             print,files(i) &$
             read_toms,files(i),ozone,lons,lats &$
             fill_image,ozone,where(ozone eq 0.) &$
             oz(i)=interp(ozone,lons,lon,lats,lat) &$
           endfor


            

 AUTHOR:   Paul Ricchiazzi                        04 Jun 98
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/read_toms.pro)


REDUNDANT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:	    redundant

 PURPOSE:	    returns the indicies of elements array which are non-unique

 USEAGE:	    result=redundant(array)

 INPUT:       
   array           a vector array


 KEYWORD INPUT:

   all             if set, return all elements which appear more than
                   once. The default is to return all but one of the
                   replicated elements

   non             If set, return all non-redundant elements.  If ALL
                   is also set, return those elements which appear
                   only once, (i.e., all replicated items are left off
                   the list).

   indecies        If set return array indecies instead of the array 
                   elements.
 EXAMPLE:
;
           array=[1,2,3,1,4,2,3,3,5]

           print,array
;       1       2       3       1       4       2       3       3       5

           print,redundant(array)
        1       2       3       3

           print,redundant(array,/non)
;       1       4       2       3       5

           print,redundant(array,/all)
;       1       2       3       1       2       3       3

           print,redundant(array,/all,/non)
;       4       5

           print,redundant(array,/all,/non,/indecies)
        4       8


  author:  Paul Ricchiazzi                            feb95
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/redundant.pro)


REGRID

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE: regrid,alat,alon,latrng=latrng,lonrng=lonrng,nnx,nny,kx,ky
 PURPOSE: Find polynomial coeffients to warp an irregular grid into
          a regular grid.  

 INPUT:   
  alat    array of pixel latitudes
  alon    array of pixel longitudes
  nnx     number of pixels in x direction of output array
  nny     number of pixels in y direction of output array

 OPTIONAL KEYWORD INPUT:
  latrng  range of output latitudes (default = [min(alat),max(alat)] )
          not used when projection_name is set

  lonrng  range of output longitudes (default = [min(alon),max(alon)] )
          not used when projection_name is set

  nsamp   number of sample points from which to
          generate warping polynomial (default = 400)

  degree  the degree of the warping polynomial (default = 2)

  extras  extra parameters (single value, array or structure) used in
          the user supplied projection procedure.  The defininition of 
          extras is completely up to the user.

  projection_name:
          The name of the user supplied procedure which computes the
          map projection.  if projection_name is not supplied a
          cylindrical projection is assumed.  The user supplied
          procedure must accept as arguments alat,alon,extras and
          return the normalized coordinates xnorm,ynorm which show
          where a given lat,lon map to on a unit grid.  Here is an
          example for polar orthographic projection.

            pro polar_orthographic,alat,alon,extras,xn,yn
            outer_lat=extras(0)             ; the outer latitude limit
            xmax=cos(outer_lat*!dtor)
            xmin=-xmax
            ymax=xmax
            ymin=xmin
            if outer_lat gt 0 then begin
              xn=cos(alat*!dtor)*cos(alon*!dtor)
              yn=cos(alat*!dtor)*sin(alon*!dtor)
            endif else begin
              xn=cos(alat*!dtor)*cos(-alon*!dtor)
              yn=cos(alat*!dtor)*sin(-alon*!dtor)
            endelse
            xn=(xn-xmin)/(xmax-xmin)       ; normalized coordinates
            yn=(yn-ymin)/(ymax-ymin)
            
            return 
            end

 OUTPUT:
  kx      polynomial coefficients relating indecies xold to (xnew,ynew)
  ky      polynomial coefficients relating indecies yold to (xnew,ynew)

 COMMON BLOCKS:   NONE
 SIDE EFFECTS:    NONE


 PROCEDURE:    Use together with POLY_2D to warp images to regular lat,lon
               grid.  

 EXAMPLE:

  c=complex(2,2)+cmplxgen(250,200,/center)/100         ; create alat & alon
  c=c+c^2
  alon=float(c)-100
  alat=20+imaginary(c)
  im=sqrt(abs(sin(alon*!pi)*sin(alat*!pi)))^.3 
  !p.multi=[0,1,2]                               
  window,/free,xs=400,ys=600                           ; create new window
  tvim,im,/scale,title='image'
  latrng=[28,34] & lonrng=[-100,-95] & nnx=200 & nny=150
  contour,alat,/overplot,levels=latrng,thick=4,color=0
  contour,alon,/overplot,levels=lonrng,thick=4,color=0

; regrid and display 

  regrid,alat,alon,latrng=latrng,lonrng=lonrng,nnx,nny,kx,ky
  imm=poly_2d(im,kx,ky,0,nnx,nny,missing=0)
  tvim,imm,/scale,xr=lonrng,yr=latrng,title='regrided image'

 
; polar projection
  
  window,/free,xs=400,ys=1000
  !p.multi=[0,1,3]
  c=complex(2,2)+cmplxgen(128,128,/center)/100         ; create alat & alon
  c=c+c^2
  latrng=[30,70] & lonrng=[-110,-70] & nnx=200 & nny=200
  alon=(float(c)-min(float(c)))/(max(float(c))-min(float(c)))
  alat=(imaginary(c)-min(imaginary(c)))/(max(imaginary(c))-min(imaginary(c)))
  alon=lonrng(0)+(lonrng(1)-lonrng(0))*alon
  alat=latrng(0)+(latrng(1)-latrng(0))*alat
  im=randata(128,128,s=4) gt 2
  tvim,im,/scale,title='image'
  tvlct,[0,255,0],[0,0,0],[0,0,255]
  contour,alat,/overplot,levels=[40,50,60],thick=4,color=1
  contour,alon,/overplot,levels=[-100,-90,-80],thick=4,color=2
  
  regrid,alat,alon,nnx,nny,kx,ky,proj='polar_ortho',extras=30,degree=2
  imm=poly_2d(im,kx,ky,0,nnx,nny,missing=0)
  tvim,imm,/scale,xr=[-5517,5517],yr=[-5517,5517],title='regrided image, d=2'
  r=cos([40,50,60]*!dtor)*6371
  a=(-70-indgen(41))*!dtor
  for i=0,2 do oplot,r(i)*cos(a),r(i)*sin(a),color=1
  
  a=[-100,-90,-80]*!dtor
  for i=0,2 do oplot,5517*[0,cos(a(i))],5517*[0,sin(a(i))],color=2

 NOTE: the bogus stuff in the upper half plane of the tvim image is
       due to the use of the polynomial expansion outside the range
       for which the fit is valid.  This only happens when the new
       grid extends far beyond the limits of the original irregular
       grid.  
       
  
  author:  Paul Ricchiazzi                            ESRG
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/regrid.pro)


REGSTAT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  regstat

 PURPOSE:  display regional statistics of an image.

 USEAGE:   regstat,im

 INPUT:    
  im       2-d array

 KEYWORD INPUT: none

 OUTPUT:   none

 DISCUSSION:
           Use REGSTAT to print the regional statistics of selected areas
           within a TVIM image.  The region is selected using CURBOX. 
           The left and middle mouse buttons reduce and increase the
           region size.  The right mouse button causes the region
           statistics to be printed to the terminal (mean, standard
           deviation, minimum, maximum and array indicies).  Exit the
           procedure by hitting the right mouse button while the the
           box is outside the plot area
  
 EXAMPLE:  
           im=randata(128,128,s=3)
           tvim,im
           regstat,im

 REVISIONS:

 AUTHOR:   Paul Ricchiazzi                        01 Jun 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/regstat.pro)


RELHUM

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:      relhum

 PURPOSE:      compute relative humidity from wet and dry bulb temperature
               and pressure

 USEAGE:       result=relhum(td,tw,p) 

 INPUT:      
   t           ambient (dry bulb) temperature (celsius)
   tw          wet bulb temperatrue           (celsius)
   p           pressure                       (mb)

 OUTPUT:
   rh         relative humidity (partial pressure of water vapor divided
              by the saturated water vapor pressure)

 EXAMPLE:
   
               print,'the relative humidity is     ',relhum(29,20,980)

 References:

 Tetans, O. 1930. Uber emige meteorologische Begriffe. Z. Geophys. 6:297-309

 Weiss, A.1977. Algorithms for Calculation of Moist Air Properties on a Hand
 Calculator. Trans. ASAE 20:1133-1136

  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/relhum.pro)


REPCHR

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    repchr

 PURPOSE:    produces a string composed of repititions of a given character

 USEAGE:     result=repchr(n,c)

 INPUT:
    n        number of repititions
    c        character to repeat

 EXAMPLE:
             print,repchr(20,'-')

  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/repchr.pro)


RHOZ

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:   rhoz

 USEAGE:    result=rhoz(p0=p0,t0=t0,z=z,lr=lr)

 PURPOSE:   compute air density at altitude z

 KEYWORD_INPUTS:

   p0       surface pressure in mb        (default=1013.0 mb)
   t0       surface temperature in kelvin (default=273.0 K)
   z        alitude (km)                  (default=0 km)
   lr       lapse rate in kelvin/km       (default=6.5 K/km)

   result   air density                   (kg/m3)


  EXAMPLE:  compute pressure at a given altitude 

  p=1013.0*rhoz(z=.440,t0=290.,lr=6.5)/rhoz(t0=290.,lr=6.5)

 
  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/rhoz.pro)


ROOTS

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  roots

 PURPOSE:  find floating point index, f, such that x=interpolate(xx,f)
           where xx is a (possibly non-monotonic) table of values and 
           x is a scalor.  ROOTS returns -1 if no roots are found.

 USEAGE:   result=roots(xx,x)

 INPUT:    
  xx       a table of real numbers, need not be monotonic 
  x        a real number

 DISCUSSION:
           Though ROOTS isn't sophisticated, it is thorough.  It
           checks all the places where ff=(x-xx)/(shift(xx,-1)-xx) is
           between [0,1).  and returns the value ii+ff, where ii is
           the index for which x is bounded by xx(ii) and xx(ii+1).
           NOTE: Sparsely populated tables may not produce a
           satisfactory accuracy.
           
           

 EXAMPLE:  

;  find the roots of the equation t^3-10*t^2-200*exp(-t)+100. = 0

   t=findrng(.0,10,1000)
   xx=t^3-10*t^2-200*exp(-t)+100.
   plot,t,xx 
   f=roots(xx,0)
   oplot,interpolate(t,f),interpolate(xx,f),psym=2
   oplot,!x.crange,[0,0],color=100
   print,'     t(f)     =',interpolate(t,f)

;  find zeroes of legendre polynomial

   x=findrng(-1.,1.,10000)
   n=16 & f=legendre(n,x) & r=roots(f,0.) & print,interpolate(x,r)

 AUTHOR:   Paul Ricchiazzi                        03 Apr 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/roots.pro)


ROWCOL

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  rowcol

 PURPOSE:  compute the plot frame position of next plot

 USEAGE:   result=rowcol(ix=ix,iy=iy)

 INPUT:    

 KEYWORD INPUT:

   ix      the x position index starting from 0 on left, 
           ix<0 indicates rightmost column of plots

   iy      the y position index starting from 0 on bottom
           iy<0 indicates top row of plots

 OUTPUT:
   result  1 if plot position matches ix or iy position index,
           otherwise zero

 DISCUSSION:
   This routine is intended to simplify labeling setup for multiframe
   plots.  Use ROWCOL in IF statements to set the XTITLE and YTITLE
   as appropriate for plots in the left or right column or bottom or
   top row.  Since ROWCOL interprets a negative IX or IY as the
   rightmost or top row of plots, respectively, you don't need to
   explicitly refer to !p.multi in your plot routines when all you
   want to do is set a special value of XTITLE for the right column
   or top row of plots.

 EXAMPLE:  

           !p.multi=[0,2,3]

; execute these lines four times:

           if rowcol(ix=0) then ytitle='ylabel' else ytitle=''
           if rowcol(iy=0) then xtitle='xlabel' else xtitle=''
           plot,dist(20),xtitle=xtitle,ytitle=ytitle

 AUTHOR:   Paul Ricchiazzi                        09 Apr 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:
 nov97: now works for column major ordering

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/rowcol.pro)


SATGRID

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  satgrid

 PURPOSE:  compute data coordinates of scanning sensors deployed on 
           polar orbiting satellites

 USEAGE:   satgrid,nx,ny,alon,alat,lon0=lon0,lat0=lat0,inclin=inclin, $
            alt=alt,period=period,lres=lres,sres=sres,dmsp=dmsp, $
            descend=descend,time=time

 INPUT:    

  nx        number of samples, if nx le 1 then alon and alat
            are one dimensional vectors which specify the satellite
            ground track.  

  ny        number of lines


 KEYWORD INPUT:


  lon0      longitude of equator crossing     (degrees)
            the NOAA polar orbiters cross the equator at the same
            local time each day.  Local time is defined as 

                tloc = utc - fix(lon+7.5)/15

            For example if the ascending node crossing occurs at local
            time 14:30, or 2.5 hrs after noon, then in a given day
            lon0 takes on the values,
 
                 lon0 = indgen(24)*15 + 15*2.5

                        or for a particular longitude

                 lon0 = 15*fix(lon+7.5)/15   +   15*2.5 

  inclin    orbital inclination               (degrees)  (default=98.9127)
            0 < inclin < 180
            (this is the angle between the north pole and the the
            satellite orbital axis. [Use right hand rule to establish
            direction of orbital axis.] The default value cooresponds to
            to a sun sychronous orbit. 

  alt       altitude of orbit                 (km)       (default=853. km)

  period    period of orbit                   (hours)    (default=1.6985 hrs)

            either alt or period may be input and the other quantity is
            computed through the relation between orbital period and altitude

  dmsp      set to 1 if satellite ground resolution is held constant
            in the crosstrack direction, as it is on the DMSP satellite,

  lres      along track resolution at nadir=0 (km)       (default=1.)

  sres      cross track resolution at nadir=0 (km)       (default=1.)

            NOTE: SRES is internally limited to less than
                  .999*2*nadrlim/(nx-1), where nadrlim is the 
                  maximum nadir angle for which the earth is 
                  still in the IFOV of the sensor.

  descend   if set, choose descending node.  This affects the
            ordering of the ALON and ALAT grids.

 OUTPUT:
  alon      longitude array

  alat      latitude array

            NOTE: when facing the direction of ground track motion the
            first array index of the alat and alon arrays are filled
            from left to right.
            
  time      time offset at which a given line of data is obtained (hours)
            The offset is respect to the time at which the first line
            of data is returned.

  swath     cross track swath width in km


 DISCUSSION:
  This routine is not intended to give precise satellite coordinates,
  rather it can be used to compute illustritive grids to test other
  routines.  A circular orbit is assumed and the earth is allowed to
  rotate during the period of the orbit.  In reality, NOAA polar
  orbiters have an eccentricity of about 0.0011. This has a very
  small impact on inter pixel spacing. The ordering of alat and alon
  may need to be transposed, reversed or rotated to account for
  satellite direction of motion i.e., ascending / descending node and
  for details of how a given satellite orders its output.

 LIMITATIONS:
  Should not be used to compute satelite ground track or data grids 
  when high accuracy is required.

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  
   
;; show satellite ground track   

   map_set,0,-120,/cyl,/cont,/grid
   satgrid,0,200,alon,alat,lres=240.
   oplot,alon,alat

;; show sensor samples, color indicates array ordering (dark=>start)

   loadct,5
   color=(!d.n_colors*findgen(100)/100.) # replicate(1,600)

   satgrid,100,600,alon,alat,lres=200,sres=16.5.,swath=swath
   print,swath
   plots,alon,alat,psym=3,color=color


 AUTHOR:   Paul Ricchiazzi                        20 Dec 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/satgrid.pro)


SCONVOL

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  sconvol

 PURPOSE:  convolve a spectrum defined on an arbitrary 1-d grid
           with a response function.  

 USEAGE:   sconvol,x,y,fwhm,xx,yy,type=type,isample=isample,osample=osample

 INPUT:    

   x 
     x value 

   y 
     spectral values

   fwhm   
     filter width at half of maximum value in x units

 KEYWORD INPUT:
   type  
     filter type 
     0 = square      (default)
     1 = triangular

   isample
     number of pre-convolution samples taken within a given fwhm interval
     (default = 10) 

   osample
     number of output samples provided within a given fwhm interval
     (default = 1)

 OUTPUT:

   xx
      x values at sample points, output values will be at multiples of
      of OSAMPLE*FWHM starting at min(XX)+.5*FWHM

   yy
      response values at xx

 DISCUSSION:

 EXAMPLE: degrade MODTRAN spectral transmission to LOWTRAN resolution
 
      modtrns,buf,/noplot
      w=reform(buf(0,*))
      t=w & t(*)=1.
      for i=1,11 do t=t*reform(buf(i,*))
      sconvol,w,t,20,ww,tt,type=0
      plot,10000./ww,tt,xrange=[.25,1]


; show oxygen A line at 1 nm resolution

      sconvol,10000/w,t,.001,w1,t1
      plot,10000/w,t,xrange=[.755,.77]
      oplot,w1,t1,psym=10

; and at 20 cm-1 resolution
      sconvol,w,t,20,w20,t20
      plot,10000./w,t,xrange=[.755,.77]
      oplot,10000./w20,t20,psym=10


 AUTHOR:   Paul Ricchiazzi                        20 Nov 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/sconvol.pro)


SIND

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       SIND

 PURPOSE:
       Return the sine of an angle specified in degrees rather than radians.

 CALLING SEQUENCE:
       x = sind(deg)

 INPUTS:
       angle   angle in degrees

 OPTIONAL INPUTS:

 OUTPUTS:
       Sine of angle returned.

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  12/07/93

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/sind.pro)


SLOPE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:         slope

 PURPOSE:      compute a two point fitting function, y=f(x)

 USEAGE:       slope,a,b
 
 INPUTS:       none

 KEYWORDS:     none

 OUTPUTS:      
   a           fit coefficients
   b           fit coefficients

 PROCEDURE:    use the LMB to specify two points on the plot.  
               The form of the fitting function depends on whether the plot 
               has log axis in either the x or y directions, as follows,

                       x          y
                      linear - linear           y=a+b*x
                      log    - linear           y=a+b*log(x)
                      linear -  log             y=a*exp(b*x)
                      log    -  log             y=a*x^b

               After two points are chosen SLOPE will show the form of the
               fitting function and the value of a and b in an XMESSAGE
               widget.  At this point the user can exit the procedure by
               hitting any of the mouse buttons.  The XMESSAGE widget is not
               not destroyed if the RMB is used to exit SLOPE.
                

  author:  Paul Ricchiazzi                            nov93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

 REVISIONS:    

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/slope.pro)


SOLVE2

[Previous Routine] [Next Routine] [List of Routines]
 routine    solve2
 purpose    solve two simultaneous non-linear equations for variables
            x and y.  In The non-linear equations are formally
            expressed as,
                           fu(x,y) = u
                           fv(x,y) = v
 input:
   fu       name of first non-linear function (string)
   fv       name of second non-linear function (string)
   u        rhs value of first non-linear function (scalor)
   v        rhs value of second non-linear function (scalor)
   x        first guess value for variable x (scalor)
   y        first guess value for variable y (scalor)
   xrange   reasonable range of x (i.e.,  [xmin, xmax] )
   yrange   reasonable range of y (i.e.,  [ymin, ymax] )

 keyword input
   view     plot convergence trace and print diagnostics
   tol      convergence criterium (see below).
   maxit    maximum number of iterations

            Iteration terminates when one of the following 
            conditions is true:

            1. number of iterations exceeds MAXIT

            2. x or y is pegged at their extreme values, 
               given by XRANGE or YRANGE.

            3. abs{fu(x,y)-u} lt TOL * u  and 
               abs{fv(x,y)-v} lt TOL * v
 
 output:
   x        converged value of x
   y        converged value of y

 
 PROCEDURE:  the functions fu and fv should return both the values
             of the non-linear function and their derivatives with respect
             to x and y.  SOLVE2 assumes that these quantities are actually
             implemented as procedures, so that all three values can be
             obtained simply.  The argument list of the fu or fv procedures
             should be set up as follows,

             pro fu,x,y,uu,dudx,dudy
               and
             pro fv,x,y,vv,dvdx,dvdy

             where uu    function value of fu at x,y
                   dudx  partial derivative of fu with respect to x
                   dudy  partial derivative of fu with respect to y
                   vv    function value of fv at x,y
                   dvdx  partial derivative of fv with respect to x
                   dvdy  partial derivative of fv with respect to y

             the equations are solved by newton-raphson iteration
             

  author:  Paul Ricchiazzi                            22mar93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/solve2.pro)


SPHASE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  sphase,polar,g,type=type

 PURPOSE:  compute sphase greenstein phase function

 USEAGE:   sphase,polar,g

 INPUT:    
   mu      cosine of polar angle (mu=1 in forward direction)
   g       asymmetry factor 
 
 keywords
   rayleigh
           returns rayleigh phase function and ignors value of g
  
 EXAMPLE:  compute fraction of all single scattered radiation 
           within a disk which subtends one degree of the of 
           the forward direction.

           shadow,.8,30,.01,type="henyey"

 AUTHOR:   Paul Ricchiazzi                        22 Apr 98
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/sphase.pro)


SPRITE

[Previous Routine] [Next Routine] [List of Routines]
ROUTINE:      sprite

PURPOSE:      
    interactive display of multi parameter correspondences.  Points
    corresponding to a single independent index variable is hilighted
    by a small "sprite" symbol on several plot frames simultaneously. 
    The sprite position is controlled by the master index, which can
    be incremented/decremented via the mouse.
                

USEAGE:
    plot,x1,y1 & sprite,x1,y1,/init
    plot,x2,y2 & sprite,x2,y2
    plot,x3,y3 & sprite,x3,y3
      ...
    sprite
               

INPUT:

  xvec
    x vector for current plot. Only required when accumulating the
    DATA and CONTROL info after each plot. If xvec and yvec are not
    set, SPRITE executes in interactive mode

  yvec 
    y vector for current plot. Only required when accumulating the
    DATA and CONTROL info after each plot.


KEYWORD INPUT:

  init
    Set the keyword to reinitialize SPRITE for a new set of plots.

  psym
    symbol used to indicate sprite

  color
    color index used to draw sprite

  xtitle
    title of x variable for current plot, used to label quantity in
    print out widget.

  ytitle
    title of y variable for current plot, used to label quantity in
    print out widget.


 DISCUSSION:   SPRITE operates in two modes:

    1. in accumulation mode SPRITE is called immediately after each
    plot is written to the screen.  Multiple plot frames can be
    accumulated because SPITE stores all the data and plot geometry
    information in an internal common block, SPRITE_BLK, for latter
    use. 
    
    NOTE:   SPRITE ignors the values of PSYM, COLOR and
            LABELS while in accumulation mode.
    
    2. In interactive mode a sprite control window is created with
    several mouse-sensitive areas defined.  Pressing a mouse button
    in one of these areas causes the following actions:
    
    control area    action
    ------------    ------
    QUIT            quit 
      <<            move sprite backward taking large steps
      <             move sprite backward one step
      >             move sprite forward one step
      >>            move sprite forward taking large steps
    
    Using the MMB in the "<", ">" areas causes the sprite to pause
    between steps and to update the print-out widget after each step.
    Otherwise, if the LMB or RMB is used, the print-out widget is
    updated only after the button is released.


 SIDE EFFECTS: 
    Draws a sprite on each of the plot frames

    While in operations the XOR graphics mode is set.

    If psym is not set, user symbol, psym=8, is redefined to a filled
    diamond

 COMMON BLOCKS:
    sprite_blk
  
 EXAMPLE:

; use sprite to show solar flux values :

       !p.multi=0
       solar,wv,f
       xtitle='wavenumber' & ytitle='W/m2' & title='irradiance'
       plot,wv,f,xtitle=xtitle,ytitle=ytitle,title=title
       sprite,wv,f,xtitle=xtitle,ytitle=title,/init
       sprite,color=150

; try a four frame plot 
 
       !p.multi=[0,2,2]
       time=findgen(100)*10 & tlab='Time (hours)'
       lon=-90+10*cos(!dtor*time)+randf(100,3)
       lat=30+5*sin(!dtor*time)+randf(100,3)
       alt=5000*sin(time*!pi/999)+2000*randf(100,3.3)
       ch1=10.+randf(100,3)
       ch2=25.+randf(100,2.5)^3
       plot,lon,lat,/yno,xtit='Longitude',ytit='Latitude',title='Flight path'
       sprite,lon,lat,xtit='Longitude',ytit='Latitude',/init     ; initialize 
       plot,time,alt,xtitle=tlab,title='Altitude',ytitle='meters'
       sprite,time,alt,xtitle=tlab,ytitle='Altitude'
       plot,time,ch1,xtitle=tlab,title='Ch1 flux'
       sprite,time,ch1,ytitle='Ch1 flux'
       plot,time,ch2,xtitle=tlab,title='Ch2 flux'
       sprite,time,ch2,ytitle='Ch2 flux'
       loadct,5
       sprite,color=150

; You can also have two sprites in one plot frame:

       !p.multi=[0,1,2]
       w8x11
       y2=randf(10000,3) & x1=indgen(10000)
       y1=y2+.5*randf(10000,2)
       !p.font=-1
       plot,x1,y1  ,xtitle='time',ytitle='ch1 and ch2 flux'
       sprite,x1,y1,xtitle='time',ytitle='ch1 flux',/init      ; initialize 
       oplot,x1,y2,li=3
       sprite,x1,y2,ytitle='ch2 flux'
       sprite,color=150

 
 AUTHOR:   Paul Ricchiazzi                       2 March 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/sprite.pro)


STEPIND

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  stepind

 PURPOSE:  step through a sequence of nested indicies

 USEAGE:   result=stepind,ic,n1,i1,n2,i2,n3,i3,n4,i4,n5,i5,n6,i6

 INPUT:    

   ic      one dimensional index.  incremented or decrimated by
           LMB or MMB, respectively.  if the starting value of ic
           ic is -1,  no delay occurs before the plot

   n1      number of elements in first dimension
   i1      index for first dimension
   n2      number of elements in second dimension
   i2      index for second dimension

   etc

 KEYWORD INPUT

   nowait  STEPIND returns immediately if button is in down state

   step    a named variable, if set to non-zero value STEP causes
           STEPIND to return immediately.  The initial value of STEP
           determines wheather the first call to STEPIND will return
           incremented indicies (STEP>0) or decremented indicies (step<0)
           After the STEPIND where loop is started the sign of STEP
           is toggled by the left or middle mouse buttons.
   
 OUTPUT:
   result  logical flag, 0 if RMB is pressed, 1 otherwise

  
 EXAMPLE:  

  ic=-1 & step=1                & x=5*(findgen(360)-180)*!dtor 
  s=exp(-(x/(360*!dtor))^2)     & phs=10.*!dtor

 while stepind(ic,36) do plot,x,s*sin(x+ic*phs),title=string(ic*phs)

 while stepind(ic,36,/nowait) do plot,x,s*sin(x+ic*phs),title=string(ic*phs)

 while stepind(ic,36,step=step) do plot,x,s*sin(x+ic*phs),title=string(ic*phs)
    

 AUTHOR:   Paul Ricchiazzi                        22 Sep 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/stepind.pro)


STEP_CT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:       step_ct

 USEAGE:        step_ct, range, inc, cs, nbotclr=nbotclr
                step_ct, /off

 PURPOSE:       Discreetizes color scale at given numerical intervals.
                NOTE:  the rgb color value of the top color scale index is
                       not changed.  

 INPUT:   

     range      array or vector which specifies range of physical values, 
                e.g., [amin,amax]

     inc        number scale increment

     cs         a floating point number between -1.0 to +1.0 that
                translates the color table a fraction of a color step
                higher (cs > 1) or lower (cs < -1).  It has its most
                noticeable effect when the number of steps is small,
                because in this case a single step is usually a
                significant change in color value.  (default = 0)

    nbotclr     starting color index

     off        restore original unquantized color table, 
                no other input is required when this keyword is set

 EXAMPLE
                loadct,0
                tvlct,r,g,b,/get
                plot,r,xmargin=[10,20],/yst=1
                color_key,range=[0,255],inc=20
                range=[0,255]
                inc=20
                step_ct,range,inc
                tvlct,r,g,b,/get
                oplot,r,li=3


 AUTHOR:        Paul Ricchiazzi    oct92 
                Earth Space Research Group
                UCSB
 REVISIONS:
 21sep93: fixed case of range spanning zero (see shiftup)

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/step_ct.pro)


STRIP_FN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       STRIP_FN 

 PURPOSE:
       Return a filename stripped of all directory information.

 CALLING SEQUENCE:
       result = strip_fn(filename)

 INPUTS:
       filename      filename to be stripped.  Can be scalar or vector.

 OPTIONAL INPUTS:

 OUTPUTS:
       stripped filename.  Same type (vector/scalar) as input filename.

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     8/12/93

 MODIFICATION HISTORY:
     JAH  8/13/93   Added filename vector capability.

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/strip_fn.pro)


STRMATCH

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    strmatch

 PURPOSE:    check for string match to a wild card specification

 USEAGE:     result=strmatch(str,spec)

 INPUT:
   str       string
   spec      wild card specification

 OUTPUT:     1 if STR matches SPEC
             0 if STR does not match SPEC

 LIMITATIONS:
             Currently the only wild card character is asterisk, "*"
             which matches 1 or more arbitrary characters.

  
 EXAMPLE:    
             print,strmatch('string','st*ng')      ;  => 1
             print,strmatch('string','*st*ng')     ;  => 0
             print,strmatch('string','*t*ng')      ;  => 1
             print,strmatch('string','st*ng*')     ;  => 0
             print,strmatch('string','st*n*')      ;  => 1

  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/strmatch.pro)


STRWHERE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  strwhere

 PURPOSE:  a "where" operator for strings matching a set of string 
           wild cards

 USEAGE:   result=strwhere(starr,wildcard)

 INPUT:    
   starr   an array of strings                   

 wildcard  wild card specifier composed of regular and special
           characters.  The special characters are  asterisk '*'
           and vertical bar '|'.  The asterisk matches any number of
           characters the vertical bar indicates an "or" operation
           between different wild card specifications.

 KEYWORD INPUT:

   orchar  character used to indicate "or" wildcard operation.
           (default = '|')

 OUTPUT:
   result  an index array such that starr(result) = those elements of
           STARR that match the wild card specification in WILDCARD
   

 EXAMPLE:  

  f=findfile(/home/paul/arm/arese/bsrn/sgpbsrnC1.a1.*.cdf)
  clrdays='*1018*|*1022*|*1030*'
  print,f(strwhere(f,clrdays))

 AUTHOR:   Paul Ricchiazzi                        14 Jan 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/strwhere.pro)


SUNGLINT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:	sunglint

 PURPOSE:	compute lat-lon of point on earths surface which will
               reflect sunlight to satellite observation point by 
               purely specular reflection.

 USEAGE:	sunglint,doy,time,lat,lon,alt,glat,glon

 INPUT:

   doy		day of year              (scalor)
   time	time UTC (hours)         (scalor)
   lat         satellite latitude       (scalor)
   lon         satellite longitude      (scalor)
   alt         satellite altitude       (scalor)

 OUTPUT

   glat        sunglint latitude
   glon        sunglint longitude
   gnadir      sunglint nadir angle
   gaz         sunglint azimuth
               
               if satellite is on the night side 
               glat and glon are returned as 1000,1000
 
   if parameters GLAT, GLON, GNADIR and GAZ are left off the argument
   list then SUNGLINT prints these parameters to the terminal


 KEYWORD INPUT:

  
 EXAMPLE:	

 sunglint,129,21.5,25,-120,800,glat,glon,gnadir,gaz
 print,f='(4f10.2)',glat,glon,gnadir,gaz

 sunglint,80,12,90.0,0,1000              ; sunlat =0 sunlon=0
 sunglint,80,12,90.0,0,10000             ;   note how glat approaches
 sunglint,80,12,90.0,0,100000            ;   45 at alt is increased
 sunglint,80,12,90.0,0,1000000           ; 


 REVISIONS:

  author:  Paul Ricchiazzi                           dec 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/sunglint.pro)


SUPERPIX

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:           superpix

 USEAGE:            superpix, a, binsz, abin, sbin
                    superpix, a, binsz, abin, sbib, /align, /compare

 PURPOSE:           compute super pixel average and standard deviation
                    of a scene

 INPUT:
         a          image array

         binsz      A scalar specifying the number of horizontal and 
                    vertical sub-pixels in one super pixel. 
                    BINSZ must be an odd integer.

         align      If set, output arrays are REBINed back up to the 
                    original size and output array cell centers are aligned
                    with input array cell centers.

         compare    if set, compare A and ABIN with the FLICK procedure

 OUTPUT:
         abin       mean value of superpixel at superpixel cell centers

         sbin       standard deviation of superpixel at superpixel
                    cell centers.

 AUTHOR:            Paul Ricchiazzi    oct92 
                    Earth Space Research Group, UCSB

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/superpix.pro)


SWATH

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  swath

 PURPOSE:  plot raw data (not on a regular lat-lon grid) from a satellite
           pass on a predifined ploting grid (usually setup by map_set)

 USEAGE:   swath,image,lon,lat,thick=thick,nlevels=nlevels, $
           colors=colors,outline=outline

 INPUT:    

  image
    two dimensional satellite data field.  the first index 
    corresponds to cross-track sample number and the second 
    to the along-track line number.

  lon
    longitude array, same size as image

  lat
    latitude array, same size as image

 KEYWORD INPUT:
  thick
    thickness of lines used to fill lines in swath
    (The default is 3 for "X" and 10 for "ps")

  colors
   discreet set of colors used for each level in LEVELS.  

  nlevels
    number of contour level values (if not set continuous colors are used)

  range
    physical range of image (2 element vector)

  outline
    color index used to draw swath outline. If not set, a swath
    outline is not drawn. 

 KEYWORD OUTPUT:
  colors 
    a vector of color indicies which can be used as input to
    color_key. This is required to coordinate the color key with the
    discreet colors drawn by SWATH. It is not required when nlevels
    is not set.  COLORS is returned if the input value of COLORS is a
    named variable with 0 or 1 elements.

 DISCUSSION:
    Each individual satellite line is drawn as a separate call
    to PLOTS.  Hence, there may be gaps between lines.  This
    can be controlled by adjusting the thickness of the drawn
    lines.  If the the printer has greater resolution than the
    screen or if the number of lines is not large, you may have to
    increase THICK to avoid getting gaps between lines on your
    hardcopy.

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  

 y=findrng(-8500,8500,400)     ; satelite data coordinates (400 lines)
 x=findrng(-1012,1012,100)     ;                           (100 samples)
 gengrid,x,y
 incl=98                       ; orbital inclination
 az=atan(x,y)/!dtor            ; azimuth (clockwise around track direction)
 az=(az+90-incl+360) mod 360
 rng=sqrt(x^2+y^2)             ; range   (from equator crossing)
 compass,0,0,rng,az,alat,alon,/to_latlon 
 range=[0,1]
 colors=0

 map_set,0,0,/orth,pos=boxpos(/asp)
 for i=0,5 do swath,abs(sin(!pi*x/2000)*sin(!pi*y/2000)), $
     alon+25*i-50,alat,nlev=11,colors=colors,/outline
 map_continents
 map_grid
 color_key,range=range,colors=colors
  
 map_set,0,0,/cyl,pos=boxpos(/asp)
 for i=0,5 do swath,abs(sin(!pi*x/2000)*sin(!pi*y/2000)), $
     alon+30*i-60,alat,nlev=11,colors=colors,outline=255
 map_continents
 map_grid
 color_key,range=range,colors=colors
 

 AUTHOR:   Paul Ricchiazzi                        20 Dec 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/swath.pro)


TABLE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    table

 PURPOSE:    print a table of vectors in nicely formatted columns

 USEAGE:     table,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,f=f

 INPUT:      
  p1,p2,...  a set of vector quantities to print. all vectors must
             be of the same length

 KEYWORD INPUT:
   f         format specification string, E.G.  'f10.3,e11.2'

             NOTE:     don't provide a specification for the integer
             subscript which appears in the first column. TABLE puts
             it in automatically. Also, the format string need not
             have opening and closing parenthesis, but its ok to put
             them in.

   index     if set, the array indicies of the first parameter, p1,
             are printed.  This only has effect when p1 has dimension
             greater than two.  Indicies for array dimensions greater
             than 5 are not printed.


 EXAMPLE:

    x=sqrt(findgen(20)+23)
    y=sin(.1*x)

    table,x,y                                            ; 
    table,x,y,x+y,x-y,x*y,(x+y)*(x-y),x/y,f='7f10.3'
    table,rebin(x,4,5),y,/index
    table,rebin(x,5,4),y,/index
    table,rebin(x,5,2,2),y,/index

  author:  Paul Ricchiazzi                            may94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/table.pro)


TAND

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       TAND

 PURPOSE:
       Return the tangent of an angle specified in degrees rather than radians.

 CALLING SEQUENCE:
       x = tand(deg)

 INPUTS:
       angle   angle in degrees

 OPTIONAL INPUTS:

 OUTPUTS:
       Tangent of angle returned.

 PROCEDURE

 COMMON BLOCKS:
       None.

 NOTES

 REFERENCES
 
 AUTHOR and DATE:
     Jeff Hicke     Earth Space Research Group, UCSB  12/07/93

 MODIFICATION HISTORY:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/tand.pro)


TDEWP

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:	tdewp

 PURPOSE:	compute dew point temperature from ambient temperature and
		relative humidity.  The dew point is the temperature to
		which air must be cooled at constant pressure and
		constant mixing ratio to reach 100% saturation with
		respect to a plane water surface

 USEAGE:	result=tdewp(t,p,rh)

 INPUT:      
   t		ambient temperature	       (celsius)
   p           ambient pressure               (mb)
   rh		rh relative humidity	       (0-100%)
               

 OUTPUT:
   result	dew point temperature (celsius)

 METHOD:

   From thermodynamics we know that the saturated water vapor pressure
   is just a function of the temperature.  Lets call that function 
   VPS(T).  Then the water vapor mixing ratio, which is the ratio of
   the mass of vapor to the mass of dry air, is

   1.	    r = (Mw/Ma) .01*rh VPS(T)/(P - VPS(T))

   where rh is the relative humidity (this equation can be taken as
   the definition of rh) and k is Boltzman's constant and Mw and Ma
   are the molecular masses of water and air.  By the definition of
   dew point temperature, the water vapor density in this
   non-saturated situation can also be expressed by,

   2.	    r = (Mw/Ma) VPS(Td)/(P - VPS(Td))

   Now, to solve for Td in terms of T and rh we set the RHS of eqn 1
   equal to the RHS of eqn 2.	

   So the dew point is found by solving

   3.	      VPS(Td)/(1.-VPS(Td)/P)=.01*rh*VPS(T)/(1.-VPS(T)/P)

   To simplify matters we use an analytic approximation, 

   4.        VPS(t) = c0*exp(c1*t/(t+c2)) (Tetans, 1930).  


 References:

 equation relating saturated vapor pressure to temperature from:
 Tetans, O. 1930. Uber emige meteorologische Begriffe. Z. Geophys. 6:297-309

 EXAMPLE:

  print,'the dewpoint temperature is',tdewp(29,44)
  15.4947

; plot contours dew point temperture for a range of temperature
; and relative humidity

  t=findgen(100)
  rh=1+findgen(100)
  gengrid,t,rh
  td=tdewp(t,1013,rh)
  contour,td,t,rh,xtitle='temperature (C)',ytitle='relative humidity',$
     levels=contlev(td),/follow

  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/tdewp.pro)


TERM_SIZE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  term_size

 PURPOSE:  find the number columns and number of lines in the idl terminal

 USEAGE:   term_size,xs,ys

 INPUT:    

 KEYWORD INPUT:

 OUTPUT:
  xs       number of columns
  ys       number of lines

 DISCUSSION:
  uses the unix command "resize" to find the terminal size

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  
           term_size,xs,ys & print,xs,ys

 AUTHOR:   Paul Ricchiazzi                        04 Nov 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/term_size.pro)


TEXTCLOSE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	TEXTCLOSE                   

 PURPOSE:
	procedure to close file for text output as specifed
	by the (non-standard) system variable !TEXTOUT. 

 CALLING SEQUENCE:
	textclose, [ TEXTOUT = ]

 KEYWORDS:
	textout - Indicates output device that was used by
		TEXTOPEN

 SIDE EFFECTS:
	if !textout is not equal to 5 and the textunit is
	opened.   Then unit !textunit is closed and released

 HISTORY:
	D. Lindler  Dec. 1986  (Replaces PRTOPEN)
	Test if TEXTOUT is a scalar string   W. Landsman   August 1993

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/textclose.pro)


TEXTOPEN

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	TEXTOPEN
 PURPOSE
	Procedure to open file for text output.   The type of output 
	device (disk file or terminal screen) is specified by the 
	TEXTOUT keyword or the (nonstandard) system variable !TEXTOUT.

 CALLING SEQUENCE:
	textopen, program, [ TEXTOUT = ]

 INPUTS:
	program - scalar string giving name of program calling textopen

 OPTIONAL INPUT KEYWORDS:
	TEXTOUT - Integer scalar (0-6) specifying output file/device to be 
		opened (see below) or scalar string giving name of output file.
		If TEXTOUT is not supplied, then the (non-standard) system 
		variable !TEXTOUT is used.

 SIDE EFFECTS:
	The following dev/file is opened for output.

		textout=0 	Nowhere
		textout=1	TERMINAL using /more option
		textout=2	TERMINAL without /more option
		textout=3	.prt
		textout=4	laser.tmp
		textout=5      user must open file
		textout = filename (default extension of .prt)

	The unit it is opened to is obtained with the procedure GET_LUN
	unless !TEXTOUT=5.  The unit number is placed in system variable 
	!TEXTUNIT.  For !TEXTOUT=5 the user must set !TEXTUNIT to the 
	appropriate unit number.

 NOTES:
	Note that TEXTOUT = 1 or TEXTOUT = 2 will open a unit to the terminal,
	SYS$OUTPUT (VMS) or /dev/tty (Unix).     However, this terminal 
	output will *not* appear in an IDL JOURNAL session, unlike text
	printed with the PRINT command.	

 NON-STANDARD SYSTEM VARIABLES:
	DEFSYSV,'!TEXTOUT',1
	DEFSYSV,'!TEXTUNIT',0

 HISTORY:
	D. Lindler  Dec. 1986  
	Keyword textout added, J. Isensee, July, 1990
	Made transportable, D. Neill, April, 1991
	Trim input PROGRAM string W. Landsman  Feb 1993
	Don't modify TEXTOUT value   W. Landsman   Aug 1993

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/textopen.pro)


TEXT_BOX

[Previous Routine] [Next Routine] [List of Routines]
 Name        : text_box

 Purpose     : Writes a text message within a box in a graphics window.

 Description:  This procedure writes a short text message within a box-shaped
               area in a graphics window.  The message may be split at word
               boundaries into several lines, and the character size and
               orientation may be adjusted for the text to fit within the box.

 Useage:       text_box,text,pos=pos,color=color,$
                    justify=justify,vert_space=vert_space

 Inputs      
 TEXT          ASCII text string containing the message.

 keywords
  pos          4 element vector specifying the box position and size
               pos(0),pos(1) specify the lower left corner coordinate
               pos(2),pos(3) specify the upper right corner coordinate
               data window normalized coordinates are use

   fg_color    color of box and legend titles (default=!P.COLOR)

   bg_color    background color. Setting BG_COLOR erases the area 
               covered by the text box (filling it with color BG_COLOR)
               prior to writing the text.  If both BG_COLOR and !p.color
               are zero then the background color is reset to 255 to
               gaurantee a readability.
               
  right        if set, right justify text
  center       if set, center the text

  vert_space   vertical spacing of lines in units of character height 
               (default = 1.5)


  author:  Paul Ricchiazzi                            7Jul93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/text_box.pro)


THICK

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    thick

 PURPOSE:    thicken lines and characters on postscript output.

 USEAGE:     thick,thck,cthck

 INPUT:      thck        the thickening factor.
                         if not set all graphics system variables
                         related to line thickness are set to 1

             cthck       character thickening factor, if CTHCK is not
                         not set or equal to zero then it defaults to 
                         1+.5*(thck-1) if not set.


 OUTPUT:     none

 SIDE EFFECTS:  changes the values of system varaibles as follows

            !p.charthick=cthck

            !p.thick=thck
            !x.thick=thck
            !y.thick=thck


 PROCEDURE:  a thickening factor of 3 is a good value to use for
             plots on the Phaser color printer.  and 5 is good for
             very bold lines.  2 is good enough for the low resolution
             printers
  
  author:  Paul Ricchiazzi                            feb94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/thick.pro)


TIMESTAMP

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE      timestamp
 PURPOSE      print the current day and time in the lower right corner of
              the device window
 
 USEAGE       timestamp
              timestamp,label,charsize=charsize
 INPUT:
    label     optional label string. If LABEL not supplied the current
              working directory is used

 KEYWORD INPUT:
    charsize  character size multiplier (default=0.5)
    right     put timestamp at lower right corner of the page
              (default is lower left corner)

 OUTPUT:      none

 AUTHOR:              Paul Ricchiazzi    oct92 
                      Earth Space Research Group, UCSB

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/timestamp.pro)


TOGGLE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:      toggle

 USEAGE For opening a postscript file:

       toggle,color=color,landscape=landscape,portrait=portrait, $
              legal=legal,queue=queue,print=print,filename=filename, $
              eps=eps,xoffset=xoffset,yoffset=yoffset,xsize=xsize, $
              ysize=ysize,_extra=_extra

 USEAGE For closing a postscript file:

       toggle,print=print, queue=queue

 PURPOSE:      toggles IDL graphics output between X-window and a postscript
               output file.

 OPTIONAL INPUTS (keyword parameters):

;;; these keywords recognized when opening a postscript file:
 
   COLOR
     Enable color plotting (output to Tek Phaser color printer)

   LANDSCAPE   
     Horizontal plotting format (i.e., long side of paper is horizontal)

   PORTRAIT
     Vertical plotting format (default)

   LEGAL       
     8.5 x 14 inch page size 
     (8.5 x 11 is default)

   EPS
     If set, an encapsulated postscript file is produced.  Many word
     processing and typesetting programs provide facilities to
     include encapsulated PostScript output within documents (for
     example groff's PSPIC command).  If the XSIZE and YSIZE
     parameters are not set the value of EPS is interpreted as an
     aspect ratio of the graphic.  
     
     NOTE: Using the SET_CHARSIZE procedure to set the character size
           makes it easier to use an x-window preview to predict the
           appearance of PS output.

   XSIZE, YSIZE
     Controls the size of the plotting area (inches).  These
     parameters can be used to set the size of an EPS graphic.  If
     XSIZE and YSIZE are not set the value of of EPS is used to
     compute the aspect ratio.  In that case, the internal values of
     XSIZE and YSIZE are set to 8 and 8/EPS inches, respectively.
     Setting XSIZE and YSIZE explicitly is useful for controlling the
     appearance of different linestyles.  For example, when linestyle
     2 is used to produce dashed lines, a 4"x4" plot size will
     produce half as many dashes as a 8"x8" plot size.

   XOFFSET,YOFFSET
     In PORTRAIT mode XOFFSET,YOFFSET is the coordinate position of
     the lower left corner of the plotting area (inches) with respect
     to the lower left corner of the paper.  In LANDSCAPE mode the
     whole coordinate system is turned to 90 degrees counter-
     clockwise, so that XOFFSET is the bottom margin and YOFFSET is
     the distance from the lower-left corner of the plotting area to
     the RIGHT (yup, that's RIGHT) edge of the page.

   FILENAME
     name of postscript file (default = plot.ps or plotc.ps). 

;;; these keywords recognized when closing a postscript file:

   PRINT
     PRINT=1 => submit to default printer ( setenv PRINTER ????)
     otherwise if PRINT is a string variable the job will be spooled
     to the named print queue (e.g., PRINT='tree'). 

   QUEUE
     if set, print queue is selected from a pop-up menu. 

 PROCEDURE:
     The first call to TOGGLE (and all odd number calls) changes the
     output device from X-window to a Postscript output file.  If the
     output file name is not specified on the command line the
     default file name will be plot.ps for the laser printers, or
     plotc.ps for the TEK Phaser color printer.
     
     The next call (and all even number calls) switches back to the
     X-window and closes the plot file.  If the keyword PRINT is set
     the plotfile will be submitted to one of the ICESS print queues.
     
     NOTE: Only one postscript file can be open at any given time

 SIDE EFFECTS: 
     In order to maintain a font size which keeps the same
     relation to the screen size, the global variable
     !p.charsize is changed when switching to and from
     postscript mode, as follows,
     
     When toggleing to PS !p.charsize --> !p.charsize/fac
     When toggleing to X  !p.charsize --> !p.charsize*fac
     
                 [!d.x_ch_size]    [!d.x_vsize  ]
     where fac=  [------------]    [----------- ]
                 [!d.x_vsize  ]    [!d.x_ch_size]
                               PS                X 
     
     Thus, to ensure that plotted character strings scale
     properly in postscript mode, specify all character
     sizes as as multiples of !p.charsize.

 EXAMPLE:  View the IDL dist function and then make a hardcopy:
     
      d=dist(200)
      loadct,5
      tvscl,d                    ; view the plot on X-windows
      toggle,/color,/landscape   ; redirect output to plotc.ps
      tvscl,d                    ; write plot onto plotc.ps
      toggle,/print              ; resume output to X-windows
                                 ; submit plot job to default printer
      toggle,/color,/land
      tvscl,d
      toggle,print='term'        ; submit plot "term" print queue
               

 BUGS:  EPS option does not work in LANDSCAPE format.  Looks like a 
        a problem in IDL's DEVICE proceedure.
   


  author:  Paul Ricchiazzi                            1jun92
           Institute for Computational Earth System Science
           University of California, Santa Barbara
 

 NOTE: you can check for the currently defined print queues in /etc/printcap

 REVISIONS:
  feb93: added PRINT keyword
  feb93: set yoffset=10.5 in landscape mode
  feb93: added FILENAME keyword
  mar93: added bits=8 in black and white mode
  mar96: modify !p.charsize to compensate for larger ps font size
  mar96: send output to print queue tree on eos
  sep96: added EPS,XSIZE and YSIZE keywords
  dec96: make PORTRAIT format standard for color plots

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/toggle.pro)


TRACE

[Previous Routine] [Next Routine] [List of Routines]
 NAME:		TRACE

 PURPOSE:	Define a path through a plot or image using the image display 
               system and the cursor/mouse.  TRACE can be used either to 
               obtain the vector of x and y vertices of a path in data 
               coordinates or, when used with TVIM, the array of image 
               indecies of all points along the path or inside the defined
               polygon.

 CATEGORY:	Image processing.

 CALLING SEQUENCE:
	trace,xv,yv,ii,retore=retore,silent=silent,region=region,dt=dt,
                  color=color

 INPUTS:         none

 KEYWORD INPUT PARAMETERS:

	RESTORE   if set, originaly displayed image is restored to its
		  original state on completion. 

       SILENT    If set no intructional printout is issued at the 
                 beginning of execution

       DT        repitition time interval for adding or removing nodes
                 when the mouse button is held down

       REGION    keyword REGION is set II contains indecies of all points
                 within the polygon defined by XV and YV

       COLOR     color to shade polygonal region, 
                 works only when REGION is set and RESTORE is not set

 OUTPUTS:

       XV    Vector of x vertices of traced path in data coordinates

       YV    Vector of y vertices of traced path in data coordinates

       ii    subscript vector of all pixels along defined path.  This works
             on an image displayed by TVIM as long as you don't define
             an XRANGE and YRANGE in the TVIM call.

             if keyword REGION is set II contains indecies of all points
             within the polygon defined by XV and YV


 COMMON BLOCKS:
	None.

 SIDE EFFECTS:
	Display is changed if RESTORE is not set.

 RESTRICTIONS:
       1. Only works for interactive, pixel oriented devices with a
          cursor and an exclusive or writing mode.

       2. A path may have at most 1000 vertices.  If this is not enough
          edit the line setting MAXPNTS.

       3. Only works with images displayed by TVIM

 PROCEDURE:
       This procedure is intended to be used with TVIM.  The original
       TVIM image should be displayed without the XRANGE and YRANGE
       parameters set, because in this case the x and y axis of the
       TVIM plot represents the actual image or array coordinates of
       the imaged quantity.  TRACE uses these values to compute the
       array indices either along a transect or within a specified
       polygonal region.

       The exclusive-or drawing mode is used to allow drawing and
       erasing objects over the original object.

       The operator marks the vertices of the path, either by
       dragging the mouse with the left button depressed or by
       marking individual points along the path by clicking the
       left mouse button, or with a combination of both.

       The center button removes the most recently drawn points.

       Press the right mouse button when finished.  On exit gaps in the 
       traced path are filled by interpolation

 EXAMPLE
       !p.multi=[0,1,2]
       d=dist(300,100)
       tvim,d
       trace,xv,yv,ii           ; draw a circle inside the image with the 
                                ; the left mouse button pressed down
       polyfill,xv,yv,color=100 ; shade the selected region
       oplot,xv,yv,psym=-1      ; highlight the border of the region
       plot,d(ii),psym=-1       ; plot a transect of the path


; blowup a given region and show it under the original image

       loadct,5
       !p.multi=[0,1,2]
       a=randata(200,200,s=4)
       rng=[min(a,max=amx),amx]              ; save range for use in blowup
       tvim,a,/scale,range=rng
       trace,xv,yv,ii,/region
       xv=[xv,xv(0)] & yv=[yv,yv(0)]         
       oplot,xv,yv                           ; show border of blowup region
       xrng=[min(xv,max=xmx),xmx]            ; save xrng and yrng for blowup
       yrng=[min(yv,max=ymx),ymx]
       b=fltarr(200,200)
       b(ii)=a(ii)                           ; show only the selected region
       b=b(xrng(0):xrng(1),yrng(0):yrng(1))
       tvim,b,xrange=xrng,yrange=yrng,range=rng,/scale
       oplot,xv,yv                           ; show border of blowup region


 Adapted from DEFROI by : Paul Ricchiazzi    oct92 
                          Earth Space Research Group, UCSB

 REVISIONS
 29oct92: if no points are selected return -1
 11nov92: allow input parameter AA to be 2 element vector 
 26apr93: massive simplifications to make TRACE easier to use

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/trace.pro)


TRI_SURF

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
	TRI_SURF

 PURPOSE:
	This function Interpolates a regularly or irregularly gridded
	set of points with a C1 smooth quintic surface.

 CATEGORY:
	Mathematical functions, Interpolation, Surface Fitting

 CALLING SEQUENCE:
	Result = TRI_SURF(Z [, X, Y])

 INPUTS: 
	X, Y, Z:  arrays containing the X, Y, and Z coordinates of the 
		  data points on the surface. Points need not be 
		  regularly gridded. For regularly gridded input data, 
		  X and Y are not used: the grid spacing is specified 
		  via the XGRID and YGRID (or XVALUES and YVALUES) 
		  keywords, and Z must be a two dimensional array. 
		  For irregular grids, all three parameters must be
		  present and have the same number of elements. 

 KEYWORD PARAMETERS:
  Input grid description:
	REGULAR:  if set, the Z parameter is a two dimensional array 
		  of dimensions (N,M), containing measurements over a 
		  regular grid. If any of XGRID, YGRID, XVALUES, YVALUES 
		  are specified, REGULAR is implied. REGULAR is also 
		  implied if there is only one parameter, Z. If REGULAR is 
		  set, and no grid (_VALUE or _GRID) specifications are 
		  present, the respective grid is set to (0, 1, 2, ...). 
	XGRID:    contains a two element array, [xstart, xspacing], 
		  defining the input grid in the X direction. Do not
		  specify both XGRID and XVALUES. 
	XVALUES:  if present, XVALUES(i) contains the X location 
		  of Z(i,j). XVALUES must be dimensioned with N elements. 
	YGRID:    contains a two element array, [ystart, yspacing], 
		  defining the input grid in the Y direction. Do not
		  specify both YGRID and YVALUES. 
	YVALUES:  if present, YVALUES(i) contains the Y location 
		  of Z(i,j). YVALUES must be dimensioned with N elements. 

  Output grid description:
	GS:	  If present, GS must be a two-element vector [XS, YS],
		  where XS is the horizontal spacing between grid points
		  and YS is the vertical spacing. The default is based on
		  the extents of X and Y. If the grid starts at X value
		  Xmin and ends at Xmax, then the default horizontal
		  spacing is (Xmax - Xmin)/(NX-1). YS is computed in the
		  same way. The default grid size, if neither NX or NY
		  are specified, is 26 by 26. 
	BOUNDS:   If present, BOUNDS must be a four element array containing
		  the grid limits in X and Y of the output grid:
		  [Xmin, Ymin, Xmax, Ymax]. If not specified, the grid
		  limits are set to the extent of X and Y. 
	NX:       The output grid size in the X direction. NX need not
	  	  be specified if the size can be inferred from GS and
		  BOUNDS. The default value is 26.
	NY:       The output grid size in the Y direction. See NX. 

  Others:
       EXTRAPOLATE: If set, extrapolate the surface to points outside
		the convex hull of input points.  Has no effect if
		input points are regularly gridded.
	MISSING: If set, points outside the convex hull of input points
		are set to this value.  Default is 0.  Has no effect
		if input points are regularly gridded.

 OUTPUTS:
	This function returns a two-dimensional floating point array
 	containing the interpolated surface, sampled at the grid points.

 RESTRICTIONS:
	The output grid must enclose convex hull of the input points.
 PROCEDURE:
	This routine is similar to MIN_CURVE_SURF but the surface
	fitted is a smooth surface, not a minimum curvature surface.  This
	routine has the advantage of being much more efficient
	for larger numbers of points.

	The built-in IDL routines TRIANGULATE and TRIGRID(/QUINTIC) are
	used.

 EXAMPLES:
 Example 1: Irregularly gridded cases
	Make a random set of points that lie on a gaussian:
	  n = 15				;# random points
	  x = RANDOMU(seed, n)
	  y = RANDOMU(seed, n)
	  z = exp(-2 * ((x-.5)^2 + (y-.5)^2)) 	 ;The gaussian

 	get a 26 by 26 grid over the rectangle bounding x and y:
	  r = TRI_SURF(z, x, y)	;Get the surface.

 	Or: get a surface over the unit square, with spacing of 0.05:
	  r = TRI_SURF(z, x, y, GS=[0.05, 0.05], BOUNDS=[0,0,1,1])

 	Or: get a 10 by 10 surface over the rectangle bounding x and y:
	  r = TRI_SURF(z, x, y, NX=10, NY=10)

 Example 2: Regularly gridded cases
	Make some random data
	  z = randomu(seed, 5, 6)

	interpolate to a 26 x 26 grid:
	  CONTOUR, TRI_SURF(z, /REGULAR)

 MODIFICATION HISTORY:
	DMS, RSI, October, 1993.  Written.

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/tri_surf.pro)


TVB

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:   tvb

 USEAGE:    tvb,im

 PURPOSE:   Display a large image in one window at reduced resolution.
            Use the CURBOX routine to select a region of interest.
            The sub-array is displayed in another window at full resolution
            For each new sub-array the selected subscript range is printed
            to the terminal.  

 INPUT:
   im       a large two dimensional image array

 OUTPUT:    none

 PROCEDURE:
            when first invoked TVB renders the full image (possibly
            at reduced resolution) in a large window.  A region of
            interest is selected via the CURBOX procedure, by moving
            the mouse pointer or pressing the LMB or MMB to
            decrease/increase the box size.  The region is selected
            with the right mouse button.  Next, TVB draws the
            selected region at full resolution in another window and
            puts up a popup menu with 5 options.  The operator can
            choose to

         1. select a new region, killing the last special region window
         2. select a new region, keeping the last special region window
         3. blow up the current special region window by 50%
         4. quit the procedure, keeping all windows
         5. quit the procedure, killing all windows

 Side Effects:
            When items 1,2,4 or 5 are selected the the sub-array indecies of 
            the save window are printed to the terminal in format,
 
               window wid: (ix1:ix2, iy1:iy2)

            where,
 
            wid      is the window id of the special region window
            ix1:ix2  range of first subscript
            iy1:iy2  range of second subscript

            the sub array can be retrieved as,
 
            sub_array = im(ix1:ix2, iy1:iy2)

 EXAMPLE

    loadct,5
    im=randata(50,100,s=3)
    im=congrid(im,500,1000,/interp)

    tvb,im

  author:  Paul Ricchiazzi                            oct93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/tvb.pro)


TVIM

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  tvim

 USEAGE:   tvim,a

           tvim,a,scale=scale,range=range,xrange=xrange,yrange=yrange,     $
                aspect=aspect,title=title,xtitle=xtitle,ytitle=ytitle,     $
                noaxis=noaxis,interp=interp,colors=colors,c_map=c_map,     $
                stitle=stitle,rmarg=rmarg,clip=clip,labels=labels,         $
                pcharsize=pcharsize,lcharsize=lcharsize,nbotclr=nbotclr,   $
                clevels=clevels,nodata=nodata,rgb_nodata=rgb_nodata,       $
                barwidth=barwidth,position=position,noframe=noframe,rct=rct

 PURPOSE:  Display an image with provisions for
               
            1. numbered color scale 
            2. plot title
            3. annotated x and y axis 
            4. simplified OPLOT capability
            5. manual or automatic scaling with smooth or discreet colors
            6  special treatment of "invalid data" pixels

 INPUT    
   a           image quantity

 Optional keyword input:

  title
    plot title

  xtitle
    x axis title
 
  ytitle
    y axis title

  stitle
    color key title (drawn to the right of color scale)

  rmarg 
    right margin expansion factor to provide more room for extra wide
    color scale annotation (default=1)

  xrange
    array spanning entire x axis range. (default = [0,x_dimension-1])

  yrange
    array spanning entire y axis range. (default = [0,y_dimension-1])

    NOTE:TVIM only uses min(XRANGE), max(XRANGE), min(YRANGE) and max(YRANGE).

  scale
    if set draw color scale.  SCALE=2 causes steped color scale

  range
    two or three element vector indicating physical range over which
    to map the color scale.  The third element of RANGE, if specified, 
    sets the step interval of the displayed color scale.  It has no
    effect when SCALE is not set. E.g., RANGE=[0., 1., 0.1] will
    cause the entire color scale to be mapped between the physical
    values of zero and one; the step size of the displayed color
    scale will be set to 0.1.

  clip
    specifies a set percentage of pixels which will be left outside
    the color scale.  Larger values of CLIP yield images with greater
    contrast. For example if clip=2 then the color scale range will
    be set to include 98% of the pixels and to exclude the brightest
    1% and the dimmest 1% of the pixel brightness distribution.
    Keyword RANGE overides the effect of CLIP.

    If CLIP is a two element vector, the upper and lower percentile
    range can be specified.  For example CLIP=[0,95] will exclude the
    top 5%.  

    An alternative is to set CLIP to a single negative integer.  This
    causes the grey scale range to be obtained from the max and min
    value of the image array after it is filtered by a 2-D median
    filter. The radius of the median filter is set to -clip.  Median
    filtering is effective in removing "salt and pepper" noise,
    (isolated high or low values). For example, setting clip=-1
    causes the code to check the 9 element superpixel centered at
    each pixel for median values.  A single extremely large or small
    value does not affect the final value of the median at each pixel
    point.

  aspect
    the x over y aspect ratio of the output image. If not set, aspect
    is set to (size_x/size_y) of the input image.

  position
    specifies the lower left and upper right TVIM frame position in
    normal coordinates.  When set POSITION overides the setting of
    ASPECT.

  noaxis
    if set do not draw x and y numbered axis around image. Instead
    just draw a box

  noframe
    if set no not draw anything around image, not even a box

  interp
    TVIM normally uses nearest neighbor sampling to resize the image
    to fill the data window area. If INTERP is set the resizing
    operation uses bilinear interpolation

    If INTERP = 2 the interpolation range is adjusted so that there
    is a half pixel border around the plot.  This ensures that the
    smoothed image properly represents the cell center values of the
    pixels, but introduces an extrapolation on the outer edges.  This
    option has noticeable effects for small (<20) image arrays.
    
    NOTE: When writing to a Postscript file the resizing operation is
    accomplished by changing the pixel size.  Thus the INTERP
    parameter has no effect on Postscript output.

  pcharsize
    character size of numbers along x and y axis and the title
    (default is !p.charsize if non-zero, 1 otherwise)
 
    NOTE: The character size of the x and y-axis number scale
    annotation may be independently controlled by the !x.charsize or
    !y.charsize system variables.  For example, the x and y axis
    number scale characters may be made invisible by setting these
    variables to a very small non-zero number before calling TVIM.
    Remember to restore normal character sizes by setting !x.charsize
    and !y.charsize to 1 or zero after the call to TVIM.

  lcharsize
    character size of color key number or labels (default is
    !p.charsize if non-zero, 1 otherwise)

  barwidth
     width of color key which appears to right of image when SCALE is
     set.  (default=1)

  labels
     a vector of strings used to label the color key levels.  If not
     set the default color key number labels are used.  If the number
     of elements in LABELS is the same as the number of elements in
     COLORS then the labels will appear in the middle of a given
     color band instead of at the boundary between colors.  If COLORS
     is not set the number of elements in LABELS should be at least
     as large as the number of color key segments plus one.

  colors
     an array of color indicies.  When the COLORS array is set TVIM
     will map values of A into the color values specified in COLORS.
     How physical values are assigned to color values depends on how
     the RANGE parameter is set, as shown in this table:
     
             RANGE           color_value
             -----           -----------
       1.  not set          COLORS(A)
       2.  [amin,amax]      COLORS((A-amin)/dinc)
       3.  [amin,amax,inc]  COLORS((A-amin)/inc)
     
     where amin, amax and inc are user specified elements of RANGE
     and dinc=(amax-amin)/n_elements(COLORS).  In case 1, A is used
     directly as a subscript into COLORS.  When RANGE is not set
     legend labels should be used to annotate the color values. In
     case 2, A is scaled so that each color defined in COLORS
     represents a proportionate fraction of the total dynamic range.
     In case 3, amin and inc (and not amax) are used to control which
     colors are associated with given physical values.  See examples.

  c_map
     TVIM normally rescales the input image to span the entire color
     table range. Setting C_MAP disables this automatic re-scaling.
     This is useful when the image byte values correspond to a
     particular color mapping that could be destroyed by the
     rescaling process (E.G.  a gif image).
     
     NOTE: When the number of IDL color table entries is less than
     256 some colors may be lost. Use a private color map to avoid
     this. See examples.
               
  nbotclr
     number of reserved colors at the bottom of the color
     table.  Color values between 0 and nbotclr-1 will not
     be used in the displayed image.  This allows the
     bottom of the table to be set to special colors which
     will not be used in the displayed the image.  This
     keyword is disabled when either the COLORS or NODATA 
     options are used.  (default=1)

     NOTE: by default the color table indicies used within a TVIM
     image is limited to the range 1 to !d.n_colors-2. In most
     predefined color tables, color index 0 and !d.n_color-1
     correspond to pure black and white, respectively. TVIM uses
     these color indicies as background and foreground colors for
     region blanking and axis annotation. Color tables which do not
     define black and white in these index locatations are not good
     choices for TVIM plots, unless the first and last color table
     entries are redefined as black and white using TVLCT, e.g.,
     tvlct,0,0,0,0 & tvlct,255,255,255,!d.n_colors-1
     
     NOTE: the procedure DCOLORS can be used to load a set
     of discreet colors in the bottom 11 color values
     (0-10). The original color table is resampled to fit
     between color value 11 and the !d.n_colors-1.
             

  nodata
     pixel values which are interpreted as invalid data.  Pixels
     containing this data value are colored with color RGB_NODATA.

  rgb_nodata
     an RGB value (a 3 component vector) used to color pixels filled
     with invalid data. (default = [0,0,0])

     NOTE: NODATA and RGB_NODATA override the effect of NBOTCLR

  rct
     if set, reverse direction of color table.  This keyword can be
     used on black & white printers to allow large field values to be
     represented by dark colors.  Note, this feature is implemented
     by reversing the association between physical values and color.
     Though it reverses the colors on the color key, it does not
     affect the actual color table.
     
               
 KEYWORD OUTPUT:
   clevels 
     physical values at the color key tic marks.  Use this to set
     contour levels in a subsequent call to CONTOUR.

 SIDE EFFECTS: 
     Setting SCALE=2 changes the color scale using the STEP_CT
     procedure.  The color scale may be returned to its original
     state by the command, STEP_CT,/OFF

 PROCEDURE:
     TVIM first determines the size of the plot data window with a
     dummy call to PLOT.  When the output device is "X", CONGRID is
     used to scale the image to the size of the available data
     window.  Otherwise, if the output device is Postscript,
     scaleable pixels are used in the call to TV.
     
     If the input image quantity is not of type byte, TVIM converts
     them to byte by scaleing the input between 0 and !d.n_colors-1.
     If the input is already a byte array and if either the number of
     color table entries is 256 or if C_MAP is set, then no scaling
     is done.  This is to ensure consistency with specially defined
     private color tables.
     
     After the the image is drawn TVIM calls PLOT again to draw the x
     and y axis and titles.  Finally if scale is set, TVIM calls the
     COLOR_KEY procedure to draw the color scale just to the right of
     the data window.

 RESTRICTIONS: 
     A stepped color scale (SCALE = 2 option) is not available when
     writing to a black & white postscript file (i.e., when the
     DEVICE color option is not enabled).

 DEPENDENCIES: COLOR_KEY, STEP_CT, PRANK

 EXAMPLES:

;    Plot a GIF image with its own preset RGB
;    table (perhaps from a digitized video image)

 window,colors=256            ; set up a private color map
 read_gif,'/home/paul/gif/el-nino.gif',im,r,g,b
 tvlct,r,g,b
 tvim,im,/c_map
;
;
;    Plot an image with descreet greyscale values to a printer
;    which has its own hard-wired color table.

 im=randata(128,128,s=4)
 immx=max(im) & immn=min(im)
 !p.multi=[0,2,2]
 tvim,im,/scale,colors=!p.color*indgen(4)/3.,range=[immn,immx]
 tvim,im,/scale,colors=!p.color*indgen(5)/4.,range=[immn,immx]
 tvim,im,/scale,colors=!p.color*indgen(8)/7.,range=[immn,immx]
 tvim,im,/scale,colors=!p.color*indgen(10)/9.,range=[immn,immx]
;
;
;    Display a map of surface types (green=veg, blue=water, red=sand)
;    Notice how RANGE is used to associate physical values with colors.
;    (use im from the previous example)

 im=randata(128,128,s=4)
 immx=max(im) & immn=min(im) & delim=immx-immn
 
 tvlct,[0,0,0,255],[0,255,0,0],[0,0,255,0]
 !p.multi=[0,2,2]
 colors=[1,2,3] & labels=[' veg',' water',' sand']
 range=[immn,immx,delim/3]
 
 tvim,im,/scale
 
 tvim,im,colors=colors,range=range,/scale
 
 tvim,im,colors=colors,range=range,/scale,labels=labels,lch=2
 
 !p.multi=0
 range=[immn-.25*delim,immx+.25*delim,delim/2]
 lbl=[' veg!c region 1',' water!c region 2',' sand!c region 3']
 tvim,im,colors=colors,range=range,/scale,labels=lbl,lch=2,rmarg=2,pchar=1.2
;
;
;   Display the image from previous example and overlay a contour plot
;
 loadct,5
 im=randata(128,128,s=4)
 immx=max(im) & immn=min(im) & delim=immx-immn
 xrange=[-120,-100]
 yrange=[20,50]
 range=[immn,immx]
 xx=findrng(xrange,128)
 yy=findrng(yrange,128)

 tvim,im,/scale,xrange=xrange,yrange=yrange,clevels=clevels,range=range
 contour,im,xx,yy,levels=clevels,/overplot


;    NOTE: You might prefer the results obtained from procedure CONFILL.
         
 confill,im,xx,yy,/asp,levels=clevels
;
; 
;    Display a grey scale image and annotate certain points in color
;
 loadct,0
 dcolors
 tvim,im,/scale,nbotclr=11                    ; reserve some colors at bottom
 xx=interpolate([40,80],randomu(iseed,10))
 yy=interpolate([40,80],randomu(iseed,10))
 plots,xx,yy,psym=2,color=1+indgen(10)
  
;
; 
;    Display a grey scale image and show nodata values in red
;
 loadct,0
 im=randata(100,100,s=4.5)
 im(randomu(iseed,50)*9999)=-999.
 tvim,im,/scale,nodata=-999.,rgb_nodata=[255,0,0]
  
;
;
;    Postscript output with a reversed color scale.  Because the
;    background color is always RGB=(255,255,255) you must set the
;    default color, !p.color, to a dark color if you want good contrast
;    between the axis labels and the white paper.   According to 
;    Didier's reversed color table a color index of 255 should produce
;    black, but for some reason !p.color=255 doesn't work right.
;    I think IDL is iterpreting !p.color=255 in some special way.
;    So instead use !p.color=254; this seems to work fine.
;
 toggle,/color
 loadct,28
 !p.color=254              ; don't use 255, don't ask me why
 tvim,dist(20),/scale
 toggle
               
;
; display data defined on a regular LAT-LON grid onto a given map 
; projection.  USE MAP_SET and MAP_IMAGE to create the map projection
; and to warp the image.  Then use BOXPOS to position the TVIM frame
; to correctly register the map and image

 IMAGE = sin(!pi*findrng(0,24,200))#sin(!pi*findrng(0,12,200))
 !p.multi=[0,1,2]
 map_set,45,0,/ortho,/advance,pos=boxpos(/aspect)
 newimage=map_image(image,/bilin,latmin=-90,latmax=90,lonmin=-180,lonmax=180)
 tvim,newimage,title='Warped data',pos=boxpos(/get),/scale
 map_set,45,0,/ortho,pos=boxpos(/get),/grid,/cont,/noerase ; draw map
 tvim,image,xrange=[-180,180],yrange=[-90,90],/scale, $
     title='Unwarped data',xtitle='Longitude',ytitle='Latitude'
 map_set,0,0,/cyl,pos=boxpos(/get),/grid,/cont,/noerase ; draw map

; use MAP_SET2 to mask out land areas. Note that the example below is
; unusual.   MAP_SET2 doesn't always produce such nicely filled land areas.
; Typically one must run MAP_SET2 with /SAVE
; to create a ascii file containing the continental boundary lat-lon
; coordinates. Then use an editor  to group the continental coordinates 
; line segments to form closed contours which POLYFILL can understand 
; (the call to POLYFILL is enabled by setting con_color).
;  

 image=randata(256,256,s=2.5)
 tvim,image
 map_set2,-64,-64,/cont,limit=[-65.1,-64.5,-64,-62],/ortho,con_col=100,$
           pos=boxpos(/get),/noerase,/grid
;               
 AUTHOR:       Paul Ricchiazzi    oct92 
               Earth Space Research Group, UCSB

 REVISIONS:
 28jan93: switched from PUT_COLOR_SCALE to COLOR_KEY
 11feb93: added INTERP keyword
 11feb93: added C_MAP keyword
 11feb93: added STITLE keyword
 20apr93: added RMARG keyword, centered image in plot window
 23apr93: call COLOR_KEY before TV. Now stepped color scales copy to PS file
 10sep93: deal with perfectly flat images. No more math error when a=0
 14sep93: added CLIP keyword
 11feb94: added PCHARSIZE,LCHARSIZE,LABELS, and COLORS keywords
 18feb94: added NBOTCLR keyword
 16mar94: added INTERP=2 option and adjusted centering of pixels
 08Jul94: added NODATA and RGB_NODATA keywords
 04Aug94: added BARWIDTH keyword 
 04Aug94: defaulted PCHARSIZE and LCHARSIZE to !P.CHARSIZE if non-zero
 02Mar95: added POSITION keyword
 31Mar95: added NOAXIS keyword
 24may95: initial sizing includes allowance for PCHARSIZE > 1
 06sep95: color indecies used in plot now run from 1 to !d.ncolors-2
 24jul96: do a REFORM(a) to allow tvim,a(1,*,*) to work with no complaints
 01sep96: added the RCT keyword

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/tvim.pro)


TV_POLAR

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    
   tv_polar
 
 USEAGE:     
   tv_polar,psi,phi,theta

   tv_polar,psi,phi,theta,style=style,grdres=grdres,title=title,rot=rot, $
            image=image,xvec=xvec,yvec=yvec,phitics=phitics,half=half, $
            thetics=thetics,charsize=charsize,thephi=thephi,rmarg=rmarg, $
            labels=labels,colors=colors,lcharsize=lcharsize,stitle=stitle, $
            showpnts=showpnts,range=range,lower=lower,gclr=gclr, $
            clevels=clevels,noscale=noscale,barwidth=barwidth, $
            c_thick=c_thick,c_color=c_color,xtitle=xtitle,nadir=nadir

 PURPOSE:    
   Display of images defined in polar coordinates (without resorting
   to IDL's mapping routines).

 INPUT:
   psi      
     image quantity (2-d array) one value at each (phi,theta) point
     note that the phi coordinate is the first index

   phi
     monitonically increasing vector specifying azimuthal coordinate
     PHI must span either 0 to 360 degrees or 0 to 180 degrees.  If
     phi spans 0-180 degrees and the keyword HALF is not set, then
     reflection symmetry is assumed, i.e.,
     r(phi,theta)=r(360-phi,theta).

   theta
     monitonically increasing vector specifying polar coordinate (degrees)
 
 KEYWORD INPUT:

   style
     0   do not plot anything, just return image,xvec and yvec
     1   use confill for plot
     2   use tvim for plot
     3   use contour for plot, no grey scale

   title
     plot title

   grdres
     number of grid points in cartesian grid used to rebin polar
     information.  Array size is (grdres x grdres) default=51

   phitics
     azimuth tic mark spacing in degrees 

   thetics
     polar angle tic mark spacing in degrees
 
   half
     if set, the part of the polar plot with azimuth angles between
     180 and 360 is not displayed.  if HALF lt 0 the half circle is
     inverted so that the horizontal axis is at the top of the plot 
     and the magnitude of HALF is the vertical offset (in character 
     heights) below the previous plot (which is presumed to be a 
     TV_POLAR plot of the upper hemisphere).  If abs(HALF) le 2 then
     xaxis labeling is disabled. This option requires column major
     ordering, i.e., either !P.MULTI(4)=1 or !P.MULTI(1)=1
     Don't set HALF if ROT ne 0. (see example)

   thephi
     vector of azimuth angles at which to annotate polar angles.  For
     example setting THEPHI=[45,315] causes all the polar angles
     listed in THETICS to be labeled at azimuth angles 45 and 315.
     If maximum element of THEPHI is negative then the 
     (default is 45 degrees)

   charsize
     character size multiplier used on all plot labels but not on
     color scale labels

   rot
     set location of azimuth zero point and direction of increase

     0    right , azimuth increases counterclockwise (default)
     1    top   , azimuth increases counterclockwise
     2    left  , azimuth increases counterclockwise
     3    bottom, azimuth increases counterclockwise
     4    top   , azimuth increases clockwise       (standard compass)
     5    left  , azimuth increases clockwise
     6    bottom, azimuth increases clockwise
     7    left  , azimuth increases clockwise
             

   range
     two or three element vector indicating physical range over which
     to map the color scale.  The third element of RANGE, if
     specified, sets the step interval of the displayed color scale.
     It has no effect when SCALE is not set. E.g., RANGE=[0., 1.,
     0.1] will cause the entire color scale to be mapped between the
     physical values of zero and one; the step size of the displayed
     color scale will be set to 0.1.  RANGE overides CLEVELS.

   rmarg
     right margin expansion factor to provide more room for extra
     wide color scale annotation (default=1)

   labels
     a vector of strings used to label the color key levels.  If not
     set the default color key number labels are used.  If the number
     of elements in LABELS is the same as the number of elements in
     COLORS then the labels will appear in the middle of a given
     color band instead of at the boundary between colors.  If COLORS
     is not set the number of elements in LABELS should be at least
     as large as the number of color key segments plus one.

   colors
     an array of color indicies.  When the COLORS array is set TVIM
     will map values of A into the color values specified in COLORS.
     How physical values are assigned to color values depends on how
     the RANGE parameter is set, as shown in this table:
     
               RANGE           color_value
               -----           -----------
         1.  not set          COLORS(A)
         2.  [amin,amax]      COLORS((A-amin)/dinc)
         3.  [amin,amax,inc]  COLORS((A-amin)/inc)
     
     where amin, amax and inc are user specified elements
     of RANGE and dinc=(amax-amin)/n_elements(COLORS).  In
     case 1, A is used directly as a subscript into COLORS.

   lcharsize
     character size of color key number or labels

   stitle
     color key title (drawn to the right of color scale) 

   contour
     if set draw contour lines 

   showpnts
     if set original grid of (phi,theta) points are ploted on the
     image

   gclr
     the color used for grid labels and axis, default=!p.color

   clevels
     a vector of contour levels

   barwidth
     width of color key which appears to right of contour plot (default=1).

   noscale
     if set don't draw color scale to the right of the plot

   c_thick
     thickness of contour lines, set to zero to eliminate contour lines

   c_color
     color of contour lines (special interpretation of c_color is
     possible when CONFILL is used, see CONFILL documentation)
     
   lower
     if set, theta values between 90 and 180 are ploted

   nadir
     if set, theta (which are usually zenith values) is displayed 
     as 180-theta

   xtitle
     title for horizontal axis when HALF is set, the titles would
     usually be either "nadir angle" or "zenith angle", 

 OUTPUT:
     none

 KEYWORD OUTPUT:
   image
     rebined image of size (grdres,grdres) 

   xvec
     vector of x coordinate values

   yvec
     vector of y coordinate values

     These optional output quantities can be used to overplot contour
     lines over the TV_POLAR output.

 EXAMPLE:

; show all styles

    loadct,5
    phi=findgen(25)*15
    theta=5+findgen(17)*5
    psi=(cos(4*phi*!dtor)#sin(5*theta*!dtor))^2
    w11x8 &  !p.multi=[0,3,2]
    tvim,psi,xrange=phi,yrange=theta,/interp
    for s=1,3 do TV_POLAR,psi,phi,theta,style=s,c_thick=0
    tv_polar,psi,phi,theta,style=1
    tv_polar,psi,phi,theta,style=2

; show all ROT possibilities

    w8x11 & !p.multi=[0,2,4]
    loadct,5
    phi=findgen(25)*15
    theta=5+findgen(14)*5
    psi=(phi*!dtor)#replicate(1.,n_elements(theta))
    title="ROT = " + string(f='(i2)',indgen(8))+repchr(50,' ')
    for rot=0,7 do TV_POLAR,psi,phi,theta,rot=rot,title=title(rot),sty=2,c_t=0

; plot radiance in lower and upper hemisphere


    t=[0,15,32,45,60,70,80,89,91,100,110,120,135,148,165,180.]
    p=[0,15,30,45,60,75,90,105,120,135,150,165,180.]
    r=fltarr(13,16) & read,r
           81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 
           96, 95, 93, 91, 87, 85, 84, 83, 80, 76, 74, 74, 73, 
          130,128,123,119,113,103, 95, 92, 84, 81, 80, 77, 75, 
          184,181,171,153,136,126,110,104, 93, 90, 84, 82, 84, 
          293,279,243,212,182,152,134,117,106, 99, 90, 93, 80, 
          388,370,323,250,208,165,144,119,110, 98, 91, 91, 90, 
          513,448,344,274,194,160,127,106, 97, 82, 82, 72, 74, 
          184,165,101, 71, 48, 40, 28, 26, 21, 19, 18, 18, 16, 
           97, 94, 89, 81, 73, 66, 60, 55, 52, 49, 47, 46, 45, 
          168,163,151,135,120,107, 96, 87, 80, 75, 71, 69, 69, 
          244,232,208,181,157,136,120,108, 98, 91, 87, 84, 83, 
          322,299,257,216,183,156,136,120,109,101, 95, 92, 91, 
          356,332,284,238,199,169,146,129,117,108,102, 98, 97, 
          291,281,254,222,193,168,148,132,121,112,107,103,102, 
          200,198,191,181,170,158,148,139,131,125,121,119,118, 
          148,148,148,148,148,148,148,148,148,148,148,148,148. 
;
  nclr=12 & cl=findrng(0,550,nclr) & clr=!d.n_colors*(1+findgen(nclr))/nclr
 !p.multi=[0,2,4,1,1] & w8x11 & !y.omargin=[12,0] & set_charsize,2
  loadct,5 & xtz='Zenith Angle' & xtn='Nadir Angle' 

 tv_polar,r,p,t,xt=xtz,/half,clevels=cl,colors=clr,/noscale
 tv_polar,r,p,t,half=-4,/lower,clevels=cl,colors=clr,/noscale

 tv_polar,r,p,t,xt=xtn,/half,clevels=cl,colors=clr,/noscale,/nadir
 tv_polar,r,p,t,half=-4,/lower,clevels=cl,colors=clr,/noscale,/nadir

 tv_polar,r,p,t,/half,clevels=cl,colors=clr,/noscale
 tv_polar,r,p,t,half=-3,/lower,clevels=cl,colors=clr,/noscale

 tv_polar,r,p,t,/half,clevels=cl,colors=clr,/noscale
 tv_polar,r,p,t,half=-2,/lower,clevels=cl,colors=clr,/noscale

 color_bar,cl,clr,pos=[0.1,0.05,0.9,0.12],title='Radiance (W/m!a2!n/um/sr)'
 !y.omargin=0
 
 DEPENDENCIES
     TVIM, COLOR_KEY, CONTLEV, FINTERP, GENGRID, CONFILL, BOXPOS

 AUTHOR:     Paul Ricchiazzi    oct92 
             Earth Space Research Group, UCSB

 Revisions:
 aug98: use fill_image to smooth "horizon" points

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/tv_polar.pro)


UAV_PATH

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:	uav_path

 PURPOSE:	dispay a time history of measured quantities obtained 
               on a moving ship or plane.  UAV_PATH provides an easy
               user interface to 1) select measured quantities to plot
               and 2) run SPRITE to hilight the correspondences of 
               different data channels as a function of time and position.

 USEAGE:	uav_path,buf,labels,coor,trange=trange,select=select

 INPUT:       
   buf         array of data values of dimension (number of variables) 
               x (number of samples). Two of the measured quantities
               should correspond to the horizontal coordiates of the
               sample location, for example longitude and latitude.
               A third quantity should provide the time coordinate of
               the measurements.

   labels      string array of variable names

   coor        Three element vector array of indecies in BUF which
               correspond to time and the "x" and "y" horizontal
               coordinates of the measurement.  For example the
               uav/tddr data set has GPS_TIME, GPS_LON and GPS_LAT at
               [7,3,2]. If COOR is not set, it defaults to [7,3,2].


 KEYWORD INPUT:

   trange      time range of interest

   select      array of variable indecies to plot.  You can also use
               SELECT to retrieve the indecies of the plot quantities
               selected interactively.  Just set SELECT to an
               undefined or zero valued variable on the first call to
               UAV_PATH and reuse the returned value of SELECT in the
               next call to UAV_PATH to repeat the plot set, (perhaps
               with a different setting of TRANGE).

   sprite      run SPRITE after plots are displayed 

   bad         a single scalor value which is interpreted as a "bad"
               measurement.  Any time sample returning this value for any
               particular plot quantity will be rejected.

  
 EXAMPLE:	

  get_uavtddr,buf,labels
  select=0              
  uav_path,buf,labels,select=select ; select uav quantities interactively
                                         ; save selections in SELECT

  uav_path,buf,labels,select=select,trange=[16,17],/sprite


; you can also use UAV_PATH with ZOOMBAR to zero in on a time range

  
  get_uavtddr,buf,labels,coor
  select=[0,5,11,12,17]

  uav_path,buf,labels,coor,select=select
  while zoombar(rng) do uav_path,buf,labels,select=select,trange=rng

 REVISIONS:

  author:  Paul Ricchiazzi                            feb95
           Institute for Computational Earth System Science
           University of California, Santa Barbara
   

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/uav_path.pro)


VSCAT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE         vscat

 PURPOSE:        1. use the interactive graphics cursor and the 
                    DEFINE_REGION procedure to select a region

                 2. plot a x vs y scatter plots of two variables from that
                    region

 USEAGE          vscat,x,y,image
 
 INPUT:
   x             array ploted on x axis of scatter plot
   y             array ploted on y axis of scatter plot
   image         image used to select regions to plot

 KEYWORD INPUT:
   xrange        range of scatter plot x axis
   yrange        range of scatter plot y axis
   xtitle        title of scatter plot x axis
   ytitle        title of scatter plot y axis
   title         title of image plot

 EXAMPLE
       !p.multi=[0,1,2]
       x=20*randata(128,128,s=4)+(findgen(128) # replicate(1.,128))
       y=20*randata(128,128,s=4)+(replicate(1.,128) # findgen(128))
       image=x+y
       vscat,x,y,image



 OUTPUT:         none

  author:  Paul Ricchiazzi                            aug93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/vscat.pro)


W11X8

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  w11x8

 PURPOSE:  create a window which approximates the aspect ratio of a
           8.5 x 11 piece of paper in landscape orientation

 USEAGE:   w11x8

 INPUT:    none

 KEYWORD INPUT:
  free     if set, window,/free is used to create a new window

 EXAMPLE:  

    w11x8
    plot,dist(20)   

 AUTHOR:   Paul Ricchiazzi                        03 Aug 93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/w11x8.pro)


W8X11

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  w8x11

 PURPOSE:  create a window which approximates the aspect ratio of a
           8.5 x 11 piece of paper

 USEAGE:   w8x11

 INPUT:    none

 KEYWORD INPUT:
  free     if set, window,/free is used to create a new window

 EXAMPLE:  

    w8x11
    plot,dist(20)   

 AUTHOR:   Paul Ricchiazzi                        03 Aug 93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/w8x11.pro)


WHICH

[Previous Routine] [Next Routine] [List of Routines]
 NAME:  
              which

 PURPOSE:     Prints a list of all directory pathnames which match a
              given idl procedure name.  The directory precedence is
              set by the system variable !path.  The file name may
              contain any wild card characters understood by the
              operating system.  In the case that a given procedure
              is found in more than one directory, the first listed
              pathname is the one compiled by the IDL interpreter in
              response to a .run statement.

 USEAGE:      which,filename

 INPUT:    
   filename   name of idl procedure (may include wild cards)

 KEYWORD INPUT:  none

 OUTPUT:         none
  
 EXAMPLE:  
               which,'str*'  ; produces this output:

               /local/idl/user_contrib/esrg/strip_fn.pro
               /local/idl/user_contrib/esrg/strmatch.pro
               /local/idl/user_contrib/esrg/strpack.pro
               /local/idl/user_contrib/esrg/strwhere.pro
               /local/idl/lib/color/stretch.pro
               /local/idl/lib/prog/str_sep.pro


 AUTHOR:   Paul Ricchiazzi                        19 Nov 97
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/which.pro)


WINFULL

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  winfull

 PURPOSE:  create full screen window 

 USEAGE:   winfull

 INPUT:    

 KEYWORD INPUT:

 OUTPUT:

 DISCUSSION:

 LIMITATIONS:

 COMMON BLOCKS:

 SIDE EFFECTS:
  
 EXAMPLE:  

 AUTHOR:   Paul Ricchiazzi                        30 May 96
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/winfull.pro)


WMX_MSEL

[Previous Routine] [Next Routine] [List of Routines]
               title=title, xpos=xpos, ypos=ypos, $
               rtcode=rtcode

 WaveMenu/Widgets: set flags / multiple selection from list

 START OF DESCRIPTION
 
 subroutine        (c) IPI, Uni Hannover 02'94, modified 02'94

 METHOD:           using IDL-Widgets                        (registered)
                   toggle-buttons
                   press button to select item
                   
                   routine should run under IDL 3.0 or higher
                           on SparcStations	        (SunOs)
                              Pc's                 (MsWindows)
                   
                   
 INPUT  PARAMETER: text       string-array with text to select from
                   select     long-array with selection-index
                   
 OUTPUT PARAMETER: select     as defined in routine
                              elements selected return ONE, the rest ZERO
                   
 INPUT KEYWORDS  : title      title                              ["set flags"]
                   x(y)pos    window position  (!upper left)       [automatic]
                   
 OUTPUT KEYWORDS : rtcode     Return-code : 0 for o.k., -1 for ERROR
                   
 EXAMPLE:
 
 wmx_msel, 'DEMO: ' + sindgen(32), select & print, select
 

 Author            Karlheinz Knipp                  phone:  +49 511 - 762 4922
                   University of Hannover             fax:  +49 511 - 762 2483
                   Institute for Photogrammetry
                   Nienburger Str.1     
                   FRG  30167 Hannover 1      email: knipp@ipi.uni-hannover.de

                   knipp@ipi.uni-hannover.de      jan94

 END OF DESCRIPTION

-

 event handling routine of WMX_MSEL

ro  wmx_msel_event, event



 common

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/wmx_msel.pro)


WRITE_IN_BOX

[Previous Routine] [Next Routine] [List of Routines]
 Project     :	SOHO - CDS

 Name        :	WRITE_IN_BOX

 Purpose     :	Writes a text message within a box in a graphics window.

 Explanation :	This procedure writes a short text message within a box-shaped
		area in a graphics window.  The message may be split at word
		boundaries into several lines, and the character size and
		orientation may be adjusted for the text to fit within the box.

 Use         :	WRITE_IN_BOX, X1, X2, Y1, Y2, TEXT

 Inputs      :	X1, X2	= X coordinates of the box limits.
		Y1, Y2	= Y coordinates of the box limits.
		TEXT	= ASCII text string containing the message.

 Opt. Inputs :	None.

 Outputs     :	None.

 Opt. Outputs:	None.

 Keywords    :	DATA	    = If set, then the coordinates are in data units.
			      This is the default.
		DEVICE	    = If set, then the coordinates are in device units.
		NORMAL	    = If set, then the coordinates are in normalized
			      units.
		MAXCHARSIZE = The maximum charsize to use in displaying the
			      message.  If not passed, then determined from
			      !P.CHARSIZE.
		COLOR	    = Color to use to display the text.  The default is
			      !COLOR.

 Calls       :	None.

 Common      :	None.

 Restrictions:	X2 must be greater than X1, and Y2 must be greater than Y1.

 Side effects:	The appearance of the displayed message may not be optimal if
		any words are separated by multiple blanks, or by tab
		characters.

 Category    :	Planning, Science.

 Prev. Hist. :	None.

 Written     :	William Thompson, GSFC, 7 July 1993.

 Modified    :	Version 0.1, William Thompson, GSFC, 7 July 1993.

 Version     :	Version 0.1, 7 July 1993.

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/write_in_box.pro)


WRITE_WIN

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:      write_win

 PURPOSE:      copy image on current window to a gif image file

 USEAGE:       write_win,file

 INPUT:
   file        output file name, image will be written in gif or tiff
               image format

 KEYWORD INPUT:

   tiff        if set, output is in tiff format instead of gif

   cmap        if set, color table is expanded to 256 values.
               don't use this option when discrete color values have
               been set with dcolors or tvlct

   wid         index of the idl window from which to copy the image,
               if not set write_win copies from current default window

   bgc         background color.  sets color index 0 of gif image to 
               specified RGB value.  Does not affect current color table.
               A scalor value of BGC is automatically turned into a color
               triplet, i.e., bgc=255   =>  RGB=[255,255,255]

   fgc         foreground color.  sets color index 255 of gif image to 
               specified RGB value.  Does not affect current color table.
               A scalor value of FGC is automatically turned into a color
               triplet, i.e., fgc=0   =>  RGB=[0,0,0]

 OUTPUT:       none

 EXAMPLE:
           loadct,5
           window,0
           tvim,sin(20*hanning(200,200)*dist(200)),title='GIF test image',/sc
           write_win,'test_image.gif',fgc=0,bgc=[210,255,210]
           write_win,'test_image.tiff',fgc=0,bgc=[210,255,210],/tiff
           exit

           xv test_image.gif

  author:  Paul Ricchiazzi                            feb94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/write_win.pro)


WSELECT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    wselect

 PURPOSE:    wset to window selected by a mouse click

 USEAGE:     wselect

 DISCUSSION: the LMB selects the window and exits WSELECT, 
             the MMB kills the window and remains within the 
             WSELECT program loop.  The WSELECT program loop 
             ends when either the LMB is pressed within a window
             or when there are no remaining windows.

 OUTPUT:     none

  author:  Paul Ricchiazzi                            11jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/wselect.pro)


XAXIS_MONTH

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    xaxis_month

 PURPOSE:    label x axis with month names when the x axis plot quantity
             is day of year

 USEAGE:     xaxis_month,year

 INPUT:      
   year      year, reqiured to set leap year calendar.  if not set a
             non-leap-year is used. 

 OUTPUT:     none

 SIDE EFFECTS:
             draws in the x axis with month labels and tick marks 
             between months
  
 EXAMPLE:
             x=indgen(365)+1
             zensun,x,12,35,0,zen
             plot,x,zen,xstyle=5,title='solar zenith angle',ytitle='zenith'
             xaxis_month

 REVISIONS:

  author:  Paul Ricchiazzi                            jan94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/xaxis_month.pro)


XDATENT

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  xdatent

 PURPOSE:  widget for text data entry.  

 USEAGE:   xdatent,labels,value,ncol=ncol,group=group

 INPUT:    
   labels  string array of labels for data entry field

 KEYWORD INPUT:
   ncol    number of columns of data entry fields
   font    text font to use
   group   group leader widget, when this widget dies, so does xdatent

 INPUT/OUTPUT
   value   float, double, long or int array of values
           on input: used to set default values
           on exit:  edited values

 
 COMMON BLOCKS:
   xdatentblk

 EXAMPLE:  

   labels=['min latitude','max latitude','min longitude','max longitude']
   value=[30.,40.,-130.,-120.]
   xdatent,labels,value,ncol=2
   table,labels,value

; NOTE: the input focus can be moved by hitting the tab key.  


 AUTHOR:   Paul Ricchiazzi                        05 Jul 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/xdatent.pro)


XGLOBE

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:     XGLOBE

 USEAGE:      XGLOBE

 PURPOSE:     Display a world map and allow user to zoom in on a given region

 INPUT:       none
 OUTPUT:      none

 BUTTONS:
   DONE       quit XGLOBE

 ZOOM         Pull down menu 
     ZOOM IN: The IDL routine BOX_CURSOR is used to select the region.
              use left mouse button to point and drag the cursor box
              use middle mouse button to resize cursor box
              use right mouse to select region and draw the map

              To reduce distortion on zoomed regions near the poles
              it is a good idea to choose a short, wide map region.

    ZOOM OUT: The latitude and longitude limits are increased by 20% and
              the map is redrawn.

       WORLD: Redisplay world map (equivalent to hitting ZOOM OUT many times)

        PLOT: Replot map with current lat-lon limits.

 PRINT        Pull down menu
        TERM: Print current map to device TERM 
     GAUTIER: print current map to device GAUTIER 
      PHASER: print current map to device PHASER (color plots)
         DUP: print current map to device DUP


   COLOR      Pull down menu
  CONTINENTS: adjust color value of continental boundaries
    US STATE: adjust color value of US state boundaries
   POLITICAL: adjust color value of political boundaries
      RIVERS: adjust color value of rivers

	 NOTE: Each of these options use the procedure PICK_COLOR
	       to adjust the color value for a single color index.
	       Motion of the cursor inside the PICK_COLOR window 
              adjusts the Hue and Saturation values.
	       Holding down the left mouse button decreases brightness.
	       Holding down the middle mouse button increases brightness. 
	       Pressing the right mouse button selects the color and returns.

   HELP       print this help file


 TEXT WIDGET  (labeled WHERE IS:)

              Enter the latititude   longitude 
              A symbol is drawn to indicate point on map.
              NOTE: the code will bomb if you mess up the format

 DRAW WIDGET  The lat-lon coordinates under the cursor are
              printed when the left mouse button is held down
              (This feature is disabled in "ZOOM IN" region selection
              mode)

  author:  Paul Ricchiazzi                            DEC92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/xglobe.pro)


XHELP

[Previous Routine] [Next Routine] [List of Routines]
 NAME: 
	xhelp

 PURPOSE:
	Display an IDL procedure header using widgets and the widget manager.

 CATEGORY:
	Widgets.

 CALLING SEQUENCE:
	xhelp, Filename, TITLE = TITLE, GROUP = GROUP, WIDTH = WIDTH, $
		HEIGHT = HEIGHT, TEXT = TEXT, FONT = font, unmanaged=unmanaged

 INPUTS:
     Filename:	A scalar string that contains the filename of the file
		to display.  If FILENAME does not include a complete path
               specification, xhelp will search for the file in
               the current working directory and then each of the
               directories listed in !PATH environment variable.  The
               ".pro" file suffix will be appended if it is not supplied.

 KEYWORD PARAMETERS:
	FONT:   The name of the font to use.  If omitted use the default
		font. If font is set to 1 then a fixed width font is used:
               "-misc-fixed-bold-r-normal--13-120-75-75-c-80-iso8859-1"

	GROUP:	The widget ID of the group leader of the widget.  If this 
		keyword is specified, the death of the group leader results in
		the death of xhelp.

	HEIGHT:	The number of text lines that the widget should display at one
		time.  If this keyword is not specified, 24 lines is the 
		default.

	TEXT:	A string or string array to be displayed in the widget
		instead of the contents of a file.  This keyword supercedes
		the FILENAME input parameter.

	TITLE:	A string to use as the widget title rather than the file name 
		or "xhelp".

	WIDTH:	The number of characters wide the widget should be.  If this
		keyword is not specified, XHELP checks the input file for
               the maximum line length.

   UNMANAGED:  do not call xmanager and do not include a "DONE" button
               on the widget.  In this case the x window manager must be
               used to kill the widget.

 OUTPUTS:
	No explicit outputs.  A file viewing widget is created.

 SIDE EFFECTS:
	Triggers the XMANAGER if it is not already in use.

 RESTRICTIONS:
	None.

 PROCEDURE:
	Open a file and create a widget to display its contents.

 MODIFICATION HISTORY:
	Written By Steve Richards, December 1990
	Graceful error recovery, DMS, Feb, 1992.
       Modified to extract .pro documentation headers, PJR/ESRG mar94

  author:  Paul Ricchiazzi                            jun93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/xhelp.pro)


XLESS

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:    xless

 PURPOSE:    create a text widget to scroll through a string array or
             a file

 USEAGE:     xless,text,file=file,space=space,xsize=xsize,ysize=ysize,$
                   xpad=xpad,ypad=ypad,title=title,font=font,group=group,$
                   unmanaged=unmanaged

 INPUT:
   text      string array containing text.  if TEXT is set FILE is ignored

 KEYWORD INPUT:
   file      pathname of text file to display
   space     space to put around text widget
   xsize     x size of text widget (characters)
   ysize     y size of text widget (lines)
   xpad      padding 
   ypad      padding
   title     title of text widget (default = XLESS)
   font      text font to use
   group     widget group leader 
   unmanaged don't put widget under control of the XMANAGER. This
             also means there will be no DONE button: to kill the widget
             use a XWINDOW manager command (EG, menu option "close")
             

 OUTPUT:
   none

 EXAMPLE:

; list a string array

             text=string(indgen(40)) & text(*)=text(*)+' this is a test'
             xless,text

             xless,text,/unman ; notice how control returns to the terminal
                               ; imediately after this command

; list a file
             
             xless,file=pickfile(/noconfirm)

 REVISIONS:

  author:  Paul Ricchiazzi                            Jul94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/xless.pro)


XMAKEDRAW

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:      xmakedraw

 PURPOSE:      create a simple draw widget with a done button

 USEAGE:       xmakedraw,group=group,x_window_size=x_window_size,$
                 y_window_size=y_window_size,widget_label=widget_label,$
                 make_draw_index=make_draw_index,nowait=nowait

 INPUT:        none required

 KEYWORD INPUT:

  group                widget id of parent widget 

  x_window_size        width of draw widget

  y_window_size        height of draw widget

  widget_label         widget label 

  base_id              widget id of base widget

  nowait               if set do not call xmanager, return immediately
                       after draw widget is realized

                       This keyword should be used when XMAKEDRAW is
                       not called by another widget procedure (see example)
 EXAMPLE:

; called from non-widget application (e.g., interactive input)

   xmakedraw,base_id=base_id,x_w=500,y_w=500,/nowait
   !p.multi=[0,2,2]
   loadct,5
   plot,dist(10)
   tvim,dist(100)
   plot,hanning(10,10)
   tvim,hanning(10,10)
   xmanager,'xmakedraw',base_id

;  in this example control is returned from the XMANAGER routine only
;  after the operator hits the DONE button.  If instead, this program
;  segment were called from another widget application, the highest
;  level call to the XMANAGER would supercede all lower level calls.
;  That is, program flow in not halted and normal widget event
;  processing would continue. In this case the NOWAIT parameter should
;  not be set and the call to XMANAGER is not required.
 
 Author:       Jeff Hicke                                      sep93
               Earth Space Research Group, UC Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/xmakedraw.pro)


XMAP

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:     xmap

 PURPOSE:     Display a world map and allow user to zoom in on a given region

 INPUT:       none
 OUTPUT:      none

                         INTERACTIVE CONTROLS:

 BUTTON EVENTS WITHIN MAP FRAME:

   Left mouse button --- Display lat-lon coordinates under cursor.

   Middle mouse button - Display distance between the last LMB click
                         and the current cursor position

   Right mouse button -- Enter region selection mode.  An interactive
                         cursor box appears.  The user selects the ZOOM
                         region by moving the cursor and using the
                         left/middle mouse buttons to decrease/increase
                         the box size.  Hitting the right mouse
                         button again selects the region, draws the
                         map and displays the MAP_SET command line
                         which duplicates the displayed map.  NOTE: to
                         improve performance, the whole world map is
                         drawn at low resolution whereas the zoomed
                         in maps are drawn at high resolution.

 BUTTONS:

 DONE
    quit XMAP

 WORLD
    Redisplay world map

 ROTATE
    Rotates the central longitude by 180 degrees.

 COLOR
    Adjust color values of lines used to indicate continental
    boundaries, US state boundaries, political boundaries, and
    rivers.

    NOTE: Color adjustment is accomplished via the PICKC widget.
    Motion of the cursor inside the PICKC window adjusts
    the Hue and Saturation values.  The intensity is adjusted
    with a horizontal slider.

 SPAWN
    Copy current map to a new window. The spawned window will
    remain visible after XMAP terminates.
              

 PRINT
    Pull down menu  
      TERM:     Print current map to device TERM 
      TREE:     Print current map to device TREE
      PSCOLOR:  Print current color map to device PSCOLOR
      BW PS:    create a BW postscript file named plot.ps
      COLOR PS: create a color postscript file named plotc.ps

 PATH
    trace a path on the map and compute total distance
    LMB adds a new path line segment
    MMB erases last path segment
    RMB computes total distance of path in km, and return to normal mode

 CITIES
    mark major city locations 

 HELP       
   Display this help file in a scrollable widget.


 TEXT WIDGET  (labeled WHERE IS:)
   Enter the latititude  longitude.   A symbol is drawn to
   indicate point on map.  NOTE: the code will bomb if you mess up
   the format

  author:  Paul Ricchiazzi                            Dec92
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/xmap.pro)


XMESSAGE

[Previous Routine] [Next Routine] [List of Routines]
 routine:      xmessage
 purpose:      create a simple set of widget labels

 useage:       xmessage,labels,charsize=charsize,wbase=wbase,group=group,$
                   title=title,kill=kill,relabel=relabel,wlabels=wlabels,$
                   done=done,font=font

 input:        
  labels       string array of labels

 keyword input:
  charsize     size of characters
               
  wbase        widget id of xmessage base widget
               
  group        widget id of parent widget 
               
  title        widget label 
               
  kill         kills xmessage widget if KILL is set to the value 
               of WBASE returned from a previous call of XMESSAGE
               
 relabel       scalor or integer array of widget id's.  Used to relabel
               xmessage labels, relabel should be set to the values
               (possibly a subset) of WLABELS from a previous call of
               XMESSAGE.  When XMESSAGE is used with RELABEL, the
               LABELS parameter should be set to a string array of
               the new labels

  done         if set, the XMESSAGE widget will have a "DONE" button
               which can be used to destroy the widget.  Otherwise
               the XMESSAGE widget is destroyed by calling XMESSAGE
               with the KILL keyword set to the XMESSAGE widget id.
               It is also destroyed when it is part of a widget
               hierarchy whose group leader is killed

  font         the hardware font used in the labels

 keyword output:
  wbase        widget id of xmessage base widget
  wlabels      widget id's of xmessage label widgets (intarr)

 EXAMPLE:

; create xmessage widget
   
    labels=['here is an example','of the xmessage widget']
    xmessage,labels,wbase=wbase,wlabel=wlabels

; relabel 2'nd label

    xmessage,'of The XMESSAGE WIDGET',relabel=wlabels(1)

; kill the message

    xmessage,kill=wbase

  author:  Paul Ricchiazzi                            Jan93
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/xmessage.pro)


XMULTI

[Previous Routine] [Next Routine] [List of Routines]
 routine:      xmulti

 purpose:      set up margins for horizontally stacked multi frame plot

 input:        

   p           named variable, contains stuff you don't need to know
               the contents of p are changed after each call
 
 Keyword input

   np          number of frames in plot, set on first call only

   xmargin     2 element vector specifying overall margin setting 
               left (0) and right (1) of the multiframe plot
               if xmargin is not set the left and right margin is taken
               from !x.margin. This keyword is ignored when NP not set

   space       space between frames of multiframe plots in units of 
               character width.  This keyword is ignored when NP not set


 SIDE EFFECTS: Changes the values !p.multi(4) to 0 to enforce row
               major ordering of plots. Also changes the value of
               !y.charsize to a very small value to disable y-axis
               labeling.  The original value of !y.charsize is
               restored when xmulti is called with no arguments,
               e.g., p=xmulti()
               

 EXAMPLE:      create a three frame plot stacked horizontally

 y1=randf(200,1.5)
 y2=randf(200,2)
 y3=randf(200,2.5)
 y4=randf(200,3)
 
 !p.multi=[0,3,1]
 plot,y1, xmargin=xmulti(p,np=3,xmargin=[5,3],space=1)
 plot,y2, xmargin=xmulti(p)
 plot,y3, xmargin=xmulti(p) & p=xmulti()

;  Now try a four frame plot with no space between frames

 !p.multi=[0,4,1]
 plot,y1,            xmargin=xmulti(p,np=4)
 plot,y2,            xmargin=xmulti(p)
 plot,smooth(y2,5),  xmargin=xmulti(p)
 plot,smooth(y2,7),  xmargin=xmulti(p) & p=xmulti()

;  now try two four frame plots on the same page
;

 !p.multi=[0,4,2]

 plot,y1,xmargin=xmulti(p,np=4,space=1) & xl=!x.window(0)
 plot,y2,xmargin=xmulti(p)
 plot,y3,xmargin=xmulti(p) 
 plot,y4,xmargin=xmulti(p) & p=xmulti()
 xl=(!x.window(1)+xl)/2
 yl=!y.window(1)+.5*!y.margin(1)*!d.y_ch_size/float(!d.y_vsize)
 xyouts,xl,yl,'top',align=.5,/norm

 plot,y1^2,xmargin=xmulti(p,np=4,space=1)
 plot,y2^2,xmargin=xmulti(p)
 plot,y3^2,xmargin=xmulti(p)
 plot,y4^2,xmargin=xmulti(p) &  p=xmulti()
 yl=!y.window(1)+.5*!y.margin(1)*!d.y_ch_size/float(!d.y_vsize)
 xyouts,xl,yl,'bottom',align=.5,/norm

  author:  Paul Ricchiazzi                            Mar94
           Institute for Computational Earth System Science
           University of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/xmulti.pro)


X_AXIS

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:  x_axis

 PURPOSE:  label x axis tick marks with the actual values of the x
           vector.  

 USEAGE:   x_axis,x,y,xticknames=xticknames,xtitle=xtitle, $
                  charsize=charsize,yspace=yspace,ticklen=ticklen, $
                  gridstyle=gridstyle,extend=extend

 INPUT:    
   x
     a vector of x-axis points (data coordinates) to label or mark

   y
     a scalor or two element vector. First element specifies the
     vertical subnormal coordinates of the x-axis line.  Y=0 puts
     x-axis at bottom of the plot while Y=1 puts x-axis at top of
     plot.  The second element, if present, specifies an additional
     vertical offset of the x-axis in units of the character
     height. (default=0)

 keyword input:
   xticknames
     string array of x axis tickmark labels, if not of type
     string, will be coerced into string


   xtitle
     x axis title, If XTICKNAME is undefined, XTITLE appears immediately
     below (YSPACE>0) or above (YSPACE<0) the x axis. Otherwise it
     appears below/above the XTICKNAME labels.

   yspace  
     controls vertical spacing between x-axis, tick labels and x-axis
     title.  By default the centerline of the tick labels appear 1
     character height below the x-axis while the x-axis title appears
     2.5 character heights below the x-axis.  The YSPACE factor
     multiplies these vertical offsets. YSPACE < 0 causes the titles
     to appear above the x-axis.  (default=1)

   ticklen   
     length of tickmarks as a PERCENTAGE of the entire y coordinate range
     TICKLEN=2 produces the standard major tickmark length, while
     TICKLEN=1 produces the standard minor tickmark length. (defualt=0)
     
   charsize
     character size used for x-axis annotation.  If more than two
     plots are ganged in either the X or Y direction, the character
     size is halved.
     
   extend
     if set and y lt 0 or y gt 1 then the y-axis lines are extended to 
     to intersect the new x-axis line.  This produces an enclosed
     rectangular area between the new x-axis and the old x-axis (if it
     exists).

   color
     color index used to color axis

   tcolor
     color index used to color axis and tick titles (just for the characters)

 DISCUSSION:
     Calling X_AXIS with no arguments causes the system variables
     !x.ticname and !x.ticklen to be reset to values which eliminate
     tickmarks and tick labeling on the following plot.  After the
     plot is drawn, X_AXIS is called again to draw the specified
     x-axis scale and reset the !x system variable.

 EXAMPLE:  

    
    y=randomn(iseed,6)^2 & y(0)=0 & y(5)=0
    x_axis
    plot,y,psym=10
    x_axis,1+findgen(5),xtitle='Surface type for 1993 field campagn', $
      xticknames=['dirt','snow','ocean','grass','forrest'],/ticklen

; x_axis may be called repeatedly to build up fairly
; elaborate x axis labeling 

    xx=findrng(1.5,7.5,100)
    x=2+indgen(6)
    x_axis
    plot,xx,planck(2^xx,200,/mic),ymargin=[10,10],/xstyle
    oplot,xx,planck(2^xx,190,/mic)
    oplot,xx,planck(2^xx,180,/mic)
    oplot,xx,planck(2^xx,170,/mic)
    x_axis,x,0,xtickn=2^x,ticklen=1,xtitle='wavelength (microns)'
    x_axis,x,[1,3],ysp=-.5,xtitle='test',charsize=1.3,/ext
    x_axis,x,1,xtickn=10000./2^x,ticklen=-1,yspace=-1,$
          xtitle='wavenumber (cm!a-1!n)'

; fancy log axis labeling

    v=.2*(20/.2)^(findgen(100)/99)
    w=-4*(.2/v)^2+ 2*(v/10) - 10*(v/10)^2 + 5*(v/10)^3
    x_axis
    plot_oi,v,w,/xsty & oplot,v,w^2,li=1 & oplot,v,w^3,li=2
    x_axis,[.2,.5,2,5,20],0,xtickname=['0.2','0.5','2','5','20'],/tickl
    x_axis,[1,10],0,xtickname=['1','10'],charsize=1.3,tickl=2
    x_axis,[.2+indgen(8)*.1,2+indgen(8)],0,/tickl


 AUTHOR:   Paul Ricchiazzi                        24 Aug 95
           Institute for Computational Earth System Science
           University of California, Santa Barbara
           paul@icess.ucsb.edu

 REVISIONS:

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/x_axis.pro)


YMD2JD

[Previous Routine] [Next Routine] [List of Routines]
 NAME:
       YMD2JD
 PURPOSE:
       From Year, Month, and Day compute Julian Day number.
 CATEGORY:
 CALLING SEQUENCE:
       jd = ymd2jd(y,m,d)
 INPUTS:
       y = Year (like 1987).                    in
       m = month (like 7 for July).             in
       d = month day (like 23).                 in
 KEYWORD PARAMETERS:
 OUTPUTS:
       jd = Julian Day number (like 2447000).   out
 COMMON BLOCKS:
 NOTES:
 MODIFICATION HISTORY:
       R. Sterner,  23 June, 1985 --- converted from FORTRAN.
       Johns Hopkins University Applied Physics Laboratory.
       RES 18 Sep, 1989 --- converted to SUN

 Copyright (C) 1985, Johns Hopkins University/Applied Physics Laboratory
 This software may be used, copied, or redistributed as long as it is not
 sold and this copyright notice is reproduced on each copy made.  This
 routine is provided as is without any express or implied warranties
 whatsoever.  Other limitations apply as described in the file disclaimer.txt.

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/ymd2jd.pro)


YMULTI

[Previous Routine] [Next Routine] [List of Routines]
 routine:      ymulti

 purpose:      set up margins for vertically stacked multi frame plot 

 input:        

   p           named variable, contains stuff you don't need to know
               the contents of p are changed after each call
 
 Keyword input

   np          number of frames in plot, set on first call only (see examples)

   ymargin     2 element vector specifying overall margin setting 
               below (0) and above (1) multiframe plot
               if ymargin is not set the top and bot margin is taken
               from !y.margin.  This keyword is ignored when NP not set

   space       the separation distance between frames of a multiframe
               plot in units of the character height. This keyword is
               ignored when NP not set. Default is no space between plots


 SIDE EFFECTS: Changes the value of !p.multi(4) to enforce column
               major ordering of plots.  To reinsate the default row
               major ordering, set !p.multi=0 or !p.multi(4)=0.  Also
               changes the value of !x.charsize to a very small value
               to disable x-axis labeling on the upper frames.  On
               the bottom frame of a multi-frame plot !x.charsize is
               restored to its original value.

 EXAMPLE:      create a three frame plot

 y1=smooth(randomu(iseed,200),3)
 y2=smooth(y1,11)
 y3=smooth(randomu(iseed,200),11)
 y4=smooth(y3,3)
 
 !p.multi=[0,1,3]
 plot,y1,ymargin=ymulti(p,np=3,ymargin=[5,3],space=1)
 plot,y2,ymargin=ymulti(p)
 plot,y3,ymargin=ymulti(p)

;  Now try a four frame plot with no space between frames

 !p.multi=[0,1,4]
 plot,y1, ymargin=ymulti(p,np=4)
 plot,y2, ymargin=ymulti(p)
 plot,y3, ymargin=ymulti(p)
 plot,y4, ymargin=ymulti(p) 

;  Now try a multi-column plot

 !p.multi=[0,2,4] 

 plot,y1,title='top left',ymar=ymulti(p,np=2)
 plot,y2,ymargin=ymulti(p)

 plot,y3, title='bottom left',ymar=ymulti(p,np=2)
 plot,y4, ymargin=ymulti(p)

 plot,y1*y1, title='top right',ymar=ymulti(p,np=2)
 plot,y2*y2, ymargin=ymulti(p)

 plot,y3^2,  title='bottom right',ymar=ymulti(p,np=2)
 plot,y4^2,  ymargin=ymulti(p)


 AUTHOR        Paul Ricchiazzi                                    mar94
               Institute for Computational Earth System Science
               Univerity of California, Santa Barbara

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/ymulti.pro)


ZENDAY

[Previous Routine] [Next Routine] [List of Routines]
 purpose:      compute daylight average of solar zenith, daylight
               hours per day and maximum solar zenith as a function of
               latitude and day of year

 useage:       zenday,day,lat,mubar,mumax,hours

 input:
   day         day of year
   lat         latitude

 output:
   mubar       cosine of solar zenith angle (SZA) averaged over 
               daylight hours

   mumax       maximum value of cos(SZA)

   hours       hours of sunlight 

               NOTE: mubar*hours*Fo = average daily insolance

                     where Fo is the solar constant

 EXAMPLE:      as a function of latitude and season make plots of 
;
;                         1. hours of sunlight
;                         2. average daylight value of cos(SZA)
;                         3. daily average insolation
;                         4. maximum cos(SZA)
      
    !p.multi=[0,2,2]
    day = findgen(365)+1
    lat=findrng(-90,90,37)
    gengrid,day,lat
    zenday,day,lat,mubar,mumax,hours

    ytickv=[-90,-75,-60,-45,-30,-15,0,15,30,45,60,75,90] & ytitle='Latitude'
    contour, hours,day,lat, ytitle=ytitle,xstyle=5,/follow,$
    ytickv=ytickv,yticks=14,levels=indgen(25),$
    title='Daylight Hours'
    xaxis_month
    contour, mubar,day,lat, ytitle=ytitle,xstyle=5,/follow,$
    ytickv=ytickv,yticks=14,levels=indgen(20)*.05,$
    title='Average Daylight cos(zenith)'
    xaxis_month
    contour, 1371*hours*mubar/24.,day,lat, ytitle=ytitle,xstyle=5,/follow,$
    ytickv=ytickv,yticks=14,levels=indgen(12)*50,$
    title='Daily Average Insolation (W/m2)'
    xaxis_month
    contour, mumax,day,lat, ytitle=ytitle,xstyle=5,/follow,$
    ytickv=ytickv,yticks=14,levels=indgen(20)*.05,$
    title='Maximum cos(zenith)'
    xaxis_month

;
  AUTHOR:      Paul Ricchiazzi        23oct92
               Earth Space Research Group,  UCSB
 

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/zenday.pro)


ZENSUN

[Previous Routine] [Next Routine] [List of Routines]
 ROUTINE:      zensun

 PURPOSE:      Compute solar position information as a function of
               geographic coordinates, date and time.
               
 USEAGE:       zensun,day,time,lat,lon,zenith,azimuth,solfac,sunrise,sunset,
                  local=local

 INPUT:
   day         Julian day (positive scalar or vector)
               (spring equinox =  80)
               (summer solstice= 171)
               (fall equinox   = 266)
               (winter solstice= 356)

   time        Universal Time in hours (scalar or vector) 

   lat         geographic latitude of point on earth's surface (degrees)

   lon         geographic longitude of point on earth's surface (degrees)

 OUTPUT:

   zenith      solar zenith angle (degrees)

   azimuth     solar azimuth  (degrees) 
               Azimuth is measured clockwise from due north 

   solfac      Solar flux multiplier.  SOLFAC=cosine(ZENITH)/RSUN^2
               where rsun is the current earth-sun distance in
               astronomical units.

               NOTE: SOLFAC is negative when the sun is below the horizon 


 KEYWORD INPUT:

   local       if set, TIME is specified as a local time and SUNRISE
               and SUNSET are output in terms of local time
 
               NOTE: "local time" is defined as UT + local_offset
                     where local_offset is fix((lon+sign(lon)*7.5)/15)
                     with -180 < lon < 180

                     Be aware, there are no fancy provisions for
                     day-light savings time and other such nonsense.

 KEYWORD OUTPUT:

   sunrise     Time of sunrise (hours)
   sunset      Time of sunset  (hours)

   latsun      the latitude of the sub-solar point (fairly constant over day)
               Note that daily_minimum_zenith=abs(latsun-lat)

   lonsun      the longitude of the sub-solar point
               Note that at 12 noon local time (lon-lonsun)/15. is the
               number of minutes by which the sun leads the clock.

;              Often used           lat,   lon 

               Santa Barbara:        34.410,-119.727
               SGP Cart Site:        36.605,-97.485
               North Slope:          69.318,-151.015
               Palmer Station:       -64.767,-64.067
 
; EXAMPLE 1:   Compute the solar flux at Palmer Station for day 283

               time=findgen(1+24*60)/60
               zensun,283,time,-64.767,-64.067,z,a,sf
               solflx=sf*s
               plot,time,solflx

               where s is the TOA solar irradiance at normal incidence:

               s=1618.8   ; W/m2/micron for AVHRR1 GTR100 
               s= 976.9   ; W/m2/micron for AVHRR2 GTR100
               s=1685.1   ; W/m2/micron for 410nm GTR100
               s= 826.0   ; W/m2/micron for 936nm GTR100
               s=1.257e17 ; photons/cm2/s PAR GTR100
               s=1372.9   ; w/m2 total broadband


; EXAMPLE 2:   Find time of sunrise and sunset for current day
 
     doy=julday()-julday(1,0,1994)                          
     zensun,doy,12,34.456,-119.813,z,a,s,sunrise=sr,sunset=ss,/local &$
     zensun,doy,[sr,.5*(sr+ss),ss],34.456,-119.813,z,az,/local &$
     print,'sunrise: '+hms(3600*sr)+      ' PST   azimuth angle: ',az(0)  &$
     print,'sunset:  '+hms(3600*ss)+      ' PST   azimuth angle: ',az(2)  &$
     print,'zenith:  '+hms(1800*(ss+sr))+ ' PST   zenith angle:  ',z(1) 
   
  AUTHOR:      Paul Ricchiazzi        23oct92
               Earth Space Research Group,  UCSB
 
  REVISIONS:
  
 jan94: use spline fit to interpolate on EQT and DEC tables
 jan94: output SUNRISE and SUNSET, allow input/output in terms of local time 
 jan97: declare eqtime and decang as floats.  previous version 
         this caused small offsets in the time of minimum solar zenith

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/zensun.pro)


ZOOMBAR

[Previous Routine] [List of Routines]
 NAME:
	zoombar

 USEAGE:    while zoombar(range) do ...

 PURPOSE:
	Emulate the operation of a variable-sized box cursor (also known as
	a "marquee" selector).

 CATEGORY:
	Interactive graphics.

 CALLING SEQUENCE:
	result = zoombar(range, INIT=init,message=message,$
                        ybar=ybar,xbar=xbar)

 INPUTS:
	No required input parameters.

 OPTIONAL INPUT PARAMETERS:
	x0, y0, nx, and ny give the initial location (x0, y0) and 
	size (nx, ny) of the box if the keyword INIT is set.  Otherwise, the 
	box is initially drawn in the center of the screen.

 KEYWORD PARAMETERS:

  INIT
    Sets the initial x or y range of the cursor bar.  INIT should be
    specified in data coordinates.

  ybar
    If this keyword is set, the horizontal size of the box
    is fixed.  Set this keyword to set vertical range

  xbar
    If this keyword is set, the vertical size of the box
    is fixed.  Set this keyword to set horizontal range
    (default)

  message
    if set, an instructional pop-up widget appear
    if MESSAGE is a string or string array, the contents of
    MESSAGE are pre-pended to ZOOMBARs default instructions.
                 

 OUTPUTS:
    result: 1 if exit is caused by RMB clicked inside bar
    result: 0 if exit is caused by RMB clicked outside bar

    range:  the vertical (if ybar is set)  or horizontal 
               (if xbar is set) range of the cursor bar.

 COMMON BLOCKS:
       None.

 SIDE EFFECTS:
       A box is drawn in the currently active window.  It is erased
       on exit.

 RESTRICTIONS:
       Works only with window system drivers.

 PROCEDURE:
       The graphics function is set to 6 for eXclusive OR.  This
       allows the box to be drawn and erased without disturbing the
       contents of the window.

       Operation is as follows:

       Left mouse button:   Move the box by dragging.

       Middle mouse button: Resize the box by dragging.  The corner
               nearest the initial mouse position is moved.

       Right mouse button:  Exit this procedure, returning the 
                            current xrange or yrange parameters.  
                            RMB click inside the bar,  return value = 1
                            RMB click outside the bar, return value = 0

;; Example:  

    x=randf(1000,1.5) & plot,x & while zoombar(r,/mes) do plot,x,xr=r,/xst 

;; select range in one window, plot zoomed plot in another:

  window,1 & wset,0 & x=randf(1000,1.5) & plot,x & xs=!x & r=0
  while zoombar(r,/mes,init=r) do begin &$
     wset,1 & plot,x,xr=r & !x=xs & wset,0 & end

(See /host/bluemoon/usr2/idllib/contrib/esrg_ucsb/zoombar.pro)