function rd_fitslog, log
;
;
;HISTORY:
;	Written May-94 by M.Morrison
;	31-May-94 (MDM) - Modified to use the date/time of the telemetry file if
;			  the date/time in the log file is questionable.
;
if (n_elements(log) eq 0) then log = 'nov'
;
;------------------------- OCT -------------------------
;# List of October Calibration Test (oct) series data sets as of 2.IV.94
;#  U: vax data on /data#/optest
;#  Q: data on /scr#/oct/XXX[/{raw,tlm}]
;#  Arch: archive on tape XX file XX
;#
;# id  tlmname     vaxname    fsn  lsn  st_date  time  end_date time  U Q Arch
;#
;500 xxxxxx_xxxxxx diodes     0000 0048 93.10.xx xx:xx 93.10.xx xx:xx x x 75 01
;501 931019_215619 xxx        0000 0100 93.10.19 21:56 93.10.19 22:13 x x 73 01
;502 xxxxxx_xxxxxx magneto    0000 0120 93.10.xx xx:xx 93.10.xx xx:xx x 1 74 01
;503 xxxxxx_xxxxxx magneto    0000 0039 93.10.xx xx:xx 93.10.xx xx:xx x 1 74 01
;
;------------------------- NOV, CAT, APR -------------------------
;# List of November Oven Vacuum Test (nov) series data sets as of 1.IV.94
;#  Q: data on /scr#/nov/XXX/lev0
;#  Arch: archive on tape XX file XX
;#
;# id  tlmname     fsn  lsn  st_date  time  end_date time  Q Arch
;#
;618a 931125_231103 0000 0008 93.11.25 23:11 93.11.25 23:30 x 107 09
;618b 931126_071012 0000 0009 93.11.26 07:10 93.11.26 07:29 x 107 09
;
;------------------------- OPT -------------------------
;# List of Optical Performance tests as of 30.III.94
;#  (U: data on /data#/optest) (Q: data on /scr#/optXXX) (PST: TIME-OBS in PST)
;#  (U data before 052 on /data4/Mdi rather than /data4/optest)
;#  Q: y if data are on ~soi/data directly rather than scratch system
;
;# id name           fsn  lsn  st_date  time  end_date time  U Q Archiv notes
;# optxxx xxx        0000 xxxx xx.xx.xx xx:xx xx.xx.xx xx:xx x x xx xx
;
;opt013 cracks       0000 0002 92.xx.xx xx:xx 92.xx.xx xx:xx x x xx xx raw - can't fitsify
;opt017 fdfocus      0000 0035 92.11.10 19:09 92.11.10 19:55 x x 09 05

;
case strupcase(log) of
    'OCT': begin & off1 = 1 & off2 = 2 & icfl =  2 & itelem= 1 & ncol=14 & end
    'OPT': begin & off1 = 0 & off2 = 1 & icfl =  1 & itelem=-1 & ncol=12 & end
    else:  begin & off1 = 0 & off2 = 0 & icfl = -1 & itelem= 1 & ncol=11 & end	;apr, nov, cat
end
;
if (getenv('HOSTNAME') eq 'quake') then dir = '/home/soi/data/' else dir = '$MDI_CAL_INFO/
infil = dir + log + 'log'
mat = rd_tfile(infil, ncol, nocomment='#')
n = n_elements(mat(0,*))
;
out0 = {rd_fitslog, ser: ' ', telem: ' ', cfl: ' ', nimages: 0L, $
	time: 0L, day: 0, duration: 0.0, bad_time: 0b, $
	disk: 0, tape: 0, tape_file: 0}
out = replicate(out0, n)
;
st_dattim0 = reform(str_replace(mat(4+off1,*), '.', '/') + ' ' + mat(5+off1,*))
en_dattim0 = reform(str_replace(mat(6+off1,*), '.', '/') + ' ' + mat(7+off1,*))
ss_bad_time = where(strpos(st_dattim0, 'x') ne -1)
st_dattim0 = str_replace(st_dattim0, 'xx:xx', ' 00:00')
en_dattim0 = str_replace(en_dattim0, 'xx:xx', ' 00:00')
st_dattim0 = str_replace(st_dattim0, '/xx ', '/01 ')
en_dattim0 = str_replace(en_dattim0, '/xx ', '/01 ')
st_dattim0 = str_replace(st_dattim0, '/xx', '/01')
en_dattim0 = str_replace(en_dattim0, '/xx', '/01')
st_dattim0 = str_replace(st_dattim0, 'xx/', '90/')
en_dattim0 = str_replace(en_dattim0, 'xx/', '90/')
;en_dattim0 = str_replace(en_dattim0, '93/09:23', '93/09/23 ')	;rick typo in opt log
;en_dattim0 = str_replace(en_dattim0, '93/09:24', '93/09/24 ')	;rick typo in opt log
ss = where(st_dattim0 eq '', nn)	& if (nn ne 0) then for i=0,nn-1 do st_dattim0(ss(i)) = st_dattim0(ss(i)-1)
ss = where(en_dattim0 eq '', nn)	& if (nn ne 0) then for i=0,nn-1 do en_dattim0(ss(i)) = st_dattim0(ss(i))
st_dattim = anytim2ints( reform(st_dattim0) )
en_dattim = anytim2ints( reform(en_dattim0) )
disk = reform(mat(8+off2,*))
tape = reform(mat(9+off2,*))
tape_file = reform(mat(10+off2,*))
ss = where(strpos(disk, 'x') ne -1)		& if (ss(0) ne -1) then disk(ss) = '-1'
ss = where(strpos(tape, 'x') ne -1)		& if (ss(0) ne -1) then tape(ss) = '-1'
ss = where(strpos(tape_file, 'x') ne -1)	& if (ss(0) ne -1) then tape_file(ss) = '-1'
ser = mat(0,*)
if (strupcase(log) ne 'OPT') then ser = log + ser

;
stimg = reform(mat(2+off1,*))
enimg = reform(mat(3+off1,*))
ss = where(strpos(stimg, 'x') ne -1)	& if (ss(0) ne -1) then stimg(ss) = '0'
ss = where(strpos(enimg, 'x') ne -1)	& if (ss(0) ne -1) then enimg(ss) = '0'
;
out.ser		= reform(ser)
if (itelem ne -1) then out.telem = reform(mat(itelem,*))
if (icfl ne -1)   then out.cfl   = reform(mat(icfl,*))
out.nimages	= fix(enimg)-fix(stimg)+1
out.time	= st_dattim.time
out.day		= st_dattim.day
if (ss_bad_time(0) ne -1) then begin
    out(ss_bad_time).bad_time = 1
    for i=0,n_elements(ss_bad_time)-1 do begin
	telem99 = strtrim(out(ss_bad_time(i)).telem,2)
	if (telem99 ne '') and (strpos(telem99, 'x') eq -1) then begin
	    dattim99 = anytim2ints( fid2ex(telem99) )
	    out(ss_bad_time(i)).day = dattim99.day
	    out(ss_bad_time(i)).time = dattim99.time
	end
    end
end
out.duration	= int2secarr(en_dattim, st_dattim)
out.disk	= fix(disk)
out.tape	= fix(tape)
out.tape_file	= fix(tape_file)
;
return, out
end

