pro monitor_exp,Date,Lz,Tel
;
;+
; NAME:
;	MONITOR_EXP
;
; PURPOSE:
;	This procedure reads all the files for a given date and processes
;	the image to give statistical information for exposure monitoring.
;
; CATEGORY:
;	DATA_ANAL
;
; CALLING SEQUENCE:
;	MONITOR_EXP,Date,Lz
;
; INPUTS:
;	Date:	Gives the date to be processed in one of the following formats:
;			YYMMDD,	6 character string
;			YYYY/MM/DD, 10 character string
;			CDS Date Structure
;			Long Word of the modified julian date
;	Lz:	0 for Quick-look, 1 for Level-0
;
; OPTIONAL INPUTS:
;	Tel:	The telesope designation (string):  c1, c2, c3, c4/eit
;		The default is all three LASCO telescopes.
;
; KEYWORD PARAMETERS:
;	None
;
; OUTPUTS:
;	None.
;
; SIDE EFFECTS:
;	Appends the information to files in $MON_EXP with the file name
;	telstr_monexp_YYMMDD.dat, where telstr is a string denoting the telscope
;	and YYMMDD are 6 digits giving the year, month and day of the data:
;		eg.   c1_monexp_961231.dat
;		      c2_monexp_961231.dat
;		      c3_monexp_961231.dat
;	(records) in the .dat file.
;
; RESTRICTIONS:
;
; PROCEDURE:
;
; EXAMPLE:
;	To process the exposure monitoring information for 1 Sep 1996 quick
;	look data:
;
;		MONITOR_EXP,'960901',0
;	or
;		MONITOR_EXP,'1996/09/01',0
;	or
;		MONITOR_EXP,mjd,0
;	or
;		MONITOR_EXP,mjd.mjd,0
;
; MODIFICATION HISTORY:
; 	Written by:	R.A. Howard, NRL, 10/3/96
;	Modified by:	J. S. Morrill, NRL, 4/8/97
;	Modified by:	RAH, 5/22/97, error handling for missing directories
;	Modified by:	RAH, 5/22/97, split out loop to monitor_exp_img
;
; @(#)monitor_exp.pro	1.7 06/02/97 :NRL Solar Physics
;
;-
;
;  Find out which telescope is requested
;
np = N_PARAMS()
IF (np EQ 2)  THEN BEGIN
   ntel = 3
   telstr = ['c1','c2','c3']
ENDIF ELSE BEGIN
   ntel = 1
   ttel = STRLOWCASE(tel)
   IF (ttel EQ 'eit')  THEN ttel='c4'
   IF (STRPOS('c1c2c3c4',ttel) LT 0)    THEN BEGIN
      PRINT,'ERROR:  Unrecognized telescope'
      RETURN
   ENDIF
   telstr = [ttel]
ENDELSE
blank = '               '		; a 15 character blank string
;
;  Generate the modified julian date from the input date after
;  finding out what format the input date is in
;
CASE datatype(date) OF
     'STR':  BEGIN
                IF (STRLEN(date) EQ 6) THEN BEGIN
                   d = STRMID(date,0,2)
                   IF (FIX(d) LT 99)  THEN pre='19' ELSE pre='20'
                   d = pre+d+'/'+STRMID(date,2,2)+'/'+STRMID(date,4,2)
                ENDIF ELSE d = date
                mjd = STR2UTC(d)
              END
      'LON':  BEGIN
                 get_utc,mjd
                 mjd.mjd = date
                 mjd.time = 0
              END
      'STC':  mjd = date
ENDCASE
CASE lz OF
   0:  BEGIN
          IF (GETENV('QL_IMG') NE '')  THEN BEGIN
             CD,GETENV('QL_IMG'),curr=old
          ENDIF ELSE BEGIN
             CD,'/net/corona/cplex1/flight_data',curr=old
          ENDELSE
       END
   1:  BEGIN
          IF (GETENV('LZ_IMG') NE '')  THEN BEGIN
             CD,GETENV('LZ_IMG'),curr=old
          ENDIF ELSE BEGIN
             CD,'/net/corona/cplex2/lz_data',curr=old
          ENDELSE
       END
ENDCASE
dd = UTC2YYMMDD(mjd)
PRINT,'Processing date = '+dd
CD,'level_05'
f = FINDFILE(dd)
IF (f(0) NE '')  THEN BEGIN
   CD,dd
   FOR i=0,ntel-1 DO BEGIN
       f = FINDFILE(telstr(i))
       IF (f(0) NE '') THEN BEGIN
       CD,telstr(i),curr=top
       print,'Processing telescope = '+telstr(i)
       ff = FINDFILE ('*.fts')
       sz = SIZE (ff)
       IF (sz(0) GT 0)  THEN BEGIN
          n = n_elements(ff)
          IF (n GT 0) THEN BEGIN
;
;  Read in each image and compute the standard monitoring quantities
;
             FOR j=0,n-1 DO BEGIN
                 MONITOR_EXP_IMG,ff(j)
             ENDFOR
          ENDIF
       ENDIF
       CD,top
       ENDIF
   ENDFOR
ENDIF
cd,old
RETURN
END

