Matlab utility code

This webpage contains numerous Matlab scripts for various functions that may be of use: firstly some general functions; then some meteorological & thermodynamic functions. Note: bulk flux code can be found on the Convective Internal Boundary Layer modelling page here.

Code

Description

filter999 removes bad data points 999 from an array and replaces them with NaN
filternan code to remove NaN from matrix M
paddednum2str checks length of string is two characters long & if not pads with a zero. Used to get days and months of 2 characters.
scatter_plot function to plot scatter plots, one plot per page and optionally print some basic statistics in the corner.
brunt_p brunt_p calculates the brunt-vaisalla frequency for theta and thetae using p as a vertical coordinate, theta, thetae in K, p (mb)
brunt_z brunt_z calculates the brunt-vaisalla frequency for theta and thetae
using z as a vertical coordinate and assuming theta(sonde_no, data)
hydro_pressure given z=height (m), t=temperature vectors (K), plus a ground pressure (mb) this function calculates the hydrostatic pressure (mb)
hydro_height given pressure (mb), temp vectors (K), and scalar ground pressure
calculates the hydrostatic height
rh_to_rhi converts rh to rh wrt ice, (%) given rh (%), T (oC), and p (mb)
rhi_to_rh converts rh wrt ice to rh, (%) given rhi (%), T (degC), and p (mb)
rhi_to_rh_e converts rh wrt ice to rh (%) and e (mb) given rhi (%), t (oC), and p (mb)
t_to_qsat generates saturated specific humidity (g/kg) wrt water and ice given T (degC), and p (mb)
t_to_theta t_to_theta generates theta from T (degC) and p (mb) vectors
thermo_es thermo_es calculates saturation vapour pressures (mb) wrt water and ice from T (degC) from the polynomial approximation of Lowe (see Sargent 1980)
thermo_rh generates thermodynamic variables from T (degC) p(mb) rh(%) vectors; output [theta, thetae, q, qsat, qsati] = thermo_rh(t,p,rh)
thermo_td generates thermodynamic variables from T (degC) p(mb) Td (degC) vectors; output [theta, thetae, q, qsat, qsati] = thermo_td(t,p,td)
thermo2_td generates thermodynamic variables from T (degC) p(mb) Td (degC) vectors; output [theta, thetae, q, qsat, qsati] = thermo_td(t,p,td). Note: Same as thermo_td, except a fix for NaNs included.
thermo_td_ecmwf generates thermodynamic variables from T (oC) p(mb) Td(oC); the modification for ec data is because their td at 2m field is T_dewpoint if T >0 and T_frostpoint if T <0; output [theta, thetae, q, qsat, qsati], in K, K, g/kg, g/kg, g/kg
theta_to_t generates T (K) from theta (K) and p(mb) vectors
uv_to_vectormean takes vectors (u,v) and calculates the vector mean wind speed and wind direction
uv_to_wswd takes vectors (u,v) and converts to wind speed and wind direction (deg from North) vectors
wswd_to_uv takes wind speed and wind direction (deg from North) and converts to vectors (u,v)