njtbx-icon
Netcdf-Java Toolbox
previous Function nj_tslice
Function nj_writeNcMLtoFile Next

 
 
Function nj_varget

PURPOSE ^

NJ_VARGET - Get variable data (gridded as well as non-gridded)

SYNOPSIS ^

function data=nj_varget(ncRef,var,start, count, stride)

DESCRIPTION ^

NJ_VARGET - get variable data from local NetCDF file, NetCDF URL or OpenDAP URL

 Usage:
   data=nj_varget(file,var,start,count,stride);
 where,
  ncRef - Reference to netcdf file. It can be either of two
           a. local file name or a URL  or
           b. An 'mDataset' matlab object, which is the reference to already
              open netcdf file.
              [ncRef=mDataset(uri)]
  var  =  variable to extract%           
  start = A 1-based array specifying the position in the file to begin reading or corner of a
          hyperslab e.g [1 2 1]. Specify 'inf' for last index.
          The values specified must not exceed the size of any
          dimension of the data set.
  count = A 1-based array specifying the length of each dimension to read. e.g [6 10 inf]. 
          Specify 'inf' to get all the values from start index.
  stride = A 1-based array specifying the interval between the
           values to read. e.g [1 2 2] or empty []
 returns,
   data - matlab array
 
 e.g,       
     Any of these URI types will work:
     Local NetCDF:  ncRef='bora_feb.nc';
     Remote NetCDF: urincRef='http://coast-enviro.er.usgs.gov/models/test/bora_feb.nc';
     OpenDAP:       ncRef='http://coast-enviro.er.usgs.gov/cgi-bin/nph-dods/models/test/bora_feb.nc';
     Local NcML:    ncRef='bora_feb.ncml';
     Remote NcML:   ncRef='http://coast-enviro.er.usgs.gov/models/test/bora_feb.ncml';

   Any of these syntaxes will return the surface temperature values
   from the first time step: Assuming Array shape is [8,20,60,160]         
           
     Using 'start' 'count' 'stride' arrays to specify indexing%
     t=nj_varget(ncRef,'temp',[1 1 1 1],[1 1 30 inf],[1 1 2 2]); % get surface temp from first time step 
          
     The following will return the entire longitude variable
     t=nj_varget(ncRef,'lon');  % get all the lon values

     NOTE: If using 'ncRef=mDataset(uri)' object as input to 'nj_varget' then 
           call ncRef.close() after all calls to nj_varget or any other function 
           to make sure netcdf dataset pointer is properly disposed.

CROSS-REFERENCE INFORMATION ^

This function makes following njTBX API calls:
  • mDataset mDataset class constructor - opens a netcdf file and creates a grid or netcdf mDataset object.
  • getVar mDataset/getVar - Retrieves a matlab variable object.
  • getData mGeoGridVar/getData - get the 3D volume data
  • getData mVar/getData - Read data from variable.

See demos using function nj_varget:


previous Function nj_tslice
Function nj_writeNcMLtoFile Next
© 2006-2009   Mississippi State University   • License Terms   • Credits