;+
; NAME:
;       HELP_SSR
; PURPOSE:
;       Prints information about an observatory/instrument held in EGSO SSR
; CALLING SEQUENCE:
;       help_ssr, file_list
;
; INPUTS
;       file_list       List of Files structure returned by EGSO API
;                       - if multiple obs/inst, user asked to select an instrument
;                       - if single obs/inst, just prints the result
; KEYWORDS INPUTS:
;       repair          apply routine egso_repair_filelist to remove inconsistencies
; OUTPUTS:
;       none - result printed
; KEYWORDS OUTPUTS:
; RESTRICTIONS:
; HISTORY:
;       20-Feb-2007  rdb  Written
;       28-Feb-2007  rdb  patched up some mixed filenames characters...
;                         call to egso_repair_filelist if /repair
;
;-

pro help_ssr, filelist, debug=debug, repair=repair

common ssr_hold, ssr

;    establish SSR object if not already done
if n_elements(ssr) eq 0 or keyword_set(debug) then begin
  message,'Loading EGSO SSR object',/info
  ssr=obj_new('egso_ssr')
;    SSR will be ingested on first call...
endif else message,'EGSO SSR object already loaded',/info

help,ssr
help,filelist	;,/st
lobs = filelist

if keyword_set(repair) then egso_repair_filelist,lobs
nlobs = n_elements(lobs)

;    need to make sure the names are consistently - obs__inst

for j=0,nlobs-1 do begin
  if strpos(lobs(j).instrument,'__') gt 0 then $
    lobs(j).instrument = strmid(lobs(j).instrument,strpos(lobs(j).instrument,'__')+2,100)
endfor

inst = ssr->search(filelist=lobs, debug=debug)
help,inst
obs = ssr->search(obs=all_vals(lobs.observatory), debug=debug)
help,obs

temp = all_vals(lobs.observatory+'/'+lobs.instrument)

;    choose the observator/instrument pair to report on

if n_elements(temp) gt 1 then begin
  print,''
  box_message,'Select one of the Observatory/Instrument pairs'
  qsel = wmenu_sel(temp,/one)
;;print,temp(qsel)
endif else qsel=0

;    output the report

if qsel(0) ge 0 then begin
;;  qv = where(inst.key eq temp(qsel))

  obsinst = strupcase(temp(qsel))
  obsinst = str_replace(obsinst,'/','__')
  obsinst = str_replace(obsinst,'-','_')
  qv = where(inst.key eq obsinst)

  if qv(0) ge 0 then begin
    qob = where(obs.observatory eq inst(qv).observatory)
    if qob(0) ge 0 then begin
      print,''
      print,'>>>> Observatory'
      help,/st,obs(qob)
    endif else message,'Observatory not identified',/cont

    print,''
    print,'>>>> Instrument'
    help,/st,inst(qv)

    qs = where(inst(qv).synonyms ne '')
    synonyms = ''
    if qs(0) ge 0 then synonyms = arr2str(inst(qv).synonyms(qs), delim=', ')
    print,'++ Synonyms:  ', synonyms

  endif
endif

print,''

end