function getnum, prompt, defval,noquery=noquery ; ;+ ; PURPOSE: ; print a string and then let user enter a number ; just like READ command, except can enter to choose default ; and will re-prompt if user doesn't enter a number ; ; ; ; INPUTS ; prompt string to print (no colon) ; defval default value ; ; KEYWORD ; /noquery don't actually ask user, just return the default value ; This is useful for making an "automatic" mode. ; ; USES ; strc, isnumber (JHU/APL) ; ; 05/12/99 MCL ; 05/31/00 MCL: bug fix - returned value was a string, now it's a float ; 2003-11-25 MDP: added /noquery ;- if n_elements(prompt) eq 0 then prompt = 'enter a value' if n_elements(defval) eq 0 then defstr = '' $ else defstr = strc(defval) ans = '' if keyword_set(noquery) and n_elements(defval) then return,defval done = 0 repeat begin read, string(prompt)+' ['+defstr+']: ', ans if (ans eq '') and (n_elements(defval) ne 0) then begin done = 1 retval = defval endif else if (isnumber(ans) gt 0) then begin done = 1 retval = float(ans) endif endrep until (done) return, retval end