%======================================================================
%                    U N I T S . S T Y 
%                    doc: Sat Sep 25 14:41:12 1999
%                    dlm: Fri Mar 22 17:35:26 2002
%                    (c) 1999 A.M. Thurnherr
%                    uE-Info: 248 0 NIL 0 0 72 0 2 4 NIL ofnI
%======================================================================

% TYPESET NUMBERS WITH DIMENSIONS
% - the number of capital Ds is equal to the number of (compound) dimensions
% - the starred form has the pwroften exponent as the 2nd arg
% - naming is given by the official (where available) unit symbol; compounds
%   are simply catenated; reciprocals are indicated by a preceding p(er); 
%   exponents (e.g. meter cubed) are indicated by repeating the last letter
%   of the symbol
% - NB: the starred commands are fragile!!!
% - HINT: if just a number prefixed by a symbol (e.g. \approx) is to be 
%         typeset, \! should be used after the symbol (not, however if
%	   	  an equation is typeset, e.g. x\approx3)

\def\DIM{\@ifstar\@@DIM\@DIM}					% use directly

%----------------------------------------------------------------------
% internal commands
%----------------------------------------------------------------------

\newcommand\@DC{\!\cdot\!}						% typeset compound

\newcommand\@DIM[2]{\mbox{\ensuremath{#1\,\mathrm{#2}}}}			% dimensional numbers
\newcommand\@DDIM[3]{\mbox{\ensuremath{#1\,\mathrm{#2\@DC#3}}}}
\newcommand\@DDDIM[4]{\mbox{\ensuremath{#1\,\mathrm{#2\@DC#3\@DC#4}}}}

\newcommand\@@DIM[3]{\mbox{\ensuremath{#1\times10^{#2}\,\mathrm{#3}}}}	% power of ten
\newcommand\@@DDIM[4]{\mbox{\ensuremath{#1\times10^{#2}\,\mathrm{#3\@DC#4}}}}
\newcommand\@@DDDIM[5]{\mbox{\ensuremath{#1\times10^{#2}\,\mathrm{#3\@DC#4\@DC#5}}}}

%----------------------------------------------------------------------
% dimens starting with ° (degrees) and also '
% the degree symbol is special because there is officially no space before it 
% NB: the LaTeX function \deg (which typesets the string deg in math mode)
%	  is redefined
%----------------------------------------------------------------------

\renewcommand\deg[1]{\@DIM{#1}{\!^\circ{\!}}}			% degrees
\newcommand\arcmin[1]{\@DIM{#1}{^\prime{}}}				% minutes

\def\degC{\@ifstar\@@degC\@degC}						% temperature
	\newcommand\@degC [1]{\@DIM{#1}{\!^\circ C}}
	\newcommand\@@degC[2]{\@@DIM{#1}{#2}{^\circ C}}

\def\pdegC{\@ifstar\@@pdegC\@pdegC}						% temperature^-1
	\newcommand\@pdegC [1]{\@DIM{#1}{^\circ C^{-1}{}}}
	\newcommand\@@pdegC[2]{\@@DIM{#1}{#2}{^\circ C^{-1}{}}}

\newcommand\degCm[1]{\@DDIM{#1}{\!^\circ C}{m}}			% degrees * meters

\def\degCpV{\@ifstar\@@degCpV\@degCpV}					% degrees per volt
	\newcommand\@degCpV [1]{\@DDIM{#1}{\!^\circ C}{V^{-1}}}
	\newcommand\@@degCpV[2]{\@@DDIM{#1}{#2}{^\circ C}{V^{-1}}}

\def\degCpm{\@ifstar\@@degCpm\@degCpm}					% temperature gradient
	\newcommand\@degCpm [1]{\@DDIM{#1}{\!^\circ C}{m^{-1}}}
	\newcommand\@@degCpm[2]{\@@DDIM{#1}{#2}{^\circ C}{m^{-1}}}

\def\degCmmmps{\@ifstar\@@degCmmmps\@degCmmmps}			% temp anom flux
	\newcommand\@degCmmmps [1]{\@DDDIM{#1}{\!^\circ C}{m^3}{s^{-1}}}	
	\newcommand\@@degCmmmps[2]{\@@DDDIM{#1}{#2}{^\circ C}{m^3}{s^{-1}}}	

\newcommand\degCmmmpkg[1]{\@DDDIM{#1}{\!^\circ C}{m^3}{kg^{-1}}} % BILIN coeff B

\def\degCpkm{\@ifstar\@@degCpkm\@degCpkm}				% geographical temperature gradient
	\newcommand\@degCpkm [1]{\@DDIM{#1}{\!^\circ C}{km^{-1}}}
	\newcommand\@@degCpkm[2]{\@@DDIM{#1}{#2}{\!^\circ C}{km^{-1}}}

%----------------------------------------------------------------------
% geographical coordinates (lat/lon)
%----------------------------------------------------------------------

\newcommand\degN[1]{\@DIM{#1}{\!^\circ N}}
\newcommand\degS[1]{\@DIM{#1}{\!^\circ S}}
\newcommand\degE[1]{\@DIM{#1}{\!^\circ E}}
\newcommand\degW[1]{\@DIM{#1}{\!^\circ W}}

\newcommand\latN[2]{\@DIM{#1}{\!^\circ}\@DIM{#2}{^\prime N}}
\newcommand\latS[2]{\@DIM{#1}{\!^\circ}\@DIM{#2}{^\prime S}}
\newcommand\lonE[2]{\@DIM{#1}{\!^\circ}\@DIM{#2}{^\prime E}}
\newcommand\lonW[2]{\@DIM{#1}{\!^\circ}\@DIM{#2}{^\prime W}}

%----------------------------------------------------------------------
% no dimension (No unITS)
%----------------------------------------------------------------------

\def\nits{\@ifstar\@@nits\@nits}
	\newcommand\@nits [1]{\mbox{\ensuremath{#1}}}
	\newcommand\@@nits[2]{\mbox{\ensuremath{#1\times10^{#2}}}}

%----------------------------------------------------------------------
% simple dimensions
%----------------------------------------------------------------------

\def\m{\@ifstar\@@m\@mym}								% length
	\newcommand\@mym[1]{\@DIM{#1}{m}}
	\newcommand\@@m [2]{\@@DIM{#1}{#2}{m}}

\def\km{\@ifstar\@@km\@km}
	\newcommand\@km [1]{\@DIM{#1}{km}}
	\newcommand\@@km[2]{\@@DIM{#1}{#2}{km}}

\def\mm{\@ifstar\@@mm\@mm}								% area
	\newcommand\@mm [1]{\@DIM{#1}{m^2}}
	\newcommand\@@mm[2]{\@@DIM{#1}{#2}{m^2}}

\def\mmm{\@ifstar\@@mmm\@mmm}							% volume
	\newcommand\@mmm [1]{\@DIM{#1}{m^3}}
	\newcommand\@@mmm[2]{\@@DIM{#1}{#2}{m^3}}

\def\Sv{\@ifstar\@@Sv\@Sv}								% volume flux
	\newcommand\@Sv [1]{\@DIM{#1}{Sv}}
	\newcommand\@@Sv[2]{\@@DIM{#1}{#2}{Sv}}

\def\ps{\@ifstar\@@ps\@ps}								% frequency
	\newcommand\@ps [1]{\@DIM{#1}{s^{-1}}}
	\newcommand\@@ps[2]{\@@DIM{#1}{#2}{s^{-1}}}

\def\Pm{\@ifstar\@@pm\@pm}								% wave number
	\newcommand\@pm [1]{\@DIM{#1}{m^{-1}}}
	\newcommand\@@pm[2]{\@@DIM{#1}{#2}{m^{-1}}}

\def\pkm{\@ifstar\@@pkm\@pkm}							% non-dim gradient
	\newcommand\@pkm [1]{\@DIM{#1}{km^{-1}}}
	\newcommand\@@pkm[2]{\@@DIM{#1}{#2}{km^{-1}}}

\newcommand\s[1]{\@DIM{#1}{s}}							% time
\newcommand\h[1]{\@DIM{#1}{h}}
\renewcommand\d[2][s]{\ensuremath{#2} day#1}
\newcommand\w[2][s]{\ensuremath{#2} week#1}

\newcommand\dbar[1]{\@DIM{#1}{dbar}}					% pressure

\def\psu{\@ifstar\@@psu\@psu}							% salinity
	\newcommand\@psu [1]{\@DIM{#1}{psu}}
	\newcommand\@@psu[2]{\@@DIM{#1}{#2}{psu}}

\def\ppsu{\@ifstar\@@ppsu\@ppsu}						% per salinity
	\newcommand\@ppsu [1]{\@DIM{#1}{psu^{-1}}}
	\newcommand\@@ppsu[2]{\@@DIM{#1}{#2}{psu^{-1}}}

\def\W{\@ifstar\@@W\@W}									% power
	\newcommand\@W [1]{\@DIM{#1}{W}}
	\newcommand\@@W[2]{\@@DIM{#1}{#2}{W}}
\newcommand\GW[1]{\@DIM{#1}{GW}}

\newcommand\V[1]{\@DIM{#1}{V}}							% voltage

\newcommand\cph[1]{\@DIM{#1}{cph}}						% frequency
\def\cpd{\@ifstar\@@cpd\@cpd}
	\newcommand\@cpd [1]{\@DIM{#1}{cpd}}
	\newcommand\@@cpd[2]{\@@DIM{#1}{#2}{cpd}}

%----------------------------------------------------------------------
% 2 dimens compounded
%----------------------------------------------------------------------

\def\umolpkg{\@ifstar\@@umolpkg\@umolpkg}				% new O2 units
	\newcommand\@umolpkg [1]{\@DDIM{#1}{\mu mol}{kg^{-1}}}
	\newcommand\@@umolpkg[2]{\@@DDIM{#1}{#2}{\mu mol}{kg^{-1}}}

\def\kgpmmm{\@ifstar\@@kgpmmm\@kgpmmm}					% density
	\newcommand\@kgpmmm [1]{\@DDIM{#1}{kg}{m^{-3}}}
	\newcommand\@@kgpmmm[2]{\@@DDIM{#1}{#2}{kg}{m^{-3}}}

\def\kgpmmmm{\@ifstar\@@kgpmmmm\@kgpmmmm}				% density
	\newcommand\@kgpmmmm [1]{\@DDIM{#1}{kg}{m^{-4}}}
	\newcommand\@@kgpmmmm[2]{\@@DDIM{#1}{#2}{kg}{m^{-4}}}

\def\mps{\@ifstar\@@mps\@mps}							% velocity
	\newcommand\@mps [1]{\@DDIM{#1}{m}{s^{-1}}}
	\newcommand\@@mps[2]{\@@DDIM{#1}{#2}{m}{s^{-1}}}
	
\def\cmps{\@ifstar\@@cmps\@cmps}						% velocity
	\newcommand\@cmps [1]{\@DDIM{#1}{cm}{s^{-1}}}
	\newcommand\@@cmps[2]{\@@DDIM{#1}{#2}{cm}{s^{-1}}}

\def\mpd{\@ifstar\@@mpd\@mpd}							% velocity
	\newcommand\@mpd [1]{\@DDIM{#1}{m}{day^{-1}}}
	\newcommand\@@mpd[2]{\@@DDIM{#1}{#2}{m}{day^{-1}}}

\def\mmps{\@ifstar\@@mmps\@mmps}						% diffusivity
	\newcommand\@mmps [1]{\@DDIM{#1}{m^2}{s^{-1}}}
	\newcommand\@@mmps[2]{\@@DDIM{#1}{#2}{m^2}{s^{-1}}}

\def\mmmmpsss{\@ifstar\@@mmmmpsss\@mmmmpsss}			% buoyancy flux
	\newcommand\@mmmmpsss [1]{\@DDIM{#1}{m^4}{s^{-3}}}
	\newcommand\@@mmmmpsss[2]{\@@DDIM{#1}{#2}{m^4}{s^{-3}}}

\def\Wpmm{\@ifstar\@@Wpmm\@Wpmm}						% heat flow
	\newcommand\@Wpmm [1]{\@DDIM{#1}{W}{m^{-2}}}
	\newcommand\@@Wpmm[2]{\@@DDIM{#1}{#2}{W}{m^{-2}}}

\newcommand\cmpa[1]{\@DDIM{#1}{cm}{a^{-1}}}
\newcommand\kmpd[1]{\@DDIM{#1}{km}{d^{-1}}}

\def\mmpss{\@ifstar\@@mmpss\@mmpss}						% energy
	\newcommand\@mmpss [1]{\@DDIM{#1}{m^2}{s^{-2}}}
	\newcommand\@@mmpss[2]{\@@DDIM{#1}{#2}{m^2}{s^{-2}}}

\def\Spm{\@ifstar\@@Spm\@Spm}                           % conductivity
	\newcommand\@Spm [1]{\@DDIM{#1}{S}{m^{-1}}}      
	\newcommand\@@Spm[2]{\@@DDIM{#1}{#2}{S}{m^{-1}}}

\def\mpss{\@ifstar\@@mpss\@mpss}						% acceleration
	\newcommand\@mpss [1]{\@DDIM{#1}{m}{s^{-2}}}
	\newcommand\@@mpss[2]{\@@DDIM{#1}{#2}{m}{s^{-2}}}

\def\mmmps{\@ifstar\@@mmmps\@mmmps}						% volume flux
	\newcommand\@mmmps [1]{\@DDIM{#1}{m^3}{s^{-1}}}
	\newcommand\@@mmmps[2]{\@@DDIM{#1}{#2}{m^3}{s^{-1}}}

\def\kgps{\@ifstar\@@kgps\@kgps}						% mass flux
	\newcommand\@kgps [1]{\@DDIM{#1}{kg}{s^{-1}}}
	\newcommand\@@kgps[2]{\@@DDIM{#1}{#2}{kg}{s^{-1}}}

\def\psupkm{\@ifstar\@@psupkm\@psupkm}					% geographical salin gradient
	\newcommand\@@psupkm[2]{\@@DDIM{#1}{#2}{psu}{km^{-1}}}

\def\psupm{\@ifstar\@@psupm\@psupm}						% salinity gradient
	\newcommand\@psupm [1]{\@DDIM{#1}{psu}{m^{-1}}}
	\newcommand\@@psupm[2]{\@@DDIM{#1}{#2}{psu}{m^{-1}}}

\def\pmps{\@ifstar\@@pmps\@pmps}						% PV
	\newcommand\@pmps [1]{\@DDIM{#1}{m^{-1}}{s^{-1}}}
	\newcommand\@@pmps[2]{\@@DDIM{#1}{#2}{m^{-1}}{s^{-1}}}

%----------------------------------------------------------------------
% 3 dimens compounded
%----------------------------------------------------------------------

\def\JpkgpK{\@ifstar\@@JpkgpK\@JpkgpK}					% specific heat
	\newcommand\@JpkgpK [1]{\@DDDIM{#1}{J}{kg^{-1}}{K^{-1}}}
	\newcommand\@@JpkgpK[2]{\@@DDDIM{#1}{#2}{J}{kg^{-1}}{K^{-1}}}

\def\kgpmmmpkm{\@ifstar\@@kgpmmmpkm\@kgpmmmpkm}			% horiz density grad
	\newcommand\@kgpmmmpkm [1]{\@DDDIM{#1}{kg}{m^{-3}}{km^{-1}}}
	\newcommand\@@kgpmmmpkm[2]{\@@DDDIM{#1}{#2}{kg}{m^{-3}}{km^{-1}}}

\def\kgpmmmpm{\@ifstar\@@kgpmmmpm\@kgpmmmpm}			% horiz density grad
	\newcommand\@kgpmmmpm [1]{\@DDDIM{#1}{kg}{m^{-3}}{m^{-1}}}
	\newcommand\@@kgpmmmpm[2]{\@@DDDIM{#1}{#2}{kg}{m^{-3}}{m^{-1}}}

