Warning, /verification/tutorial_global_oce_latlon/diags_matlab/mit_overturning.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
051ee7f715 Jean*0001 function [psi, psimask] = mit_overturning(v,vmask,dx,dz,addlayer);
0002 %function [psi, psimask] = mit_overturning(v,vmask,dx,dz);
0003 % overturning stream function for mitgcm model, time slabs are handled as
0004 % cell objects, integration from bottom to top.
0005
0006 if nargin < 5
0007 addlayer = 0;
0008 elseif (nargin > 5 & nargin < 4)
0009 error('needs 4 or 5 arguments')
0010 end
0011 [nx ny nz] = size(vmask);
0012 for kz=1:nz
0013 dxdzs(:,:,kz) = (vmask(:,:,kz).*dx)*dz(kz);
0014 end
0015
0016 % mask for stream function
0017 pmask = change(squeeze(nanmean(vmask)),'~=',NaN,1);
0018 % add another psi-point at the bottom of each column
0019 for ky=1:ny;
0020 iz = min(find(isnan(pmask(ky,:))));
0021 if ~isempty(iz) & iz > 1
0022 pmask(ky,iz) = 1;
0023 end
0024 end
0025 if iscell(v)
0026 nt = length(v);
0027 psi = cell(size(v));
0028 for k=1:nt
0029 vdxdz = v{k}(:,:,:).*dxdzs; %(dxdzs.*vmask);
0030 zave = fliplr(change(squeeze(nansum(vdxdz)),'==',NaN,0));
0031 psi{k} = -fliplr(cumsum(zave,2)).*pmask;
0032 end
0033 else
0034 nt = size(v,4);
0035 for k=1:nt
0036 vdxdz = squeeze(v(:,:,:,k)).*dxdzs; %(dxdzs.*vmask);
0037 zave = fliplr(squeeze(sum(change(vdxdz,'==',NaN,0),1)));
0038 psi(:,:,k) = -fliplr(cumsum(zave,2)).*pmask;
0039 end
0040 end
0041 % add another layer at the bottom; psi is zero in the layer by definition
0042 if addlayer
0043 disp('mit_overturning: adding a layer with psi = 0 at the bottom')
0044 pmask = [pmask pmask(:,end)];
0045 if iscell(psi)
0046 nt = length(psi);
0047 for k=1:nt
0048 psi{k} = [psi{k} change(psi{k}(:,end),'~=',NaN,0)];
0049 end
0050 else
0051 psi = cat(2,psi,change(psi(:,end,:),'~=',NaN,0));
0052 end
0053 end
0054 if nargout == 2
0055 psimask = pmask;
0056 end
0057
0058 return
0059
0060
0061
0062
0063