[netcdfgroup] offsets are ignored when creating compound types

Hello,

I have found out that NetCDF-4 ignores the offsets that the users specifies
when creating compound types. Instead, I think it calculates the offsets
taking into account the architecture alignment rules.

So it is not possible for example to create a compound offset without
defining a "struct" in your C program. My problem is that I need to write a
program that is able to create arbitrary compound objects.

Another thing that is not possible is to create a compound type that is an
extract (a subset) of a larger struct. In the following simplified example,
I have a struct with 3 fields, but I want to write to disk only the 1st and
the 3rd fields:

////////////////////////////

struct mystruct {
    char field1;
    int field2;
    float field3;
};
struct mystruct myvar;
myvar.field1=123;
myvar.field3=45.67;

nc_def_compound(ncid, sizeof(struct mystruct), "MYSTRUCTEXTRACT", &typeid);
nc_insert_compound(ncid, typeid, "FIELD1", 0, NC_BYTE)==0);
nc_insert_compound(ncid, typeid, "FIELD3", NC_COMPOUND_OFFSET(struct
mystruct, field3), NC_FLOAT);

nc_def_var(ncid, "CVAR", typeid, 0, NULL, &varid);
nc_put_var(ncid, varid, &myvar);

////////////////////////////

The file that I create does not contain the right value for "FIELD3", and I
think the reason is that the library is ignoring the offset that I am
supplying.

Felipe
  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: