Matlab creates netcdf file but can't open it later(ERROR: The NetCDF library encountered an error during execution of 'open' function - 'Unknown file format (NC_ENOTNC)'
24 views (last 30 days)
Show older comments
Hello, I've encountered a problem with NetCDF library, I would be very grateful for any tips how to solve it.
I'm trying to create a netcdffile and write variables in it. But for some reason after creating a file I can't reach it anyhow (nccreate, ncdisp are getting the same error):
ncid = netcdf.create('F:\GLORYS_day\ARC\GLORYS_surf.nc','NETCDF4');
nccreate('F:\GLORYS_day\ARC\GLORYS_surf.nc','Lat','Dimensions',{'Lat' 205});
Error using matlab.internal.imagesci.netcdflib
The NetCDF library encountered an error during execution of 'open' function - 'Unknown file format (NC_ENOTNC)'.
Error in netcdf.open (line 77)
[varargout{:}] = matlab.internal.imagesci.netcdflib('open', ...
Error in internal.matlab.imagesci.nc/openToAppend (line 1250)
this.ncRootid = netcdf.open(this.Filename,'WRITE');
Error in internal.matlab.imagesci.nc (line 126)
this.openToAppend();
Error in nccreate (line 159)
ncObj = internal.matlab.imagesci.nc(ncFile,'a', formatStr);
Error in export_to_netcdf (line 10)
nccreate('F:\GLORYS_day\ARC\GLORYS_surf.nc','Lat','Dimensions',{'Lat' 205});
5 Comments
Gustavo
on 15 Aug 2024
Same here on MacPro:
Error in grdread2 (line 61)
ncid = netcdf.open(file, 'NC_NOWRITE');
Gustavo
on 15 Aug 2024
And in:
yrange=netcdf.getVar(ncid,1)';
which seems to call: [varargout{:}] = matlab.internal.imagesci.netcdflib('open', ...
However, the line before is not a problem: xrange=netcdf.getVar(ncid,0)';
Answers (1)
Nalini Vishnoi
on 26 Aug 2024
I tried the following code in R2022a through R2024a:
>> ncid = netcdf.create('GLORYS_surf.nc','NETCDF4');
>> nccreate('GLORYS_surf.nc','Lat','Dimensions',{'Lat' 205});
and it errors out with the same error message as reported earlier:
Error using matlab.internal.imagesci.netcdflib
The NetCDF library encountered an error during execution of 'open' function - 'Unknown file format
(NC_ENOTNC)'.
The issue is the missing netcdf.close(ncid) after the first statement. Since the file was first created using the low-level NetCDF function netcdf.create, it should be closed before calling nccreate (high-level NetCDF function). The following code works fine:
>> ncid = netcdf.create('GLORYS_surf.nc','NETCDF4');
>> netcdf.close(ncid);
>> nccreate('GLORYS_surf.nc','Lat','Dimensions',{'Lat' 205});
Hope that helps!
0 Comments
See Also
Categories
Find more on NetCDF in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!