


TS Reads a scalar 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]=ts(cdf,var,sta); to return a matrix containing time,depth
information for variable "var" at station
sta for all sigma levels.
2. [u,jd]=ts(cdf,var,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.

0001 function [w,jd,z]=ts(cdf,var,sta,z); 0002 % TS Reads a scalar 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]=ts(cdf,var,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,var,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 % salt,temp 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,var,corner,edges); 0046 w=u.'; 0047 [m,n]=size(w); 0048 % if w is 2d, we need to fliplr, since data is stored with 0049 % depth increasing upward in tsepic.cdf 0050 % (in tsepic.cdf, index 0 = sea bed!) 0051 if(m~=1), 0052 if(cdf_version(1:3)=='1.0') 0053 w=fliplr(w); 0054 end 0055 end 0056 depth=mexcdf('varget',ncid,'depth',0,-1); 0057 depth=depth(sta)*sigma; 0058 if(nargin>3), 0059 m=length(z); 0060 if(min(z)<min(depth)), disp('requested level below data!'),return,end 0061 if(max(z)>max(depth)), disp('requested level above data!'),return,end 0062 for k=1:m, 0063 lev2=max(find(depth>z(k))); 0064 lev1=lev2+1; 0065 frac=(z(k)-depth(lev1))/(depth(lev2)-depth(lev1)); 0066 wmod(:,k)=w(:,lev1)+frac*(w(:,lev2)-w(:,lev1)); 0067 end 0068 w=wmod; 0069 else 0070 z=depth; 0071 end 0072 % 0073 base_date=zeros(1,6); 0074 base_date(1:3)=mexcdf('attget',ncid,-1,'base_date'); 0075 jd0=julian(base_date); 0076 jd=jd0+t/(3600*24); 0077 mexcdf('close',ncid);