;+ ; NAME: ; physics_constant ; PURPOSE: ; Gets value of fundamental physics constant ; CATEGORY: ; gen/idl/toolbox ; CALLING SEQUENCE: FUNCTION physics_constant, char_string, $ unit=unit, uncertainty=uncertainty, name=name, $ exponent=exponent ; INPUTS: ; char_string scalar; type: string ; string descriptof for constant ; e.g. 'speed of light' ; OPTIONAL INPUT PARAMETERS: ; /exponent passes to flt_string ; OUTPUTS: ; value scalar or array[2]; type: double ; value of constant ; OPTIONAL OUTPUT PARAMETERS: ; unit=unit scalar; type: string ; unit of 'value' (mks units are used) ; uncertainty=uncertainty ; scalar; type: double ; uncertainty in 'value' ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; GetFileSpec, who_am_i, txt_read, BadValue, flt_string ; PROCEDURE: ; Uses list of physical constants from ; http://physics.nist.gov/cuu/Constants/Table/allascii.txt ; renamed to ; physics_constant.txt in the same directory as this function. ; MODIFICATION HISTORY: ; MAR-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- bad = BadValue(0.0d0) rtn = bad name = '' unit = '' uncertainty = bad IF txt_read(GetFileSpec(who_am_i(),upto='name')+'.txt',d) THEN BEGIN i = where(strpos(d,'-----') EQ 0) IF i[0] EQ -1 THEN message, 'oops' d = d[i+1:*] col_name = 1-1 col_value = 56-1 col_uncertainty = 78-1 col_unit = 100-1 names = strmid(d, col_name, col_value-col_name) names = strtrim(strlowcase(names)) char_low = strlowcase(char_string) pos = where(names EQ char_low, count) IF count EQ 0 THEN $ pos = where(strpos(names,char_low) NE -1, count) IF count EQ 0 THEN BEGIN message, /info, 'no match found: '+char_string ENDIF ELSE IF count EQ 1 THEN BEGIN d = d[pos] name = strmid(d, col_name , col_value - col_name ) value = strmid(d, col_value , col_uncertainty- col_value ) uncertainty = strmid(d, col_uncertainty , col_unit - col_uncertainty) unit = strmid(d, col_unit ) value = strcompress(value,/remove_all) value = flt_string(value,/double,exponent=exponent ) uncertainty = strcompress(uncertainty,/remove_all) CASE uncertainty EQ '(exact)' OF 0: uncertainty = flt_string(uncertainty,/double,exponent=exponent) 1: uncertainty = bad ENDCASE rtn = value ENDIF ELSE IF count GT 1 THEN BEGIN print, d[pos] message, /info, 'multiple matches found' ENDIF ENDIF RETURN, rtn & END