;+
; Project     : SOHO - CDS     
;                   
; Name        : STUDY_BRIEF
;               
; Purpose     : Lists information on CDS studies available at EOF
;               
; Explanation : As above
;               
; Use         : IDL> study_brief [, study_names, /hardcopy, /status, /summary]
;    
; Inputs      : None
;               
; Opt. Inputs : study_names - enter study acronym (or array of them) for 
;                             for which info is required. Info on all known
;                             studies is given if this parameter is omitted.
;               
; Outputs     : None
;               
; Opt. Outputs: None
;               
; Keywords    : STATUS - if present the status of the study is given, rather
;                        than the definition.
;               SUMMARY - gives a list of available acronyms
;               TEXT, SAVE_TEXT - captured text arrays
;               QUIET   - suppress output
;
; Calls       : None
;
; Common      : None
;               
; Restrictions: Requires $CDS_STUDYSHEETS to be defined
;               
; Side effects: None
;               
; Category    : Info, help
;               
; Prev. Hist. : None
;
; Written     : C D Pike, RAL, 29-Mar-96
;               
; Modified    : Cater for slightly changed input file format and
;               trap non-existant files.               CDP, 12-Apr-96
;               Zarro, GSFC, 9 Sept. 1996 -- return text arrays as keywords
;
;
; Version     : Version 2, 12-Apr-96
;-            

pro study_brief, name, hardcopy=hardcopy, status=status, summary=summary,$
                 save_text=save_text,text=text,quiet=quiet

text='' & save_text=''
quiet=keyword_set(quiet)
;
;  check pointer to file
;
if getenv('CDS_STUDYSHEETS') eq '' then begin
   print,'$CDS_STUDYSHEETS is not defined'
   return
endif

;
;  summary only?
;

if keyword_set(summary) then begin
;
;  read the ascii file
;
   
   if not file_exist(concat_dir('$CDS_STUDYSHEETS','studysheets')) then begin
      print,'File $CDS_STUDYSHEETS/studysheets does not exist'
      return
   endif
   text = rd_ascii(concat_dir('$CDS_STUDYSHEETS','studysheets'))
   save_text = ''
   acro = strmid(text,0,5)
   n = where(acro eq '~~~~~',count)
   if (count eq 0) or (n_elements(n) ne 2) then begin
      print,'Cannot find summary list.'
      return
   endif
   if not quiet then print_str,text(n(0):n(1))
   if keyword_set(hardcopy) then print_str, text(n(0):n(1)),/hardcopy, /quiet
   return
endif

;
;  Is brief or status required?
;
if keyword_set(status) then begin

;
;  read the ascii file
;
   if not file_exist(concat_dir('$CDS_STUDYSHEETS','studysheets')) then begin
      print,'File $CDS_STUDYSHEETS/studysheets does not exist'
      return
   endif
   text = rd_ascii(concat_dir('$CDS_STUDYSHEETS','studysheets'))

;
;  if all was requested then do it
;
   if n_params() eq 0 then begin
      if not quiet then print_str,text
      if keyword_set(hardcopy) then print_str,text,/hard,/quiet
      return
   endif else begin
;
;  if a particular study was requested then find it
;
      save_text = ''
      acro = strmid(text,0,20)
      for i=0,n_elements(name)-1 do begin
         n = where(strpos(acro,'STUDY ID: '+strupcase(name(i))) ge 0,count)
         if count eq 0 then begin
            print,'Acronym not found'
            return
         endif
         for j=0,n_elements(n)-1 do begin
            temp = strmid(acro(n(j):*),0,2)
            nstop = where(temp eq '==')
            nstop = nstop(0)
            if nstop eq -1 then nstop = n_elements(temp)
            if not quiet then $
                       print_str,['--------------------------',$
                       text(n(j):n(j)+nstop-1),$
                       '--------------------------']
            save_text = [save_text,'--------------------------',$
                       text(n(j):n(j)+nstop-1),$
                       '--------------------------']
         endfor
      endfor
      if keyword_set(hardcopy) then print_str, save_text, /hardcopy, /quiet
   endelse




endif else begin
;
;  read the ascii file
;
   if not file_exist(concat_dir('$CDS_STUDYSHEETS','study_brief')) then begin
      print,'File $CDS_STUDYSHEETS/study_brief does not exist'
      return
   endif
   text = rd_ascii(concat_dir('$CDS_STUDYSHEETS','study_brief'))

;
;  if all was requested then do it
;
   if n_params() eq 0 then begin
      if not quiet then print_str,text
      if keyword_set(hardcopy) then print_str,text,/hard,/quiet
      return
   endif else begin
;
;  if a particular study was requested then find it
;
      save_text = ''
      acro = strmid(text,0,10)
      for i=0,n_elements(name)-1 do begin
         n = where(strpos(acro,strupcase(name(i))) ge 0,count)
         if count eq 0 then begin
            print,'Acronym not found'
            return
         endif
         for j=0,n_elements(n)-1 do begin
            temp = strcompress(text(n(j):*),/rem)
            nstop = where(temp eq '')
            nstop = nstop(0)
            if nstop eq -1 then nstop = n_elements(temp)
            if not quiet then $
                       print_str,['--------------------------',$
                       text(n(j):n(j)+nstop-1),$
                       '--------------------------']
            save_text = [save_text,'--------------------------',$
                       text(n(j):n(j)+nstop-1),$
                       '--------------------------']
         endfor
      endfor
      if keyword_set(hardcopy) then print_str, save_text, /hardcopy, /quiet
   endelse



endelse


end

