OX_UNITS converts between 3 different oxygen units ml/l, micromole/kg, micromole/l INPUTS: ox: oxygen in original units salt: salinity in PSU temp: potential temperature. from_to: string indicating original and desired units. possible cases are: mll2mml: ml/l to micromoles/l mll2mmk: ml/l to micromoles/kg mml2mmk: micromoles/l to micromoles/kg mml2mll: micromoles/l to ml/l mmk2mll: micromoles/kg to ml/l mmk2mml: micromoles/kg to micromoles/l Usage: o = ox_units(ox,salt,potentialtemp,from_to); Derrick Snowden, 2002; Based on code by Paul Robbins 1995
0001 function o = ox_units(ox,salt,temp,from_to); 0002 % OX_UNITS converts between 3 different oxygen units 0003 % ml/l, micromole/kg, micromole/l 0004 % 0005 % INPUTS: 0006 % ox: oxygen in original units 0007 % salt: salinity in PSU 0008 % temp: potential temperature. 0009 % from_to: string indicating original and desired units. 0010 % possible cases are: 0011 % mll2mml: ml/l to micromoles/l 0012 % mll2mmk: ml/l to micromoles/kg 0013 % mml2mmk: micromoles/l to micromoles/kg 0014 % mml2mll: micromoles/l to ml/l 0015 % mmk2mll: micromoles/kg to ml/l 0016 % mmk2mml: micromoles/kg to micromoles/l 0017 % 0018 % 0019 % Usage: o = ox_units(ox,salt,potentialtemp,from_to); 0020 % 0021 % Derrick Snowden, 2002; 0022 % 0023 % Based on code by 0024 % Paul Robbins 1995 0025 0026 if nargin < 4 0027 disp(['No units indicator (from_to) was passed.']) 0028 disp('') 0029 disp(['Valid units are:']); 0030 print_usage(1); 0031 end 0032 0033 % First compute potential density assuming temp is potential temp 0034 % equivalent to sw_pden(salt,temp,press,press_ref==0) if temp is in situ 0035 pdens = sw_dens(salt,temp,0); 0036 0037 switch from_to 0038 case 'mll2mmk' %ml/l to micromoles/kg 0039 o = ox*1e3./pdens/.022403; 0040 case 'mll2mml' %ml/l to micromoles/l 0041 o = (ox*1e3./pdens/.022403).*pdens./1000; 0042 case 'mml2mmk' % micromoles/l to micromoles/kg 0043 o = ox*1000./pdens; 0044 case 'mml2mll' % micromoles/l to ml/l 0045 o = (ox.*1000./pdens) .* (.022403 .* pdens ./ 1000); 0046 case 'mmk2mll' % micromoles/kg to ml/l 0047 o = ox .* (0.022403 .* pdens ./ 1000); 0048 case 'mmk2mml' % micromoles/kg to micromoles/l 0049 o = ox.*pdens./1000; 0050 0051 otherwise 0052 disp(['Incorrect units passed to ox_units.']) 0053 disp('') 0054 disp(['Valid units are:']); 0055 print_usage(1); 0056 end 0057 0058 return 0059 0060 function [] = print_usage(err) 0061 0062 disp(['mll2mml: ml/l to micromoles/l']); 0063 disp(['mll2mmk: ml/l to micromoles/kg']); 0064 disp(['mml2mmk: micromoles/l to micromoles/kg']); 0065 disp(['mml2mll: micromoles/l to ml/l']); 0066 disp(['mmk2mll: micromoles/kg to ml/l']); 0067 disp(['mmk2mml: micromoles/kg to micromoles/l']); 0068 disp('') 0069 error('Set from_to to one of the strings above;'); 0070 return