;+
;NAME:
; thm_ui_npar
;PURPOSE:
; Simple widget that asks for n parameter
;CALLING SEQUENCE:
; new_value = thm_ui_npar(name, init_value)
;INPUT:
; name = the name of the parameter, can be an array
; init_value = the initial value of the parameter, e.g., '1.0', must
;              be a string array of the smae size as name
;OUTPUT:
; new_value = the output value of the parameter, a string, e.g., '4.67'
;HISTORY:
; 5-feb-2007, jmm, jimm@ssl.berkeley.edu
; 25-OCt-2007, jmm, added KILL_REQUEST block
;
;$LastChangedBy$
;$LastChangedDate$
;$LastChangedRevision$
;$URL$
;
;-

Pro thm_ui_npar0_event, event
  common thm_ui_npar0_private, value_sav

;If the 'X' is hit...
  If(TAG_NAMES(event, /STRUCTURE_NAME) EQ 'WIDGET_KILL_REQUEST') Then Begin
    value_sav = 'Cancelled'
    widget_control, event.top, /destroy
    Return
  Endif
  widget_control, event.id, get_uval = uval
  If(uval Eq 'YES') Then Begin
    widget_control, event.top, /destroy
  Endif Else If(uval Eq 'NO') Then Begin
    value_sav = 'Cancelled'
    widget_control, event.top, /destroy
  Endif Else Begin
    j = fix(strmid(uval, 4))
    widget_control, event.id, get_val = temp_string
    value_sav[j] = temp_string
  Endelse
Return
End
Pro thm_ui_npar0, name, init_value

  master = widget_base(/col, title = 'Input Values', $
                       /tlb_kill_request_events)

  n = n_elements(name)
  listw = intarr(n)
  For j = 0, n-1 Do Begin
    uvalj = 'LIST'+strcompress(/remove_all, j)
    listid = widget_base(master, /row, /align_center, /frame)
    flabel = widget_label(listid, value = name[j])
    listw[j] = widget_text(listid, value = init_value[j], $
                      xsiz = max(strlen(init_value[j]))+20, $
                      ysiz = 1, uval = uvalj, $
                      /editable, /all_events)
  Endfor
  no_button = widget_button(master, val = 'Cancel', $
                            uval = 'NO', /align_center)
  yes_button = widget_button(master, val = 'Accept and Close', $
                             uval = 'YES', /align_center)
  state = {master:master, yes_button:yes_button, listw:listw}
  widget_control, master, set_uval = state, /no_copy
  widget_control, master, /realize
  xmanager, 'thm_ui_npar0', master
  Return
End
Function thm_ui_npar, name, init_value
  common thm_ui_npar0_private, value_sav

  n = n_elements(name)
  If(n_elements(init_value) Ne n) Then Begin
    message, /info, 'Mismatched input'
    Return, ''
  Endif

  value_sav = init_value
  thm_ui_npar0, name, init_value
  otp = value_sav

  Return, otp
End