NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/seawater/sw_bfrq.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1
2 function [n2,q,p_ave] = sw_bfrq(S,T,P,LAT)
3
4 % SW_BFRQ    Brunt-Vaisala Frequency Squared (N^2)
5 %===========================================================================
6 % SW_BFRQ  $Id: sw_bfrq.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $
7 %          Copyright (C) CSIRO, Phil Morgan  1993.
8 %
9 % USAGE:  [bfrq,vort,p_ave] = sw_bfrq(S,T,P,{LAT})
10 %
11 % DESCRIPTION:
12 %    Calculates Brunt-Vaisala Frequency squared (N^2) at the mid depths
13 %    from the equation,
14 %
15 %               -g      d(pdens)
16 %         N2 =  ----- x --------
17 %               pdens     d(z)
18 %
19 %    Also returns Potential Vorticity from q = f*N2/g.
20 %
21 % INPUT:  (all must have same dimensions MxN)
22 %   S   = salinity    [psu      (PSS-78) ]
23 %   T   = temperature [degree C (ITS-90)]
24 %   P   = pressure    [db]
25 %
26 %   OPTIONAL:
27 %      LAT     = Latitude in decimal degrees north [-90..+90]
28 %                May have dimensions 1x1 or 1xN where S(MxN).
29 %                (Will use sw_g instead of the default g=9.8 m^2/s)
30 %                (Will also calc d(z) instead of d(p) in numerator)
31 % OUTPUT:
32 %   bfrq  = Brunt-Vaisala Frequency squared (M-1xN)  [s^-2]
33 %   vort  = Planetary Potential Vorticity   (M-1xN)  [(ms)^-1]
34 %           (if isempty(LAT) vort=NaN )
35 %   p_ave = Mid pressure between P grid     (M-1xN)  [db]
36 %
37 % AUTHOR:  Phil Morgan 93-06-24, Lindsay Pender (Lindsay.Pender@csiro.au)
38 %
39 % DISCLAIMER:
40 %   This software is provided "as is" without warranty of any kind.
41 %   See the file sw_copy.m for conditions of use and licence.
42 %
43 % REFERENCES:
44 %   A.E. Gill 1982. p.54  eqn 3.7.15
45 %   "Atmosphere-Ocean Dynamics"
46 %   Academic Press: New York.  ISBN: 0-12-283522-0
47 %
48 %   Jackett, D.R. and McDougall, T.J. 1994.
49 %   Minimal adjustment of hydrographic properties to achieve static
50 %   stability.  submitted J.Atmos.Ocean.Tech.
51 %
52 %   Greg Johnson (gjohnson@pmel.noaa.gov)
53 %                added potential vorticity calcuation
54 %=========================================================================
55
56 % Modifications
57 % 03-12-12. Lindsay Pender, Converted to ITS-90.
58 % 06-04-19. Lindsay Pender, Corrected sign of PV.
59
60 % CALLER:  general purpose
61 % CALLEE:  sw_dens.m sw_pden.m
62
63 %$Id: sw_bfrq.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $
64
65 %-------------
66 % Check Inputs
67 %-------------
68
69 error(nargchk(3, 4, nargin));
70
71 if nargin == 3
72     LAT = [];
73 end
74
75 % Get S,T,P dimensions and check consistency
76
77 [ms,ns] = size(S);
78 [mt,nt] = size(T);
79 [mp,np] = size(P);
80
81 % Check S, T P and have the same shape
82
83 if (ms~=mt) | (ns~=nt) | (np~=np)
84     error('S, T & P must have same dimensions')
85 end
86
87 % Check S and T have length at least of 2
88
89 if (ms * ns == 1)
90     error('Length of T, S and P must be at least 2')
91 end
92
93 % If S, T and P are row vectors - transpose
94
95 if ms == 1
96     S = S';
97     T = T';
98     P = P';
99     transpose = 1;
100 else
101     transpose = 0;
102 end
103
104 % If lat passed then verify dimensions
105
106 if ~isempty(LAT)
107     [mL,nL] = size(LAT);
108     if mL==1 & nL==1
109         LAT = LAT*ones(size(S));
110     else
111         if (ms~=mL) | (ns~=nL)              % S & LAT are not the same shape
112             if (ns==nL) & (mL==1)           % copy LATS down each column
113                 LAT = LAT( ones(1,ms), : );  % s.t. dim(S)==dim(LAT)
114             else
115                 error('Inputs arguments have wrong dimensions')
116             end
117         end
118     end
119 end
120
121 %------
122 % Begin
123 %------
124
125 if ~isempty(LAT)
126     % note that sw_g expects height as argument
127     Z = sw_dpth(P,LAT);
128     g = sw_g(LAT,-Z);
129     f = sw_f(LAT);
130 else
131     Z = P;
132     g = 9.8*ones(size(P));
133     f = NaN*ones(size(P));
134 end %if
135
136 [m,n] = size(P);
137 iup   = 1:m-1;
138 ilo   = 2:m;
139 p_ave = (P(iup,:)+P(ilo,:) )/2;
140 pden_up = sw_pden(S(iup,:),T(iup,:),P(iup,:),p_ave);
141 pden_lo = sw_pden(S(ilo,:),T(ilo,:),P(ilo,:),p_ave);
142
143 mid_pden = (pden_up + pden_lo )/2;
144 dif_pden = pden_up - pden_lo;
145 mid_g    = (g(iup,:)+g(ilo,:))/2;
146 dif_z    = diff(Z);
147 n2       = -mid_g .* dif_pden ./ (dif_z .* mid_pden);
148
149 mid_f    = f(iup,:);
150 q        = -mid_f .* dif_pden ./  (dif_z .* mid_pden);
151
152 if transpose
153     n2    = n2';
154     q     = q';
155     p_ave = p_ave';
156 end
157
Note: See TracBrowser for help on using the browser.