Home > omviz > tsvel.m

tsvel

PURPOSE ^

TSVEL Reads velocity variable at a particular station from TSEPIC.CDF files.

SYNOPSIS ^

function [w,jd,z]=tsvel(cdf,sta,z);

DESCRIPTION ^

 TSVEL Reads velocity variable at a particular station from TSEPIC.CDF files.
 Returns data from all sigma layers, or intepolates to specified depths.
 
 USAGE:
   1.  [u,jd,z]=tsvel(cdf,sta);  to return a matrix containing time,depth
                                 information for variable "var" at station 
                                 sta for all sigma levels. 
 
   2.  [u,jd]=ts(cdf,sta,depths);  
                                 to return a matrix containing time,depth
                                 information for variable "var" at station 
                                 sta for depths specified in vector "depths". 

       Example: [t,jd]=ts('tsepic.cdf','temp',2,[-2 -10 -24]); 
              Returns a matrix containing temperature at Station 2 at 
              2, 10 and 24 m below surface.  jd is the julian day vector.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [w,jd,z]=tsvel(cdf,sta,z);
0002 % TSVEL Reads velocity variable at a particular station from TSEPIC.CDF files.
0003 % Returns data from all sigma layers, or intepolates to specified depths.
0004 %
0005 % USAGE:
0006 %   1.  [u,jd,z]=tsvel(cdf,sta);  to return a matrix containing time,depth
0007 %                                 information for variable "var" at station
0008 %                                 sta for all sigma levels.
0009 %
0010 %   2.  [u,jd]=ts(cdf,sta,depths);
0011 %                                 to return a matrix containing time,depth
0012 %                                 information for variable "var" at station
0013 %                                 sta for depths specified in vector "depths".
0014 %
0015 %       Example: [t,jd]=ts('tsepic.cdf','temp',2,[-2 -10 -24]);
0016 %              Returns a matrix containing temperature at Station 2 at
0017 %              2, 10 and 24 m below surface.  jd is the julian day vector.
0018 %
0019 ncid=mexcdf('open',cdf);
0020 [t]=mexcdf('varget',ncid,'time',0,-1);
0021 t=t(:);
0022 nt=length(t);
0023 [dattype,len,status]=mexcdf('attinq',ncid,-1,'TSCDF_VERSION');
0024   if(status~=-1),
0025     cdf_version=mexcdf('attget',ncid,-1,'TSCDF_VERSION');
0026   else
0027     cdf_version='1.0';
0028   end
0029 %
0030 [stations]=mexcdf('varget',ncid,'stations',0,-1);
0031 nsta=length(stations);
0032 %
0033 [sigma]=mexcdf('varget',ncid,'sigma',0,-1);
0034 nsigma=length(sigma);
0035 sigma(nsigma+1)=-1;
0036 %  velocity exists at center of two sigma surfaces, so average z level
0037 sigma=0.5*(sigma(1:nsigma)+sigma(2:nsigma+1));
0038 if(sta>nsta),
0039   disp('invalid station');
0040   return
0041 end
0042 %
0043 corner=[0 0 0 sta-1];
0044 edges=[nt, nsigma, 1, 1];
0045 u=mexcdf('varget',ncid,'u',corner,edges);
0046 v=mexcdf('varget',ncid,'v',corner,edges);
0047 w=u+sqrt(-1)*v;
0048 w=w.';
0049 [m,n]=size(w);
0050 % if w is 2d, we need to fliplr, since data is stored with
0051 %  depth increasing upward in tsepic.cdf
0052 %  (in tsepic.cdf, index 0 = sea bed!)
0053  if(m~=1),
0054   if(cdf_version(1:3)=='1.0')
0055       w=fliplr(w);
0056   end
0057  end
0058 depth=mexcdf('varget',ncid,'depth',0,-1);
0059 depth=depth(sta)*sigma;
0060 if(nargin>2),
0061   m=length(z);
0062   if(min(z)<min(depth)), disp('requested level below data!'),return,end
0063   if(max(z)>max(depth)), disp('requested level above data!'),return,end
0064   for k=1:m,
0065     lev2=max(find(depth>z(k)));
0066     lev1=lev2+1;
0067     frac=(z(k)-depth(lev1))/(depth(lev2)-depth(lev1));
0068     wmod(:,k)=w(:,lev1)+frac*(w(:,lev2)-w(:,lev1));
0069   end
0070   w=wmod;
0071 else
0072   z=depth;
0073 end
0074 %
0075 base_date=zeros(1,6);
0076 base_date(1:3)=mexcdf('attget',ncid,-1,'base_date');
0077 jd0=julian(base_date);
0078 jd=jd0+t/(3600*24);
0079 mexcdf('close',ncid);

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