pro list_mo_log, outfil=outfil, short=short
;
;+
;NAME:
;	list_mo_log
;PURPOSE:
;	To read the log entries when an MO disk is made and make a listing.
;SAMPLE CALLING SEQUENCE:
;	list_mo_log
;OPTIONAL KEYWORD INPUT:
;	outfil	- The name of the output file to write to
;HISTORY:
;	Written 31-May-93 by M.Morrison
;               30-Jun-94 SLF - remove file before writting 
;-
;
infil = concat_dir('$DIR_GEN_MO', 'mdm_log')
restgen, mdm_log, file=infil
n = n_elements(mdm_log)
tit1 = '        MO Label   :    Weeks                       File IDs           '
tit2 =                                                                        ' Ref Ver#             Date Made     Made By
       ;000A  910915.0924a : 91_38a,91_39a             910915.0924-910927.1452  1.120          27-FEB-93  15:14:00 linford
if (keyword_set(short)) then tit = tit1 else tit = tit1+tit2
print, tit
;
lun = -1
if (keyword_set(outfil)) then begin
    file_delete,outfil
    openw, lun, outfil, /get_lun
    printf, lun, 'LIST_MO_LOG.PRO  Ver 1.0 
    printf, lun, 'Program Run: ', !stime
    printf, lun, ' '
    printf, lun, tit
    printf, lun, ' '
end
;
mk_mo_list, list, mdm=mdm_log.map, label=label
ulabel = label(uniq(label, sort(label)))
nn = n_elements(ulabel)
;
for i=0,nn-1 do begin
    ss = where(label eq ulabel(i), count)
    mdm0 = mdm_log(ss).map
    w_str = arr2str( string(mdm0.st$week) )
    w_str = string(w_str + '                          ', format='(a25)')
    fid1 = min(string(mdm0.st$first_fid))
    fid2 = max(string(mdm0.st$last_fid))
    refv = string(mdm_log(ss).log.refverno/1000., format='(f6.3)')
    s_ref = refv
    if (n_elements(refv) gt 1) then s_ref = refv( uniq(refv, sort(refv)) )
    s_ref = arr2str( s_ref )
    s_ref = string(s_ref + '                          ', format='(a13)')

    log0 = mdm_log(ss(count-1)).log
    made = fmt_tim(log0)
    by = string(log0.st$operator)

    str1 = ulabel(i) + ' : ' + w_str + ' ' + fid1 + '-' + fid2
    str2 = '  ' + s_ref + '  ' + made + ' ' + by
    if (keyword_set(short)) then str = str1 else str = str1 + str2
    print, str
    if (lun ne -1) then printf, lun, str
end
;
if (lun ne -1) then free_lun, lun
end

