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

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

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

Initial import of Stark code.

Line 
1
2 function [ga] = sw_gpan(S,T,P)
3
4 % SW_GPAN    Geopotential anomaly
5 %=========================================================================
6 % SW_GPAN  $Id: sw_gpan.m,v 1.1 2003/12/12 04:23:22 pen078 Exp $
7 %          Copyright (C) CSIRO, Phil Morgan 1992.
8 %
9 % USAGE:  [gpan]= sw_gpan(S,T,P)
10 %
11 % DESCRIPTION:
12 %   Geopotential Anomaly calculated as the integral of svan from the
13 %   the sea surface to the bottom.  Thus RELATIVE TO SEA SURFACE.
14 %
15 % INPUT:  (all must have same dimensions)
16 %   S = salinity    [psu      (PSS-78)]
17 %   T = temperature [degree C (ITS-90)]
18 %   P = Pressure    [db]
19 %       (P may have dims 1x1, mx1, 1xn or mxn for S(mxn) )
20 %
21 % OUTPUT:
22 %  gpan = Geopotential Anomaly  [m^3 kg^-1 Pa == m^2 s^-2 == J kg^-1]
23 %
24 % AUTHOR:  Phil Morgan 92-11-05, Lindsay Pender (Lindsay.Pender@csiro.au)
25 %
26 % DISCLAIMER:
27 %   This software is provided "as is" without warranty of any kind.
28 %   See the file sw_copy.m for conditions of use and licence.
29 %
30 % REFERENCE: S. Pond & G.Pickard  2nd Edition 1986
31 %            Introductory Dynamical Oceanogrpahy
32 %            Pergamon Press Sydney.  ISBN 0-08-028728-X
33 %
34 % Note that older literature may use units of "dynamic decimeter' for above.
35 %
36 % Adapted method from Pond and Pickard (p76) to calc gpan rel to sea
37 % surface whereas P&P calculated relative to the deepest common depth.
38 %=========================================================================
39
40 % Modifications
41 % 03-12-12. Lindsay Pender, Converted to ITS-90.
42
43 %
44 % CALLER: general purpose
45 % CALLEE: sw_svan.m
46
47 %----------------------
48 % CHECK INPUT ARGUMENTS
49 %----------------------
50 if nargin ~=3
51    error('Must pass 3 parameters')
52 end %if
53
54 % CHECK S,T,P dimensions and verify consistent
55 [ms,ns] = size(S);
56 [mt,nt] = size(T);
57 [mp,np] = size(P);
58
59
60 % CHECK THAT S & T HAVE SAME SHAPE
61 if (ms~=mt) | (ns~=nt)
62    error('S & T must have same dimensions')
63 end %if
64
65 % CHECK OPTIONAL SHAPES FOR P
66 if     mp==1  & np==1      % P is a scalar.  Fill to size of S
67    P = P(1)*ones(ms,ns);
68 elseif np==ns & mp==1      % P is row vector with same cols as S
69    P = P( ones(1,ms), : ); %   Copy down each column.
70 elseif mp==ms & np==1      % P is column vector
71    P = P( :, ones(1,ns) ); %   Copy across each row
72 elseif mp==ms & np==ns     % PR is a matrix size(S)
73    % shape ok
74 else
75    error('P has wrong dimensions')
76 end %if
77 [mp,np] = size(P);
78
79
80
81 % IF ALL ROW VECTORS ARE PASSED THEN LET US PRESERVE SHAPE ON RETURN.
82 Transpose = 0;
83 if mp == 1  % row vector
84    P       =  P(:);
85    T       =  T(:);
86    S       =  S(:);
87
88    Transpose = 1;
89 end %if
90 %***check_stp
91
92 %------
93 % BEGIN
94 %------
95 db2Pascal  = 1e4;
96 [m,n]      = size(P);
97 svan       = sw_svan(S,T,P);
98 mean_svan  = 0.5*(svan(2:m,:) + svan(1:m-1,:) );
99
100 if n==1
101    top = svan(1,1).*P(1,1)*db2Pascal;
102 else
103    top = svan(1,:).*P(1,:)*db2Pascal;
104 end %if
105
106 %press_diff = diff(P);
107
108 delta_ga   = (mean_svan.*diff(P))*db2Pascal;
109 ga         = cumsum([ top; delta_ga]);
110
111 if Transpose
112    ga = ga';
113 end %if
114
Note: See TracBrowser for help on using the browser.