pro mk_obs, infil0, outfil, fullweek=fullweek, run_time=run_time, $
	append=append, qdebug=qdebug, qstop=qstop, usefid=usefid, indir=indir
;
;+
;NAME:
;	mk_obs
;PURPOSE:
;	Make the observing log file
;INPUT:
;	infil	- an array of input files of a single prefix, usually
;		  the "ada" file.
;	outfil	- the output file name
;OPTIONAL INPUT:
;	fullweek- if present, and specifying the week in 
;		  the string form 91_49 where 91 is the year
;		  and 49 is the week number, it will generate
;		  the input file array and output file
;	qdebu	- If set, print several diagnostic messages
;METHOD:
;	It checks each instrument to see if the file exists. (BCS, HXT, SXT, WBS)
;	Output: SXT - Every exposure (no more often than every major frame)
;		WBS,HXT		* Every 2 MF (4 sec) in high rate
;				* Every 1 MF (8 sec) in med rate (?)
;				* Write out the first MF when a rate or mode 
;				  change occurs
;				* Write out in night? or just single entry
;		BCS		* Combining several spectra, not to be written
;				  out more often than every 4 sec
;
;	NOTES:  Could key off WBS (since it is every 2 MF, and follows the
;		"same" rules as observing log), but what if it is not on
;		for a given orbit, and there is BCS and HXT data.
;Modification History:
;	Ver 0.20 31-Jan-92 (MDM) - added capability to copy the observing log file
;				  to the $DIR_GEN_OBS directory
;	Ver 0.30 13-Feb-92 (MDM) - changed input to be an array of filenames
;				(not the name of a file holding the list of FIDs)
;				Removed the need for "DIR_IN" parameter
;				Expanded the /FULL_WEEK option accordingly
;			     Made OBS file be written directly to $DIR_GEN_OBS, not
;			     to the data directory
;	Ver 1.00 29-Feb-92 (MDM) - changed WBS and HXT insertion of information
;				to be SQRT of summary counts.  It was overflowing
;				the byte value before (integer*2 value being put
;				into a byte)
;	Ver 1.01   1-Mar-92 (MDM) - Changed BCS reading from RD_BDA (it was reading
;				all data!!) to RD_ROADMAP and RD_BDA_DP.
;	Ver 1.02   3-Mar-92 (MDM) - Made ALL_CNTS and ACC_CNTS for BCS the SQRT of
;                         the DP_SYNC record value (to fit into one byte)
;	Ver 1.03  18-Apr-92 (MDM) - Adjusted to use UNIQ_FID instead of getting
;				a list of the FileIDs from "findfile('ada*')"
;	Ver 1.04  26-May-92 (MDM) - Changed to write a temporary file and then
;                           move it to on-line after finished generating it
;	Ver 1.05  14-Oct-92 (MDM) - Modified to allow appending to an existing
;				    OBS file.
;	Ver 1.06  15-Oct-92 (MDM) - Added /QDEBUG and had print statements only
;				    occur when QDEBUG is set
;	Ver 1.07  22-Oct-92 (MDM) - Added /QSTOP option
;				  - Moved NORBIT=0 command since if an append
;				    option was overridden (Files out of order)
;				    then it was appending to the ORBIT_ARR
;				    incorrectly.
;				  - Added /USEFID switch.  This will force the
;				    ORBIT_ARRAY time/day entry to be the input
;				    FileID.  This should only be used when
;				    generating temporary OBS logs
;       Ver 1.08 11-Nov-92 (MDM)  - Use the LAST file in "infil" to figure
;                                   out the week number when the output file
;                                   is not specified.
;				  -
;	Ver 1.09 27-Jan-93 (MDM)  - Appending option not working quite right
;	Ver 1.10  3-May-93 (MDM)  - Error in FULLWEEK option
;	********************************************************************
;	Ver 2.0  14-May-93 (MDM) -  Re-written to use MK_WEEK_FILE and to have
;				    separate OBS files per instrument
;				 -  Added INDIR option
;-
;
progVerNo = 2.001000
progName = 'MK_OBS.PRO'
;
if (n_elements(infil0) ne 0) then begin
    break_file, infil0, dsk_log, dir, filnam, ext
    infil1 = dsk_log + dir + 'bda' + strmid(filnam, 3, 6) + ext
    infil2 = dsk_log + dir + 'sfr' + strmid(filnam, 3, 6) + ext
    infil3 = dsk_log + dir + 'spr' + strmid(filnam, 3, 6) + ext
    infil4 = dsk_log + dir + 'wda' + strmid(filnam, 3, 6) + ext
    ss = where(file_exist(infil1)) & if (ss(0) ne -1) then infil1 = infil1(ss) else infil1 = ''
    ss = where(file_exist(infil2)) & if (ss(0) ne -1) then infil2 = infil2(ss) else infil2 = ''
    ss = where(file_exist(infil3)) & if (ss(0) ne -1) then infil3 = infil3(ss) else infil3 = ''
    ss = where(file_exist(infil4)) & if (ss(0) ne -1) then infil4 = infil4(ss) else infil4 = ''
end
;
mk_week_file, 'OSF', infil2, week=fullweek, run_time=run_time2, append=append, qdebug=qdebug, usefid=usefid, indir=indir
mk_week_file, 'OSP', infil3, week=fullweek, run_time=run_time3, append=append, qdebug=qdebug, usefid=usefid, indir=indir
mk_week_file, 'OWH', infil4, week=fullweek, run_time=run_time4, append=append, qdebug=qdebug, usefid=usefid, indir=indir
mk_week_file, 'OBD', infil1, week=fullweek, run_time=run_time1, append=append, qdebug=qdebug, usefid=usefid, indir=indir
run_time = run_time1 + run_time2 + run_time3 + run_time4
;
print, 'MK_OBS took ', run_time, ' minutes to run'
end
