user34790
user34790

Reputation: 2036

Issues when reading a .nc file

I got this .nc file. However, when I read the file like this

ncid = netcdf.open(ncfile)

It gives me only a number. It was supposed to contain some data. I am not sure what's wrong with it.
Can anyone please provide some information?

Upvotes: 3

Views: 730

Answers (2)

internals-in
internals-in

Reputation: 5038

Note:

ncid = netcdf.open(ncfile) Where ncid is a netCDF file identifier returned by netcdf.create or netcdf.open.

Eg : In your Case

 ncid=netcdf.open(ncfile,'NC_NOWRITE'); 
 varidp=netcdf.inqVarID(ncid,'varname'); //returns varid

Eg : Official

This example opens the example netCDF file included with MATLAB®, example.nc, and uses several inquiry functions to get the ID of the first variable.

ncid = netcdf.open('example.nc','NC_NOWRITE');

% Get information about first variable in the file.
[varname, xtype, dimids, atts] = netcdf.inqVar(ncid,0);

% Get variable ID of the first variable, given its name
varid = netcdf.inqVarID(ncid,varname)

Ref:http://www.mathworks.in/help/matlab/ref/netcdf.inqvarid.html

Thanks

Upvotes: 1

am304
am304

Reputation: 13876

According to the documentation, netcdf.open only returns the NetCDF ID, not the data:

ncid = netcdf.open(source) opens source, which can be the name of a NetCDF file or the URL of an OPeNDAP NetCDF data source, for read-only access. Returns a NetCDF ID in ncid.

You probably want to use ncread.

Upvotes: 3

Related Questions