

PRO eis_get_exposure_info, obj, nexp_prp=nexp_prp,exp_times=exp_times,delay_times=delay_times, $
                           tot_exposures=tot_exposures, npos=npos

;+
; NAME
;
;   EIS_GET_EXPOSURE_INFO
;
; PROJECT
;
;   Hinode/EIS
;
; EXPLANATION
;
;   It's not easy to get exposure time information from an EIS
;   object, so this routine gets the information from the raster
;   database. 
;
; INPUTS
;
;   OBJ   Can be either an EIS data object, or an EIS raster ID (an
;         integer). 
;
; OPTIONAL OUTPUTS
;
;   **For interpreting the various outputs, please be aware of how EIS
;   works. EIS can have up to 8 different exposure times for each slit
;   position (usually only one is used). After each exposure a delay
;   time can be set in which EIS will be remain idle (delay time
;   usually set to zero). EIS can operate in either a raster mode or a
;   sit-and-stare mode.**
;
;   NEXP_PRP  Number of exposures per raster position.
;
;   EXP_TIMES  An 8 element array giving the exposure times (seconds)
;              used. For most rasters, only the first element will be
;              non-zero. 
;
;   DELAY_TIMES   An 8 element array giving the delay time (seconds)
;            used. For most rasters all the elements will be zero. The
;            delay time is a time specified by the raster designer for
;            which EIS will remain idle before the next exposure
;            starts.  
;
;   TOT_EXPOSURES  The total number of exposures for the raster.
;
;   NPOS  This is either the number of scan positions in the case
;         of a raster, or the number of repeated exposure sets for
;         a sit-and-stare study.
;
; EXAMPLE
;
;   For a raster with 50 scan positions and 1 exposure per scan
;   position with 30s exposure time, the outputs from this routine
;   will be: 
;
;   NEXP_PRP=1
;   EXP_TIMES[0]=30
;   TOT_EXPOSURES=50
;   NPOS=50
;
;   For a raster with 30 scan positions and 3 exposures per scan
;   position with 10, 20 and 30s per exposure time, the outputs from
;   this routine will be:
;
;   NEXP_PRP=3
;   EXP_TIMES[0]=10, EXP_TIMES[1]=20, EXP_TIMES[2]=30
;   TOT_EXPOSURES=90
;   NPOS=30
;
; CALLS
;
;   DBFIND, DBOPEN, DBCLOSE, DBEXT
;
; HISTORY
;
;   Ver.1, 24-May-2012, Peter Young
;-

IF n_params() EQ 0 THEN BEGIN
  print,'Use:  IDL> eis_get_exposure_info, obj [, nexp_prp=, exp_times=, delay_times=, tot_exposures='
  print,'                            npos= ]'
  RETURN
ENDIF 

CASE datatype(obj) OF
  'OBJ': rast_id=obj->getinfo('RAST_ID')
  'LON': rast_id=obj
  'INT': rast_id=obj
  ELSE: BEGIN
    print,'%EIS_GET_EXPOSURE_INFO: the input OBJ should be either an EIS data object or an integer that '
    print,'                        specifies the raster ID number.'
    return 
  END 
ENDCASE 

dbrast=getenv('SSW')+'/hinode/eis/database/planning_db/technical_db/eis_raster_db'

dbopen,dbrast
query='id = '+trim(rast_id)
list=dbfind(query,/silent)
dbext,list,'nexp,exposures,delays,scan_fm_nsteps,scan_fm_stepsize,sns_nexps,rastertype', $
      nexp_prp,exp_times,delay_times,scan_fm_nsteps,scan_fm_stepsize,sns_nexps,rastertype
dbclose,dbrast

;
; exp_times and delay_times are stored in milli-seconds in the database,
; therefore convert to seconds.
;
exp_times=float(exp_times)/1000.
delay_times=float(delay_times)/1000.


IF rastertype EQ 0 THEN BEGIN   ; scanning
  tot_exposures=nexp_prp*scan_fm_nsteps 
  npos=scan_fm_nsteps
ENDIF ELSE BEGIN   ; sit-and-stare
  tot_exposures=nexp_prp*sns_nexps
  npos=sns_nexps
ENDELSE 

END
