5.7) Using Keywords In Functions (cont'd)
In this new function "degC" is a keyword. We specify it as a keyword by setting it equal to itself (degC=degC) in the function definition. We can then check if the keyword has been set by using the "keyword_set" function.
IF keyword_set(degC) THEN t=t+273.13 ; Convert the temperature from Kelvin to Celsius
This means that if the keyword degC is set, then add 273.15 to the temperature. A keyword is counted as set as long as it doesn't have a value equal to zero. So we can set the keyword in the call to the function by giving it a value:
theta=temp_to_theta(0., 900., degC=1) ; Call the function, setting the keyword
You can also set the keyword by just adding a forward slash (/) in front of the keyword in the call. Try typing the following at the IDL command line:
theta=temp_to_theta(0., 900., /degC) ; Call the function, setting the keyword
Both of the above calls to temp_to_theta will take the temperature input as degrees C and output theta in degrees C. If we want to go back to using Kelvin, we just omit the keyword.
theta=temp_to_theta(273.15, 900.) ; Call the function, omitting the keyword