Home > atmlab > files > nc_read_varid.m

nc_read_varid

PURPOSE ^

NC_READ_VARID Reads a variable by varid from a netcdf id.

SYNOPSIS ^

function ret = nc_read_varid(ncid, varid)

DESCRIPTION ^

 NC_READ_VARID   Reads a variable by varid from a netcdf id.

    Function used by loadncfile and loadncvar to read the actual
    variable from the netcdf file. Only used internally by ncloadvar and
    ncloadfile.

 FORMAT   ret = nc_read_varid( ncid, varid )
        
 OUT   ret        Variable contents.
 IN    ncid       ID of NetCDF file.
 IN    varid      Variable ID.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

nc_read_varid.m

SOURCE CODE ^

0001 % NC_READ_VARID   Reads a variable by varid from a netcdf id.
0002 %
0003 %    Function used by loadncfile and loadncvar to read the actual
0004 %    variable from the netcdf file. Only used internally by ncloadvar and
0005 %    ncloadfile.
0006 %
0007 % FORMAT   ret = nc_read_varid( ncid, varid )
0008 %
0009 % OUT   ret        Variable contents.
0010 % IN    ncid       ID of NetCDF file.
0011 % IN    varid      Variable ID.
0012 
0013 % 2012-02-09   Created by Oliver Lemke.
0014 
0015 function ret = nc_read_varid(ncid, varid)
0016     [varname, xtype, dimids, natts] = netcdf.inqVar(ncid, varid);
0017     skipread = false;
0018     dims = [];
0019     for dimid = dimids
0020         [dimname, dimlength] = netcdf. inqDim(ncid, dimid);
0021         dims = [dims dimlength];
0022         if (~dimlength) skipread = true; end
0023     end
0024     if (skipread)
0025         ret = zeros(dims);
0026     else
0027         ret = netcdf.getVar (ncid, varid);
0028     end
0029 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005