[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #QBI-894711]: Inability to write a variable to a NETCDF-4 file if its dimension has been defined as unlimited in a parent group



Hello Nalini,

What version of libnetcdf are you using?  Does Matlab use the C library, or the 
Java library?   Can you provide the CDL or binary netCDF file that works, and I 
will make the change from limited to unlimited and try to duplicate this issue 
in the C library.

-Ward

> Hello team,
> 
> I am a developer at MathWorks who works on netcdf functionality.
> We came across an error from the netcdf library while trying to write a 
> variable to a NETCDF-4 file when its dimension in a parent group has been 
> defined as 'NC_UNLIMITED'. Here is the reproduction code (in MATLAB):
> 
> % Create some example data
> data = 1:10;
> 
> % Choose a filename
> fileName='Test.nc';
> 
> % Create the file
> ncID = netcdf.create(fileName,'NETCDF4');
> 
> % Add unlimited dimension in the root group
> dimID = netcdf.defDim(ncID,'dim1',netcdf.getConstant('NC_UNLIMITED'));
> 
> % Create groups /group1/group2
> grID = netcdf.defGrp(ncID, 'group1');
> grID = netcdf.defGrp(grID, 'group2');
> 
> % Create a variable var1 in /group1/group2
> varID = netcdf.defVar(grID,'var1','double',dimID);
> 
> % Exit define mode
> netcdf.endDef(grID)
> 
> % Write data to /group1/group2/var1
> netcdf.putVar(grID,varID,0,10,data);
> 
> % Close the file
> netcdf.close(ncID)
> 
> The error encountered is:
> Error using netcdflib
> The NetCDF library encountered an error during execution of 'putVaraDouble' 
> function - 'Start+count exceeds dimension bound
> (NC_EEDGE)'.
> 
> Additional things we have noticed:
> 
> 
> 1.       If we change dim1 to a fixed value,
> 
> dimID = netcdf.defDim(ncID,'dim1',10); ie change NC_UNLIMITED to a fixed 
> dimension
> 
> the code will run fine.
> 
> 
> 
> 2.       Defining dim1 inside group1, mimics the above behavior:
> 
> 
> 
> Fails with dim1 set to NC_UNLIMITED:
> 
> grID = netcdf.defGrp(ncID, 'group1');
> 
> % Add unlimited dimension in group 1
> dimID = netcdf.defDim(grID,'dim1',netcdf.getConstant('NC_UNLIMITED'));
> 
> Works fine with dim1 set to a fixed dimension:
> 
> grID = netcdf.defGrp(ncID, 'group1');
> 
> % Add fixed dimension in group 1
> dimID = netcdf.defDim(grID,'dim1',10);
> 
> 
> 
> 3.       If we define dim1 (still with NC_UNLIMITED) inside group2, things 
> work fine.
> 
> grID = netcdf.defGrp(ncID, 'group1');
> 
> grID = netcdf.defGrp(grID, 'group2');
> 
> % Add unlimited dimension in group 2
> 
> dimID = netcdf.defDim(grID,'dim1',netcdf.getConstant('NC_UNLIMITED'));
> 
> 
> 
> 4.       The error we encountered above is the same in case the dimension of 
> the root group is less than the dimension of the variable:
> 
> dimID = netcdf.defDim(ncID,'dim1',8);
> ...
> netcdf.putVar(grID,varID,0,10,data);
> 
> We are trying to understand the following:
> 
> a.       Is this an expected behavior?
> 
> b.       The scenario in the first described case (defined dimension is much 
> greater than the data) is completely opposite to the scenario in case 4 
> (defined dimension is smaller than the data), yet we are getting the same 
> error message. Why?
> 
> c.       Even though the NetCDF documentation 
> (http://www.unidata.ucar.edu/software/netcdf/docs/netcdf_data_set_components.html)
>  does not mention any limitations that NC_UNLIMITED dimensions have to be 
> defined in the group itself, are there any limitations?
> 
> I look forward to your reply in order to understand this behavior.
> 
> Thanks,
> Nalini Vishnoi
> MathWorks Inc.
> 
> 


Ticket Details
===================
Ticket ID: QBI-894711
Department: Support netCDF
Priority: Normal
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.