Home > omviz > get_tsdata.m

get_tsdata

PURPOSE ^

FUNCTION: Get_TSData()

SYNOPSIS ^

function [x, time, loc, depth] = get_tsdata(cdf_file, varname, station)

DESCRIPTION ^

 FUNCTION: Get_TSData()
 
 USAGE:
     [var, time, loc, depth] = get_tsdata('cdf_file', 'varname', station) ;
     [var, time, loc]        = get_tsdata('cdf_file', 'varname', station) ;
     [var, time]             = get_tsdata('cdf_file', 'varname', station) ;
 or
     var = get_tsdata('cdf_file', 'varname', station) ;
 
 DESCRIPTION:
 Get_tsdata() is used to extract time-series variables from 'tsepic' files,
 and it not only returns the time-series data but also (optionally) returns
 the time, grid location, and depth values for the data. 
 
 There are 13 time-series variables stored in the 'tsepic' files.  No matter
 which variable names you use, get_tsdata() will return matrices of the
 appropriate dimension.  Some of these variables are just one-dimensional
 time-series.  They are:
 
     taux        Wind-stress along the x-axis...
     tauy        Wind-stress along the y-axis...
     elev        Sea surface elevation
     heat_flux        Heat flux
 
 Other variables are two-dimensional (depth & time).  These variables are:
 
     u            Current along the x-axis
     v            Current along the y-axis
     w            Current along the z-axis
     conc        Tracer concentration
     salt        Salinity
     kh        Vertical Diffusivity
     km        Vertical Viscosity
     am        Horizontal Viscosity
     temp        Temperature (degrees-Celsius)
 
 You can make a quick plot of salinity with the following set of commands
 
     [salt, t, loc, depth] = get_tsdata('tsepic.cdf', 'salt', 1) ;
     pcolor(t,depth,salt) 
     shading 'flat'
     colorbar 
 
 If you now want to make a plot of temperature (from the same file), it is
 not necessary to use all four output variables...
 
     temp = get_tsdata('tsepic.cdf', 'temp', 1);
     figure
     pcolor(t,depth,temp)
     shading 'flat'
     colorbar
 
 Author:  Randy Zagar  (zagar@chester.cms.udel.edu)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % FUNCTION: Get_TSData()
0002 %
0003 % USAGE:
0004 %     [var, time, loc, depth] = get_tsdata('cdf_file', 'varname', station) ;
0005 %     [var, time, loc]        = get_tsdata('cdf_file', 'varname', station) ;
0006 %     [var, time]             = get_tsdata('cdf_file', 'varname', station) ;
0007 % or
0008 %     var = get_tsdata('cdf_file', 'varname', station) ;
0009 %
0010 % DESCRIPTION:
0011 % Get_tsdata() is used to extract time-series variables from 'tsepic' files,
0012 % and it not only returns the time-series data but also (optionally) returns
0013 % the time, grid location, and depth values for the data.
0014 %
0015 % There are 13 time-series variables stored in the 'tsepic' files.  No matter
0016 % which variable names you use, get_tsdata() will return matrices of the
0017 % appropriate dimension.  Some of these variables are just one-dimensional
0018 % time-series.  They are:
0019 %
0020 %     taux        Wind-stress along the x-axis...
0021 %     tauy        Wind-stress along the y-axis...
0022 %     elev        Sea surface elevation
0023 %     heat_flux        Heat flux
0024 %
0025 % Other variables are two-dimensional (depth & time).  These variables are:
0026 %
0027 %     u            Current along the x-axis
0028 %     v            Current along the y-axis
0029 %     w            Current along the z-axis
0030 %     conc        Tracer concentration
0031 %     salt        Salinity
0032 %     kh        Vertical Diffusivity
0033 %     km        Vertical Viscosity
0034 %     am        Horizontal Viscosity
0035 %     temp        Temperature (degrees-Celsius)
0036 %
0037 % You can make a quick plot of salinity with the following set of commands
0038 %
0039 %     [salt, t, loc, depth] = get_tsdata('tsepic.cdf', 'salt', 1) ;
0040 %     pcolor(t,depth,salt)
0041 %     shading 'flat'
0042 %     colorbar
0043 %
0044 % If you now want to make a plot of temperature (from the same file), it is
0045 % not necessary to use all four output variables...
0046 %
0047 %     temp = get_tsdata('tsepic.cdf', 'temp', 1);
0048 %     figure
0049 %     pcolor(t,depth,temp)
0050 %     shading 'flat'
0051 %     colorbar
0052 %
0053 % Author:  Randy Zagar  (zagar@chester.cms.udel.edu)
0054 %
0055 
0056 
0057 function [x, time, loc, depth] = get_tsdata(cdf_file, varname, station)
0058 
0059 mexcdf('setopts', 0);
0060 
0061 if  isstr(cdf_file)
0062     mexcdf('setopts', 0) ;
0063     ncid = mexcdf('open', cdf_file) ;
0064 else
0065     ncid = cdf_file ;
0066 end
0067 
0068 [name, nstation] = mexcdf('diminq', ncid, 'stations');
0069 [name, nsigma]   = mexcdf('diminq', ncid, 'sigma');
0070 [name, nt]       = mexcdf('diminq', ncid, 'time');
0071 [name, ndim]     = mexcdf('diminq', ncid, 'dim');
0072 
0073 if  station > nstation
0074     errmsg = sprintf('    invalid station number (max==%d)\n', nstation);
0075     error( errmsg );
0076     return ;
0077 end
0078 
0079 if  isstr(varname)
0080     varid = mexcdf('varid', ncid, varname) ;
0081     if  varid == -1
0082     errmsg = sprintf('    invalid variable name \"%s\"\n', varname) ;
0083     error( errmsg );
0084     return ;
0085     end
0086 
0087 %   [name, type, ndims, dim, natts, status] = mexcdf('VARINQ',ncid,varid)
0088 
0089     if  nargout >= 2
0090     [time, status] = mexcdf('VARGET', ncid, mexcdf('varid',ncid,'time'),  ...
0091             [0], [nt], 1) ;
0092     end
0093 
0094     if  nargout >= 3
0095     [loc, status] = mexcdf('VARGET', ncid, mexcdf('varid',ncid,'loc'), ...
0096             [0,station-1], [2,1]) ;
0097     loc = loc';
0098     end
0099 
0100     if  nargout == 4
0101     [s, status] = mexcdf('VARGET', ncid, mexcdf('varid',ncid,'sigma'), ...
0102             [0], [nsigma]) ;
0103     [d, status] = mexcdf('VARGET', ncid, mexcdf('varid',ncid,'depth'), ...
0104             [station-1], [1]) ;
0105     depth = s * d ;
0106     end
0107         
0108     if strcmp(varname, 'taux')
0109     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,0], [nt,1,1,1]) ;
0110     if  nargout == 4
0111         depth = [] ;
0112     end
0113     if  nargout >= 3
0114         loc = [] ;
0115     end
0116     elseif strcmp(varname, 'tauy')
0117     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,0], [nt,1,1,1]) ;
0118     if  nargout == 4
0119         depth = [] ;
0120     end
0121     if  nargout >= 3
0122         loc = [] ;
0123     end
0124     elseif strcmp(varname, 'elev')
0125     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,station-1], [nt,1,1,1]) ;
0126     if  nargout == 4
0127         depth = 0 ;
0128     end
0129     elseif strcmp(varname, 'heat_flux')
0130     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,station-1], [nt,1,1,1], 1) ;
0131     if  nargout == 4
0132         depth = 0 ;
0133     end
0134     elseif strcmp(varname, 'u')
0135     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,station-1], [nt,nsigma,1,1], 1) ;
0136     elseif strcmp(varname, 'v')
0137     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,station-1], [nt,nsigma,1,1], 1) ;
0138     elseif strcmp(varname, 'w')
0139     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,station-1], [nt,nsigma,1,1], 1) ;
0140     elseif strcmp(varname, 'conc')
0141     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,station-1], [nt,nsigma,1,1], 1) ;
0142     elseif strcmp(varname, 'salt')
0143     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,station-1], [nt,nsigma,1,1], 1) ;
0144     elseif strcmp(varname, 'kh')
0145     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,station-1], [nt,nsigma,1,1], 1) ;
0146     elseif strcmp(varname, 'km')
0147     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,station-1], [nt,nsigma,1,1], 1) ;
0148     elseif strcmp(varname, 'am')
0149     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,station-1], [nt,nsigma,1,1], 1) ;
0150     elseif strcmp(varname, 'temp')
0151     [x, status] = mexcdf('VARGET', ncid, varid, [0,0,0,station-1], [nt,nsigma,1,1], 1) ;
0152     end
0153 
0154     depth = s * d ;
0155 end
0156 
0157 if  isstr(cdf_file)
0158     mexcdf('CLOSE', ncid);
0159 end

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