pro mk_obs_str, prefix, infil, out, last_tim, serial_num, refverno, ref2verno, progverno, progname
;
;+
;NAME:
;	mk_obs_str
;PURPOSE:
;	Make the observing log structure
;INPUT:
;	prefix	- The Observing log prefix (OBD, OSF, OSP, OWH)
;	infil	- an array of input files
;	last_tim - The last time in the previous input files
;OUTPUT:
;	out	- The observing log structure for the input files
;	serial_num - For OSP and OSF, this is the lowest image serial
;		  number in the file.
;HISTORY:
;	Written 21-Apr-93 by M.Morrison
;V1.00  17-Jul-93 (MDM) - Assigned program version number
;			- Read/returned the reformatter version from the header
;V1.10	17-Jan-95 (MDM) - Added "last_tim" input to remove duplicate data
;V1.2	20-Jan-95 (MDM) - Corrected V1.10 patch so that it checked to see
;			  if roadmap is a structure.  There could be files
;			  with no data in them.
;V1.3	25-Jan-95 (MDM) - Define LAST_TIM at the end of the routine
;			- Changed how existence of LAST_TIM is checked
;-
;
progverno = 1.300*1000
progname = 'MO_OBS_STR.PRO'
;
;----- Extract the reformatter version number stuff
;
rd_fheader, infil, fhead
refverno = fhead.refverno
ref2verno = fhead.ref2verno
;
;----- Extract the data
;
out = 0b
serial_num = 0
rd_roadmap, infil, roadmap
;
;---- MDM added "last_tim" code 17-Jan-95
;if (n_elements(last_tim) ne 0) and (data_type(roadmap) eq 8) then begin
if (keyword_set(last_tim)) and (data_type(roadmap) eq 8) then begin
        ist = tim2dset(roadmap, last_tim)               ;find where the time of the last dataset in
                                                        ;the previous file falls within the current file
                                                        ;This is needed because there is overlap in the ADA and CBA files.
        del = int2secarr(roadmap(ist), last_tim)
        ;               ^^^ rmap data    ^^^ Last data in weekly file ==> if last_time is after data, del is negative
        if (del le 0) then ist = ist + 1                ;if the times match, then move forward one dataset
        if (ist ge n_elements(roadmap)) then begin
            print, 'The input file is totally contained in a previous file'
	    roadmap = 0b
        end else begin
	    if (ist ne 0) then print, 'MK_OBS_STR: Skipping first', ist, $
				' entries in the roadmap out of ', n_elements(roadmap)
	    roadmap = roadmap(ist:*)
	end
end
;
case strmid(strupcase(prefix), 1, 1) of
    'S': begin
		if (get_nbytes(roadmap) gt 10) then begin
		    mk_obs_sxt, roadmap, out		;--- convert roadmap entry to observing log entry
		    serial_num = min(roadmap.serial_num)
		end
	 end
    'B': begin
		if (get_nbytes(roadmap) gt 10) then begin
                    rd_bda_dp, infil, dp_sync
                    mk_obs_bcs, roadmap, dp_sync, out
		end
	 end
    'W': begin
		infil2 = str_replace(infil, 'wda', 'hda')
		rd_roadmap, infil2, hxt_roadmap
		if ((get_nbytes(roadmap) gt 1) or (get_nbytes(hxt_roadmap) gt 1)) then begin
		    mk_obs_w_h, hxt_roadmap, roadmap, out
		end
	 end
endcase
;
if (data_type(roadmap) eq 8) then last_tim = anytim2ints( roadmap(n_elements(roadmap)-1) )	;MDM added 25-Jan-95

end
