0001 function [u,x,z] = scrum_jslice(cdf,var,timestep,jindex,irange)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 if ( (nargin < 4) | ( nargin > 5) ) ,
0020 help scrum_jslice; return
0021 end
0022
0023
0024
0025 ncmex('setopts',0);
0026
0027 ncid=ncmex('open',cdf,'nowrite');
0028 if(ncid==-1),
0029 disp(['file ' cdf ' not found'])
0030 return
0031 end
0032
0033 [name, nx]=ncmex('diminq',ncid,'xi_rho');
0034 [name, nz]=ncmex('diminq',ncid,'s_rho');
0035 if(exist('irange')),
0036 irange(1)=max(1,irange(1));
0037 irange(2)=min(nx-1,irange(2));
0038 istart=irange(1)-1;
0039 icount=irange(2)-irange(1)+1;
0040 else
0041 istart=1
0042 icount=nx-2;
0043 end
0044
0045
0046
0047
0048 u = ncmex( 'varget', ncid, var, ...
0049 [(timestep-1) 0 (jindex-1) istart],...
0050 [1 nz 1 icount] );
0051 u = squeeze(u);
0052
0053
0054
0055 if ( nargout > 1 )
0056 h = ncmex( 'varget', ncid, 'h', [(jindex-1) istart], [1 icount] );
0057 h = h';
0058
0059
0060
0061 [mask_rho_varid, status] = ncmex ( 'varid', ncid, 'mask_rho' );
0062 if ( mask_rho_varid ~= -1 )
0063 mask_rho = ncmex( 'varget', ncid, mask_rho_varid, ...
0064 [(jindex-1) istart], [1 icount] );
0065 mask_rho = mask_rho';
0066 land = find ( mask_rho == 0 );
0067 h(land) = h(land) * NaN;
0068 u(land,:)=u(land,:)*NaN;
0069 end
0070
0071
0072
0073
0074
0075
0076
0077 [s_rho_dimid, status] = ncmex ( 'dimid', ncid, 's_rho' );
0078 if ( status == -1 )
0079 fprintf ( 2, 'Could not get s_rho dimid from %s.\n', cdf );
0080 ncmex ( 'close', ncid );
0081 return;
0082 end
0083
0084 [dimname, s_rho_length, status] = ncmex ( 'diminq', ncid, s_rho_dimid );
0085 if ( status == -1 )
0086 fprintf ( 2, 'Could not get s_rho length from %s.\n', cdf );
0087 ncmex ( 'close', ncid );
0088 return;
0089 end
0090
0091
0092
0093
0094
0095 if ( strcmp(var,'w') )
0096 [sc, status] = ncmex ( 'varget', ncid, 'sc_w', [0], [-1] );
0097 else
0098 [sc, status] = ncmex ( 'varget', ncid, 'sc_r', [0], [-1] );
0099 end
0100
0101
0102 [zeta, status] = ncmex ( 'varget', ncid, 'zeta', ...
0103 [timestep (jindex-1) istart], [1 1 icount] );
0104 zeta = zeta';
0105
0106 [hc, status] = ncmex ( 'varget1', ncid, 'hc', [0] );
0107 if ( status == -1 )
0108 fprintf ( 2, 'Could not get hc from %s.\n', cdf );
0109 ncmex ( 'close', ncid );
0110 return;
0111 end
0112
0113
0114 [Cs_r, status] = ncmex ( 'varget', ncid, 'Cs_r', [0], [-1] );
0115 if ( status == -1 )
0116 fprintf ( 'scrum_zslice: could not get ''Cs_r'' in %s.', cdf );
0117 return;
0118 end
0119
0120
0121
0122 z = zeta'*(1+sc) + ones(size(h'))*hc*sc + (h'-hc)*Cs_r;
0123
0124 pm = ncmex ( 'varget', ncid, 'pm', [(jindex-1) istart], [1 icount] );
0125 pm = pm';
0126
0127
0128 x = ncmex ( 'varget', ncid, 'x_rho', [(jindex-1) istart], [1 icount] );
0129 x = x';
0130 x=x'*ones(1,nz);
0131 x = x/1000;
0132 ind=find(isnan(z));
0133 z(ind)=zeros(size(ind));
0134
0135 end
0136 ncmex('close',ncid);
0137
0138 u = u'; x = x';z=z';