Viewing contents of file '../idllib/iuedac/iuelib/pro/getsamp.pro'
;****************************************************************************
;+
;*NAME:
;
;     GETSAMP   (General IDL Library 01)  December 12, 1986
;
;*CLASS:
;
;     unit conversion
;
;*CATEGORY:
; 
;*PURPOSE:  
;
;     To convert wavelength limits to nearest sample numbers.
; 
;*CALLING SEQUENCE:
;
;     GETSAMP,WMIN,WMAX,W,SMIN,SMAX
; 
;*PARAMETERS:
;
;     WMIN  (REQ) (I) (0) (F D)
;           Required input scalar containing the starting wavelength in
;           the same units as W.
;
;     WMAX  (REQ) (I) (0) (F D)
;           Required input scalar containing the ending wavelength in the
;           same units as W.
;
;     W     (REQ) (I) (1) (F D)
;           Required input wavelength vector.
;
;     SMIN  (REQ) (O) (0) (F D) 
;           Required output scalar containing the sample number corresponding
;           to WMIN.
;
;     SMAX  (REQ) (O) (0) (F D)
;           Required output scalar containing the sample number corresponding
;           to WMAX.
;
;*EXAMPLES:
;
;     To calculate the sample value equivalents of 1300 angstroms and 1500
;     angstroms from the array W:
;        GETSAMP,1300,1500,W,SMIN,SMAX
;
;*SYSTEM VARIABLES USED:
;
;*INTERACTIVE INPUT:
;
;*SUBROUTINES CALLED:
;
;     PARCHECK
;     TABINV
; 
;*FILES USED:
;
;*SIDE EFFECTS:
;
;     If WMIN and WMAX are beyond the wavelength range of W, they are
;     reset to be MIN(W) and MAX(W).
;
;*RESTRICTIONS:
;
;*NOTES:
;
;	tested with IDL Version 2.1.0 (sunos sparc)  	20 Jun 91
;	tested with IDL Version 2.1.0 (ultrix mispel)	N/A
;	tested with IDL Version 2.1.0 (vms vax)      	21 Jun 91
;
;*PROCEDURE:
;
;     GETSAMP compares WMIN and WMAX to the actual min and max values of
;     W. If either is out of the range of W it is reassigned as the real
;     limit. TABINV is called to calculate the actual indice values.
; 
;*MODIFICATION HISTORY:
;
;     Sep 23 1984  GAR  GSFC  initial program
;     Jan 21 1985  RWT  GSFC  use TABINV for SMIN and SMAX calculation
;     Nov 18 1986  RWT  GSFC  add W as an input parameter, and delete
;                             opening file internally.
;     Apr 13 1987  RWT  GSFC  VAX Mods: add PARCHECK
;     Aug 19 1987  RWT  GSFC  add procedure call listing
;     Mar 10 1988  CAG  GSFC  add VAX RDAF-style prolog.
;     Jun 21 1991  PJL  GSFC  cleaned up; tested on SUN and VAX; 
;			      updated prolog
;
;-
;***********************************************************************
 pro getsamp,wmin,wmax,w,smin,smax
;
 if n_params(0) eq 0 then begin
    print,' GETSAMP,WMIN,WMAX,W,SMIN,SMAX'
    retall
 endif  ; n_params(0)
 parcheck,n_params(0),5,'GETSAMP'
 smin=0 & smax=0
 lpt = n_elements(w) - 1
;
; change wmin & wmax if not within wavelength range
; use tabinv to convert wmin & wmax to smin & smax
;
 if wmin lt w(0) then begin
    wmin = w(0)
    print,'minimum wavelength changed to',wmin
 endif  ; wmin
 tabinv,w,wmin,smin
 smin=fix(smin+0.5)
;
 if wmax gt w(lpt) then begin
    wmax = w(lpt) & smax = lpt
    print,'maximum wavelength changed to',wmax
    return
 endif  ; wmax
 tabinv,w,wmax,smax
 smax=fix(smax+0.5)
 return
 end  ; getsamp