Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error code NC_ELATEFILL for NetCDF-4 file #384

Closed
wkliao opened this issue Mar 24, 2017 · 2 comments
Closed

error code NC_ELATEFILL for NetCDF-4 file #384

wkliao opened this issue Mar 24, 2017 · 2 comments

Comments

@wkliao
Copy link
Contributor

wkliao commented Mar 24, 2017

According to the NetCDF document for nc_put_att, the error code description for NC_ELATEFILL is:

NC_ELATEFILL Fill values must be written while the file is still in initial define mode.

Below is what I tried:

  1. define a variable
  2. call enddef
  3. call redef
  4. call put_att to write _FillValue
    NC_ELATEFILL is expected from step 4 because it is not in the initial define mode, but I got NC_NOERR.

This behavior also appear in nc_test4/tst_vars2.c, line 70 but is considered normal (mistakenly?)

Here is my short test program.

#include <stdio.h>
#include <netcdf.h>

#define ERR {if(err!=NC_NOERR)printf("Error at line %d: %s\n",__LINE__,nc_strerror(err));}
int
main(int argc, char **argv)
{
    int ncid, dimid, varid, cmode, err;
    int no_fill, fillv, buf[10];

    cmode = NC_NETCDF4 | NC_CLOBBER;
    err = nc_create("testfile.nc", cmode, &ncid); ERR
    err = nc_def_dim(ncid, "dim", 10, &dimid); ERR
    err = nc_def_var(ncid, "var", NC_INT, 1, &dimid, &varid); ERR
    err = nc_enddef(ncid); ERR

    err = nc_redef(ncid); ERR

    /* try put attribute _FillValue and expect NC_ELATEFILL */
    fillv = 9;
    err = nc_put_att_int(ncid, varid, _FillValue, NC_INT, 1, &fillv);
    if (err != NC_ELATEFILL)
        printf("line %d expecting NC_ELATEFILL but got %d\n",__LINE__,err);
    err = nc_close(ncid); ERR
    return 0;
}
@WardF
Copy link
Member

WardF commented Mar 27, 2017

@DennisHeimbigner I'll be grateful for any context you can provide here; the exhibited behavior is how I expect things to work, but the comments (as pointed out by @wkliao) are a bit contradictory.

If I'm reading this right, the issue is that the documentation for ELATEFILL specifies that attributes can only be set in the 'initial' define mode. However, the behavior exhibited in the tests shows that you can add a _FillValue attribute during redefinition. If you go through and look at the comment for ELATEFILL in netcdf.h, you see Attempt to define fill value when data already exists.. This alludes to a different issue than setting _FillValue only in the initial definition.

Assuming that the comment in netcdf.h is correct, you should be able to define a _FillValue attribute until such time as you have written data. This is in line with my understanding of things, and assuming it's correct I think the fix is a simple documentation clarification. If redef is a relatively new operation (it may or may not be, I have no idea and am not inclined to track it down; it's not super relevant anyways) then the term initial may have had a different inference before redef was implemented.

Any insight you can provide will be appreciated @DennisHeimbigner, thanks!

@wkliao
Copy link
Contributor Author

wkliao commented Mar 28, 2017

Just want to point out that in the nc_test program, a new variable is defined right after nc_create, and immediately followed by nc_enddef. During nc_enddef, the variable will be filled with the default fill value. So later on when calling put_attr to add _FillValue, the data of that variable does already exit and hence NC_ELATEFILL should be expected.

I believe the term "initial" is relative to variables, not files. For example, when a new variable is created in a redef mode, to that variable, the define mode is its initial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants