Home > omviz > mcvgt.m

mcvgt

PURPOSE ^

MCVGT Get a NetCDF hyperslab.

SYNOPSIS ^

function values = mcvgt(cdf, var, corner,count)

DESCRIPTION ^

 MCVGT Get a NetCDF hyperslab.
  MCVGT('CDF','VAR',[COORD],[COUNT]) returns the hyperslab 
   from NetCDF file 'CDF, variable 'VAR', starting at corner 
   [COORD] and containing [COUNT] elements along the edges.  
   The starting index of an array is 0 (C-Language convention).

 Example:
    value = mcvgt('foo.cdf', 'x', [0 0], [2 3])

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function values = mcvgt(cdf, var, corner,count)
0002 
0003 % MCVGT Get a NetCDF hyperslab.
0004 %  MCVGT('CDF','VAR',[COORD],[COUNT]) returns the hyperslab
0005 %   from NetCDF file 'CDF, variable 'VAR', starting at corner
0006 %   [COORD] and containing [COUNT] elements along the edges.
0007 %   The starting index of an array is 0 (C-Language convention).
0008 %
0009 % Example:
0010 %    value = mcvgt('foo.cdf', 'x', [0 0], [2 3])
0011 
0012 % Show usage if too few arguments.
0013 %
0014 if nargin~=2 & nargin~=4,
0015    help mcvgt;
0016    return;
0017 end
0018 %
0019 % Open netCDF file
0020 %
0021 [cdfid,rcode ]=mexcdf('open',cdf,'NOWRITE');
0022 if cdfid < 0
0023    disp(['Error in mexcdf: Can''t open ' cdf]);
0024    return
0025 end
0026 % Suppress warning messages from netCDF
0027 [rcode]=mexcdf('setopts',0);
0028 %
0029 % Get variable id
0030 %
0031 [varid]=mexcdf('varid',cdfid,var);
0032 if varid < 0
0033    disp(['Error in mexcdf: Can''t get variable ' var]);
0034    return
0035 end
0036 [var_name,var_type,nvdims,var_dim,natts]=mexcdf('varinq',cdfid,varid);
0037 %
0038 % Automagically get all the data if slab is not specified
0039 %
0040 if nargin==2,
0041   for n=1:nvdims,
0042     dimid=var_dim(n);
0043     [dim_name,dim_size,rcode]=mexcdf('diminq',cdfid,dimid);
0044     corner(n)=0;
0045     count(n)=dim_size;
0046   end
0047 end
0048 %
0049 % Get slab
0050 %
0051 [values,rcode] = mexcdf('varget',cdfid,varid,corner,count,1);
0052 values=values';  % want slowest varying dimension to be # of rows
0053 mexcdf('close',cdfid);

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