pro rd_old_obs, sttim, entim, bcs0, sxtf0, sxtp0, w_h0, fid0, $
		bcs=bcs, sxtf=sxtf, sxtp=sxtp, w_h=w_h, $
		nobcs=nobcs, nosxtf=nosxtf, nosxtp=nosxtp, now_h=now_h, $
		infil=infil
;
;+
;Name:
;	rd_old_obs
;Purpose:
;	Routine to read the observing log into vectors
;CALLING SEQUENCE:
;	rd_old_obs, sttim, entim, bcs, sxtf, sxtp, w_h, fid
;	rd_old_obs, sttim, entim, bcs, sxtf, sxtp, w_h
;	rd_old_obs, sttim, entim, bcs, sxtf, sxtp, w_h, /sxtp, /sxtf
;	rd_old_obs, sttim, entim, bcs, sxtf, sxtp, w_h, /nobcs
;INPUT:
;       sttim   - start time in any format
;       entim   - end time in any format
;OUTPUT:
;	bcs	- The BCS observing log structure
;	hxt	- The HXT observing log structure
;	sxtf	- The SXT FFI observing log structure
;	sxtp	- The SXT PFI observing log structure
;	w_h	- The WBS and HXT observing log structure
;	fid	- The File ID observing log structure
;OPTIONAL KEYWORD INPUT:
;	/bcs	- Read the BCS entries
;	/sxtf	- Read the SXT full frame entries
;	/sxtp	- Read the SXT partial frame entries
;	/w_h	- Read the WBS/HXT entries
;	/nobcs	- Don't read the BCS entries
;	/nosxtf	- Don't read the SXT full frame entries
;	/nosxtp	- Don't read the SXT parital frame entries
;	/now_h	- Don't read the WBS/HXT entries
;	infil	- It is posssible to pass in the file name directly
;		  instead of the starting/ending times.
;COMMENTS:
;	The observing log data files must be located in the $DIR_GEN_OBS
;	directory.
;
;	The output arrays are positional instead of keyword to allow
;	for less typing.  The order of the outputs is alphabetical in
;	order to be more easily memorized (except the fid file is at
;	the end)
;HISTORY:
;	Written Summer '91 by M.Morrison
;	 9-Jul-92 (MDM) - Changed the calling sequence to match all of the
;			  other reading routines (RD_PNT, RD_FEM, ...)
;	26-Oct-92 (MDM) - Moved the FREE_LUN call to inside the week loop
;			- Changed the names of the buffer variables.
;			  Used to be BCS,SXTP, ... now is BCS00,SXTP00, ...
;			  since there is keyword input /BCS - dont want
;			  to clobber that input.
;			- Checked to see how many parameters there were on
;			  the calling sequence and read/save the data
;			  accordingly (if don't have SXTP in calling seqence
;			  positionally, then don't save them)
;	23-Nov-92 (MDM) - Adjusted logic so that if "bcs=0" keyword option 
;			  was used, it would be recognized (since KEYWORD_SET
;			  would not recognized it and saying "no")
;			- Added comments to the header
;	28-Jan-93 (MDM) - Modified to return only the entries between the
;			  requested times (before, it returned full orbits
;			  of data)
;	15-Apr-93 (MDM) - Changed {obs_bcs_rec} to {obs_bcs_obs_rec}
;	21-Apr-93 (MDM) - Renamed from RD_OBS to RD_OLD_OBS when the
;			  OBS file organization was changed to be one
;			  instrument per file.
;	 9-Jun-93 (MDM) - Modification to not even try to read the old
;			  files if there are non online
;-
;
ff = file_list('$DIR_GEN_OBS', 'obs*')
if (ff(0) eq '') then return	;no old files on-line anyway
;
print, '*** Attempting to Reading OLD FORMAT Observing Log Files ***'
print, '*** Please talk to your system manager about getting the ***'
print, '*** new observing log files...                           ***'
tbeep, 5
;
gen_struct
obs_struct
;
qdebug = 1
;
qfid = 1 		;always read FID
qsxtp = 0
qsxtf = 0
qbcs = 0
qw_h = 0
;
if (keyword_set(bcs))  then qbcs=1
if (keyword_set(sxtf)) then qsxtf=1
if (keyword_set(sxtp)) then qsxtp=1
if (keyword_set(w_h))  then qw_h=1
if ( (not qbcs) and (not qsxtf) and (not qsxtp) and (not qw_h)) then begin
    qsxtp = 1
    qsxtf = 1
    qbcs = 1
    qw_h = 1
end
if (n_elements(bcs) ne 0)  then if (bcs eq 0) then qbcs = 0	;a value was passed in and it was equal to zero
if (n_elements(sxtf) ne 0) then if (sxtf eq 0) then qsxtf = 0	;added 23-Nov-92
if (n_elements(sxtp) ne 0) then if (sxtp eq 0) then qsxtp = 0
if (n_elements(w_h) ne 0)  then if (w_h eq 0) then qw_h = 0
if (keyword_set(nobcs))  then qbcs=0
if (keyword_set(nosxtf)) then qsxtf=0
if (keyword_set(nosxtp)) then qsxtp=0
if (keyword_set(now_h))  then qw_h=0
;
if (n_params(0) le 5) then qw_h = 0	;no output parameter, then don't bother saving it
if (n_params(0) le 4) then qsxtp = 0	;no output parameter, then don't bother saving it
if (n_params(0) le 3) then qsxtf = 0	;no output parameter, then don't bother saving it
if (n_params(0) le 2) then qbcs = 0	;no output parameter, then don't bother saving it
;
ans_arr = ['No ', 'Yes']
if (qdebug) then print, 'BCS: ', ans_arr(qbcs), $
			'        SXTF: ', ans_arr(qsxtf), $
			'        SXTP: ', ans_arr(qsxtp), $
			'        W_H: ', ans_arr(qw_h)
;
nbuff = 500	;buffer size of vector length to grab memory
fID00  = replicate({obs_fileID_rec},nbuff)	& nfID = long(0)
sxtp00 = replicate({obs_sxt_rec},nbuff)		& nsxtp = long(0)
sxtf00 = replicate({obs_sxt_rec},nbuff)		& nsxtf = long(0)
w_h00  = replicate({obs_wbshxt_rec},nbuff)	& nw_h = long(0)
bcs00  = replicate({obs_bcs_obs_rec},nbuff)	& nbcs = long(0)
;
if (not keyword_set(infil)) then begin
    siz = size(sttim)
    typ = siz( siz(0)+1 )
    if ( (n_elements(sttim) eq 1) and (typ eq 2) ) then begin
	weeks = sttim
	years = entim
	qinfil = 1
	filnam = string(years, weeks, format="('obs', i2.2, '_', i2.2, 'a.01')")
	infil = concat_dir('$DIR_GEN_OBS', filnam)
    end else begin
	anytim2weeks, sttim, entim, weeks, years
	st_ints = anytim2ints(sttim)
	en_ints = anytim2ints(entim)
	qinfil = 0
    end
end else begin
    weeks = intarr( n_elements(infil) )

    ist = 0
    ien = -1

    qinfil = 1
end
;
for iweek=0,n_elements(weeks)-1 do begin
    if (not qinfil) then begin
	filnam = string(years(iweek), weeks(iweek), format="('obs', i2.2, '_', i2.2, 'a.01')")
	infil = concat_dir('$DIR_GEN_OBS', filnam)
    end
    if (qdebug) then print, infil
    if (not file_exist(infil)) then goto, skip
    ;
    flag = 0
    openr, lun, infil, /get_lun, /block
    rd_fheader, infil, fhead
    rd_pointer, infil, pointer
    rd_neworb_p, infil, neworb_p
    norb = n_elements(neworb_p)

    if (not qinfil) then begin
        ss1 = where(int2secarr(neworb_p, st_ints) ge 0)
        ist = ss1(0)
        ss2 = where(int2secarr(neworb_p, en_ints) gt 0)	;find where pointer times are past the end time
							;if there are no times past the end time, use the whole file
        ien = ss2(0)
    end

    if (ist ne 0) then ist = ist - 1	;back up one fileid to make sure get data at start time
    if (ist eq -2) then st_dset = neworb_p(norb-1).stEntry else st_dset = neworb_p(ist).stEntry		;case of last
								;orbit in the file (not start times after it)
    if (ien eq -1) then en_dset = fhead.ndatasets-1 else en_dset = neworb_p(ien).stEntry
    if (qdebug) then print, 'ist,ien,st_dset,en_dset', ist,ien,st_dset,en_dset
    ;
    n = (en_dset-st_dset + 1)
    ;
    iblock = st_dset
    while (iblock le en_dset) do begin
	    rd_obs_entry, lun, pointer.data_section, recsize, iblock, struct, next_block
	    entry_type = (struct.entry_type mod 32)
	    ;print,'Struct.entry_type, entry_type and i: ', struct.entry_type, entry_type, iblock, next_block
	    case entry_type of
		31:		;continuation mark
		 0: if (qfID) then begin 		;file ID mark
			fID00(nfID) = struct
			nfID = nfID + 1
			if (nfID eq n_elements(fID00)) then fID00 = [fID00, replicate({obs_fileID_rec},nbuff)]
		    end
		15: if (qsxtf) then begin		;sxt rec
			sxtf00(nsxtf) = struct
			nsxtf = nsxtf + 1
			if (nsxtf eq n_elements(sxtf00)) then sxtf00 = [sxtf00, replicate({obs_sxt_rec},nbuff)]
		    end
		16: if (qsxtp) then begin		;sxt rec
			sxtp00(nsxtp) = struct
			nsxtp = nsxtp + 1
			if (nsxtp eq n_elements(sxtp00)) then sxtp00 = [sxtp00, replicate({obs_sxt_rec},nbuff)]
		    end
		17: if (qw_h) then begin		;wbs/hxt rec
			w_h00(nw_h) = struct
			nw_h = nw_h + 1
			if (nw_h eq n_elements(w_h00)) then w_h00 = [w_h00, replicate({obs_wbshxt_rec},nbuff)]
		    end
		18: if (qbcs) then begin		;bcs rec
			bcs00(nbcs) = struct
			nbcs = nbcs + 1
			if (nbcs eq n_elements(bcs00)) then bcs00 = [bcs00, replicate({obs_bcs_obs_rec},nbuff)]
		    end
		else:		;do nothing
	    endcase
	    iblock = next_block		;avoid reading continuation block twice
    end
    free_lun, lun
    skip:
end
;
;Change variable names so that structures that do not have any entries come
;out as undefined and "n_elements" is zero.
;
if (qinfil) then begin
    if (nfID ne 0)  then fID0  = fID00(0:nfID-1)
    if (nsxtp ne 0) then sxtp0 = sxtp00(0:nsxtp-1)
    if (nsxtf ne 0) then sxtf0 = sxtf00(0:nsxtf-1)
    if (nw_h ne 0) then w_h0 = w_h00(0:nw_h-1)
    if (nbcs ne 0) then bcs0 = bcs00(0:nbcs-1)
end else begin		;MDM added 28-Jan-93
    if (nfID ne 0)  then fID0  = fID00(0:nfID-1)	;return all FIDS
    ss = sel_timrange(sxtp00, sttim, entim, /between)	& if (ss(0) ne -1) then sxtp0 = sxtp00(ss)
    ss = sel_timrange(sxtf00, sttim, entim, /between)	& if (ss(0) ne -1) then sxtf0 = sxtf00(ss)
    ss = sel_timrange(w_h00, sttim, entim, /between)	& if (ss(0) ne -1) then w_h0 = w_h00(ss)
    ss = sel_timrange(bcs00, sttim, entim, /between)	& if (ss(0) ne -1) then bcs0 = bcs00(ss)
end
;
end
