Home > omviz > scrum_jslice.m

scrum_jslice

PURPOSE ^

SCRUM_JSLICE: returns a vertical slice along j=jindex, SCRUM file.

SYNOPSIS ^

function [u,x,z] = scrum_jslice(cdf,var,timestep,jindex,irange)

DESCRIPTION ^

SCRUM_JSLICE:  returns a vertical slice along j=jindex, SCRUM file.

 The variable must be 4D.
 
 USAGE:
 >> [u,x,z] = scrum_jslice(cdf,var,time,jindex,[irange])
        u = the selected variable
        x = distance in *km* (assuming x units in netCDF file are in meters)
        z = depth in m
        jindex = j index along which slice is taken
        irange = imin and imax indices along slice (optional).  If this
           argument is not supplied the default takes all the I indices
           except for the first and last, which are always "land" cells.

 see also ISLICE, KSLICE, ZSLICE, ZSLICEUV, KSLICEUV

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [u,x,z] = scrum_jslice(cdf,var,timestep,jindex,irange)
0002 %SCRUM_JSLICE:  returns a vertical slice along j=jindex, SCRUM file.
0003 %
0004 % The variable must be 4D.
0005 %
0006 % USAGE:
0007 % >> [u,x,z] = scrum_jslice(cdf,var,time,jindex,[irange])
0008 %        u = the selected variable
0009 %        x = distance in *km* (assuming x units in netCDF file are in meters)
0010 %        z = depth in m
0011 %        jindex = j index along which slice is taken
0012 %        irange = imin and imax indices along slice (optional).  If this
0013 %           argument is not supplied the default takes all the I indices
0014 %           except for the first and last, which are always "land" cells.
0015 %
0016 % see also ISLICE, KSLICE, ZSLICE, ZSLICEUV, KSLICEUV
0017 %
0018 
0019 if ( (nargin < 4) | ( nargin > 5) ) ,
0020   help scrum_jslice; return
0021 end
0022 
0023 %
0024 % Suppress NetCDF warnings.
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 % ecom_jslice just goes to (nz-1), don't really
0047 % know why.
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 % If the grid itself was asked for..
0055 if ( nargout > 1 )
0056     h = ncmex( 'varget', ncid, 'h', [(jindex-1) istart], [1 icount] );
0057     h = h';
0058 
0059     %
0060     % Find the land cells with mask_rho.
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     % Get all the variables needed to compute z.
0074     % The equation is
0075     %
0076     % z = zeta * (1 + s) + hc*s + (h - hc)*C(s)
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     % w is defined at different locations than the others
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 %    y=cumsum(pm)/1000;
0127 %    y=y*ones(1,nz);
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';

Generated on Thu 01-Dec-2005 08:50:35 by m2html © 2003