5.4) Multiple Variable Functions
A function which takes multiple input variables is no different to a single input function. You simply list the input variables after the function name, each separated by a comma. Here we will use the example of calculating the potential temperature, which requires the temperature and pressure as inputs. The equation for potential temperature (theta) is:
We can write a function to calculate theta given the temperature and pressure as inputs. Type the following into a file called temp_to_theta.pro:
Function temp_to_theta, t, p ; Function to convert T(K) and P(hPa) to theta ; using a reference pressure of 1000hPa RoverCp=0.2896 p0=1000. theta=t*(p0/p)^RoverCp return, theta END
We can the use the function to convert zero degrees Celsius (273.15K) at 900hPa to a potential temperature and place the result in the variable "theta" using:
theta = temp_to_theta(273.15, 900.)
You should get the answer "281.506".