;+
; NAME: LIST_OP
;
; Lists menu of parameter names and current values, and available commands.
;
; CALLING SEQUENCE:
; 	list_op, prm, prm_info, commands, com_delim, comments, families=families
;
; SAMPLE CALL:
;	list_op, prm,prm_info,commands,'!!','SPEX',fam=['time','fit']       
;
; INPUT ARGUMENTS: 
;	PRM 	   - structure with parameter values, type, etc.
;		     (See create_param for info about prm and prm_info)
;	PRM_INFO   - structure with information about each family of parameters
;	COMMANDS   - list of allowed commands
;	COM_DELIM  - Delimiter parsing consecutive command strings, default '!!'
;	COMMENTS   - comments for menu
;
; KEYWORDS:
;	FAMILIES   - family names to list.  If omitted, lists all families
;                    in fam_info
;
; Written: akt 9-mar-94
; ras, 22-aug-94, prints text as a block
;-



pro list_op, prm, fam_info, com_delim, comments, families=families

checkvar, families, fam_info.fam  ; default to all families if not passed in
text = ''

do_main = (where(families eq 'main'))(0) ne -1  ;=1 if doing 'main' family
if do_main then begin
   text = [text, ' ','Change options by entering item, comma, new value.  After setting options,' ,$
   'enter one of the available commands.  Parameters and commands may be' , $
   'abbreviated to shortest unambiguous abbreviation and may be strung together' , $
   'by inserting '+com_delim+ ' between entries.  To delete a string field,', $
   "place a '' in the field"]
endif

nfam = n_elements(fam_info)

skipcom = ''

for ifam = 0,nfam-1 do begin
   if keyword_set(families) then begin
      if (where(fam_info(ifam).fam eq families))(0) eq -1 then begin
         skipcom = [skipcom, fam_info(ifam).commands]
         goto, skipfam
      endif
   endif

   text= [text,' ',string(/print,fam_info(ifam).title,form='(5x,a)'),' ']

   qvalid = where (fam_info(ifam).commands ne '', nvalid)
   if nvalid gt 0 then begin
      if (size(commands))(0) eq 0 then $
         commands = fam_info(ifam).commands(qvalid) $
         else commands = [commands, fam_info(ifam).commands(qvalid)]
   endif
   p = where(prm.fam eq fam_info(ifam).fam, np)
   if np ne 0 then begin
      for i=0,np-1 do begin
         format = '10x,a,t30,a'
         nv = 1
         if prm(p(i)).numval gt 1 then begin
            format = '10x,a,t30,a,t43,a,t56,a,t69,a'
            if prm(p(i)).numval gt 4 then format = format + $
               '/t30,a,t43,a,t56,a,t69,a'
            nv = prm(p(i)).numval
         endif

         text = temporary([text, string(/print, prm(p(i)).nam, strtrim(prm(p(i)).val(0:nv-1), 2), $
            format='('+format+')')])

      endfor
   endif
skipfam:
endfor

if keyword_set(comments) then printx,comments

text = [text, ' ']
if n_elements(commands) gt 0 then begin
   commands = commands( uniq (commands, sort(commands)) )
   text = [text, string(/print,'Commands: ', commands), '  ']
endif

if do_main and n_elements(skipcom) gt 1 then begin 
   ; only printx non-blank, unique commands that weren't in list already given
   skipcom = skipcom(where(skipcom ne ''))
   skipcom = skipcom (uniq (skipcom, sort(skipcom)) )
   ind = rem_elem(skipcom, commands, count)
   if count gt 0 then begin
      text= [text, string(/print,'Additional commands: ',skipcom(ind)), ' ']
   endif
endif

printx, text(1:*)

return&end
