Viewing contents of file '../idllib/ghrs/pro/confind.pro'
;************************************************************************
;+
;*NAME:
;     CONFIND   (General IDL Library 01) 
;  
;*CLASS:
;     User i/o; curve fitting
;  
;*CATEGORY:
;  
;*PURPOSE:
;     procedure to select continuum points in a spectrum. CONFIND is a
;     modified version of the front end of NORM which uses the interactive
;     graphics cursor to pick out points for later continuum fitting.
;  
;*CALLING SEQUENCE:
;     CONFIND,WAVE,FLUX,WCONT,FCONT
;  
;*PARAMETERS:
;     WAVE   (REQ) (I) (1) (F D)
;            Required input vector containing the wavelength data for the
;            spectrum of interest.
;     FLUX   (REQ) (I) (1) (F D)
;            Required input vector containing the flux data.
;     WCONT  (REQ) (O) (1) (F D)
;            Required output vector containing the wavelengths of the
;            selected points.
;     FCONT  (REQ) (O) (1) (F D)
;            Required output vector containing the fluxes of the selected
;            points.
;
;*EXAMPLES:
;     To pick central wavelengths for continuum bandpasses:
;     CONFIND,WAVE,FLUX,WCONT,FCONT
;     then specify widths of bandpasses in vector WIDTHS
;     BINS,WAVE,FLUX,WCONT,WIDTHS,WMEAN,WSIG,WGT
;
;     To select continuum points for normalization:
;     CONFIND,WAVE,FLUX,WCONT,FCONT
;
;*SYSTEM VARIABLES USED:
;     !ERR
;     !CXMIN
;     !CXMAX
;     !CYMIN
;     !CYMAX
;     !ILAS
;     !XMIN
;     !XMAX
;     !YMIN
;     !YMAX
;  
;*INTERACTIVE INPUT:
;     User is prompted for rescaling plot of wave vs flux
;     The user also selects the continuum points via the graphics cursor.
;
;*FILES USED:
;     None  
;  
;*SUBROUTINES CALLED:
;     PARCHECK
;     SCTODC
;
;*SIDE EFFECTS:
;     If aborted, some system variables may be reset.
;  
;*RESTRICTIONS:
;     Device Dependent - This procedure requires a graphics cursor.
;  
;*NOTES:
;     !FANCY should be =0 before beginning this procedure, as the
;     fancy graphics conflict with cursor commands.
;
;*PROCEDURE:
;     The user views the spectrum, and is given the opportunity to
;     rescale the plot. This is done iteratively until the user indicates
;     satisfaction by typing 0 (no more rescaling).
;
;     Next, while viewing the spectrum, the users marks points corresponding
;     to the continuum with the graphics cursor. Points can be added until
;     the user types 0. The data x and y coordinates of the points are 
;     calculated from the screen locations of the cursor.
;  
;*INF_1:
;  
;*MODIFICATION HISTORY:
;     May    1985  CAG GSFC wrote procedure based on NORM
;     Jun  6 1985  RWT GSFC allowed exit from CONFIND
;     Jun 11 1985  RWT GSFC modified user prompt for continuum points
;     Apr 13 1987  RWT GSFC use vector assignment statements, remove
;                           INSERT and EXTRACT commands, and use XYOUTS
;                           for XYOUT.
;     May 22 1987  RWT GSFC improve sorting 
;     Mar  1 1988  RWT GSFC make CONFIND a separate procedure
;     Mar  8 1988  CAG GSFC added VAX RDAF-style prolog, printing calling
;                           sequence if no parameters are specified, and
;                           check for minimum number of parameters.
;     1/08/90 RWT UNIX mods: convert to lower-case,
;     Mar 4 1991      JKF/ACC    - moved to GHRS DAF (IDL Version 2)
;
;-
;************************************************************************
pro confind,wave,flux,wcont,fcont
;
; ck. parameters and initialize variables
;
if n_params(0) eq 0 then begin
    print,' confind,wave,flux,wcont,fcont'
    retall & end
parcheck,n_params(0),4,'confind'
n  = 0 
ix = fltarr(1)
iy = ix
tx = (total(!x.crange))/2
ty = (total(!y.crange))/2
yn=' '
!err="61
vpos = !d.y_size - !d.y_ch_size
vspace = 1.1 * !d.y_ch_size
hpos = !d.x_ch_size
;
; plot rescaling section (useful in emission line spectra)
;
plot,wave,flux
read,' Are you satisfied with plot scale (y or n)?',yn
yesno,yn
while (not yn) do begin
     read,' enter xmin and max:',xmin,xmax
     read,' enter ymin and max:',ymin,ymax
     plot,wave,flux,XRANGE=[xmin,xmax],YRANGE=[ymin,ymax]
     yn=''
     read,' Are you satisfied with plot scale now (y or n)?',yn
     yesno,yn
     end
;
; plot wave vs flux with directions for user to define continuum
; Let user set cross hairs to define continuum
; For SUN monitors, select pt = 1, replot = 2, finished = 4
;
while (!err ne "60) and (!err ne 4) do begin   ;(note: "60=asci 0 & "61=asci 1)
     if (!err eq "61) or (!err eq 2) then begin
       xyouts,hpos,vpos-2.2*vspace,' '
       if !d.name eq 'TEK' then begin
       print,'  to select point, move cursor to point and press space bar'
       print,'  to abort,              type 2 '
       print,'  to replot last point,  type 1 '
       print,'  if finished,           type 0 '
       end else begin
       print,' '
       print,'  to select point, move cursor to point and press left button'
       print,'  to replot last point,  press middle mouse button'
       print,'  if finished,           press right mouse button'
       print,' '
       end
       if n ge 2 then oplot,ix,iy
       end
     flush = get_kbrd(0)
     cursor,tx,ty,/down,/DATA  ;read cursor
     if !err eq "62 then retall
     if (!err ne "61) and (!err ne 2) then begin
         if (!err ne "60) and (!err ne 4) then begin ; get point
           ; sort values into ascending order
           n=n+1    ;# of points 
           x=fltarr(n)
           x(0) = ix
           x(n-1) = tx
           ind = sort(x)
           ix = x(ind)
           x(0) = iy
           x(n-1) = ty
           iy = x(ind)
           if n ge 2 then oplot,ix,iy,psym=0    ;plot continuum
           !err=0   ;force one more point
           end   ;got point
       end   ;!err ne "61 or 2
     end   ;!err ne "60 or 4
;
; define output variables and return
;
wcont  = ix
fcont  = iy
return
end   ; confind