Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/dens_poly3.m is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
b30af0ec84 Alis*0001 function [dens] = dens_poly3(poly3,t,s)
                0002 % D=DENS_POLY3(P,T,S)
                0003 %
                0004 % Calculates in-situ density as approximated by the POLY3 method
                0005 % used in the MITgcm.
                0006 %  P - coefficients read from file 'POLY3.COEFFS' using INI_POLY3
                0007 %  T - potential temperature
                0008 %  S - salinity
                0009 %
                0010 % eg.
                0011 % >> P=ini_poly3;
                0012 % >> T=rdmds('T',100);
                0013 % >> S=rdmds('S',100);
                0014 % >> D=dens_poly3(P,T,S);
                0015 %
                0016 % or to work within a single model level
                0017 % >> D=dens_poly3(P(3),T(:,:,3),S(:,:,3));
                0018 
                0019 if size(t) ~= size(s)
                0020  error('T and S must be the same shape and size')
                0021 end
                0022 %if size(t,ndims(t)) ~= size(poly3,2)
                0023 % error('Last dimension of T and S must be the number of levels in P')
                0024 %end
                0025 
                0026 n=size(t);
                0027 nz=size(poly3,2);
                0028 
                0029 t=reshape(t,[prod(size(t))/nz nz]);
                0030 s=reshape(s,[prod(size(t))/nz nz]);
                0031 
                0032 for k=1:nz,
                0033  tRef=poly3(k).t;
                0034  sRef=poly3(k).s;
                0035  dRef=poly3(k).dens;
                0036  tp=t(:,k)-tRef;
                0037  sp=s(:,k)-sRef;
                0038 
                0039  deltaSig=                                    ...
                0040   poly3(k).coeffs(1) .*tp                     ...
                0041  +poly3(k).coeffs(2)             .*sp         ...
                0042  +poly3(k).coeffs(3) .*tp.*tp                 ...
                0043  +poly3(k).coeffs(4) .*tp        .*sp         ...
                0044  +poly3(k).coeffs(5)             .*sp.*sp     ...
                0045  +poly3(k).coeffs(6) .*tp.*tp.*tp             ...
                0046  +poly3(k).coeffs(7) .*tp.*tp    .*sp         ...
                0047  +poly3(k).coeffs(8) .*tp        .*sp.*sp     ...
                0048  +poly3(k).coeffs(9)             .*sp.*sp.*sp ...
                0049   ;
                0050  dens(:,k)=deltaSig+dRef;
                0051 end
                0052 
                0053 dens=reshape(dens,n);
90e90d14bf Alis*0054 dens( find(t==0 & s==0) )=0;