0001 function [wmean,x,y]=scrum_depaveuv(cdfin,tind,bounds)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 if(nargin==1),
0034 tind=1;
0035 end
0036
0037 ncid=mexcdf('open',cdfin,'nowrite');
0038 if(ncid==-1),
0039 disp(['file ' cdf ' not found'])
0040 return
0041 end
0042
0043
0044
0045
0046
0047
0048
0049 [lon_rho_varid, rcode] = ncmex('VARID', ncid, 'lon_rho');
0050 [lat_rho_varid, rcode] = ncmex('VARID', ncid, 'lat_rho');
0051 if ( (lon_rho_varid >= 0) | (lat_rho_varid >= 0) )
0052 x=ncmex('varget',ncid,'lon_rho',[0 0],[-1 -1]);
0053 y=ncmex('varget',ncid,'lat_rho',[0 0],[-1 -1]);
0054 else
0055 x=ncmex('varget',ncid,'x_rho',[0 0],[-1 -1]);
0056 y=ncmex('varget',ncid,'y_rho',[0 0],[-1 -1]);
0057 end
0058
0059 x_rho = x;
0060 y_rho = y;
0061
0062 [eta_rho_length, xi_rho_length] = size(x_rho);
0063 eta_u_length = eta_rho_length;
0064 eta_v_length = eta_rho_length-1;
0065 xi_u_length = xi_rho_length-1;
0066 xi_v_length = xi_rho_length;
0067 eta_psi_length = eta_rho_length-1;
0068 xi_psi_length = xi_rho_length-1;
0069
0070
0071
0072
0073 xtemp = (x_rho(:,1:(xi_rho_length-1)) + x_rho(:,2:xi_rho_length))/2;
0074 x = (xtemp(1:(eta_rho_length-1),:) + xtemp(2:eta_rho_length,:))/2;
0075 ytemp = (y_rho(:,1:(xi_rho_length-1)) + y_rho(:,2:xi_rho_length))/2;
0076 y = (ytemp(1:(eta_rho_length-1),:) + ytemp(2:eta_rho_length,:))/2;
0077
0078
0079
0080
0081
0082 [u_bar, status] = ncmex ( 'varget', ncid, 'ubar', [tind-1 0 0], [1 -1 -1] );
0083 if ( status == -1 )
0084 fprintf ( 'scrum_depaveuv: could not get ubar in %s.', cdf );
0085 return;
0086 end
0087 [v_bar, status] = ncmex ( 'varget', ncid, 'vbar', [tind-1 0 0], [1 -1 -1] );
0088 if ( status == -1 )
0089 fprintf ( 'scrum_depaveuv: could not get vbar in %s.', cdf );
0090 return;
0091 end
0092
0093
0094
0095 [mask_rho_varid, status] = ncmex ( 'varid', ncid, 'mask_rho' );
0096 if ( status ~= -1 )
0097 [mask_rho, status] = ncmex ( 'varget', ncid, 'mask_rho', [0 0], [-1 -1] );
0098 if ( status == -1 )
0099 fprintf ( 'scrum_zsliceuv: could not get ''mask_rho'' in %s.', cdf );
0100 return;
0101 end
0102 end
0103
0104
0105 ncmex ( 'close', ncid );
0106
0107
0108
0109 [r,c] = size(u_bar);
0110 u_bar = (u_bar(:,1:c-1) + u_bar(:,2:c))/2;
0111 [r,c] = size(v_bar);
0112 v_bar = (v_bar(1:r-1,:) + v_bar(2:r,:))/2;
0113
0114
0115
0116
0117 wmean = u_bar + sqrt(-1) * v_bar;
0118
0119
0120
0121
0122 [nx,ny] = size(wmean);
0123 if ( nargin < 3 )
0124 x1 = 1;
0125 y1 = 1;
0126 x2 = nx;
0127 y2 = ny;
0128 else
0129 if (min(bounds(:))<=0)
0130 disp('out of bounds');
0131 return;
0132 end
0133 if (length(bounds)~=4)
0134 disp('out of bounds');
0135 return;
0136 end
0137 if (bounds(2) >= nx )
0138 disp('out of bounds');
0139 return;
0140 end
0141 if (bounds(4) >= ny )
0142 disp('out of bounds');
0143 return;
0144 end
0145
0146 x1 = bounds(1);
0147 x2 = bounds(2);
0148 y1 = bounds(3);
0149 y2 = bounds(4);
0150
0151 end
0152
0153
0154
0155
0156
0157
0158
0159 angle = zeros(size(x));
0160
0161
0162
0163 [r,c] = size(x);
0164 j = [2:c-1];
0165 for i = 2:r-1
0166 angle(i,j) = atan2(y(i+1,j)-y(i-1,j), x(i+1,j)-x(i-1,j));
0167 end
0168
0169
0170 wmean=wmean.*exp(sqrt(-1)*angle);
0171
0172
0173 wmean = wmean(x1:x2,y1:y2);
0174 x = x(x1:x2,y1:y2);
0175 y = y(x1:x2,y1:y2);
0176
0177
0178
0179
0180
0181
0182
0183 [umask,vmask,pmask]=uvp_masks ( mask_rho );
0184 mask_inds = find ( pmask == 0 );
0185 wmean(mask_inds) = NaN * ones(size(mask_inds));
0186
0187
0188 return;