Re: [netcdfgroup] offsets are ignored when creating compound types

  • Subject: Re: [netcdfgroup] offsets are ignored when creating compound types
  • From: Dennis Heimbigner <dennis.heimbigner@xxxxxxxxx>
  • Date: Wed, 18 Nov 2009 09:40:30 -0700
It is possible (with some caveats)
to figure out on the fly the offsets
used in C compound types. In fact, I do
exactly that in the netcdf ncgen utility.
You might look at this writeup.
http://www.unidata.ucar.edu/blogs/default/2009/03/30/1238442300000.html

=Dennis Heimbigner

Felipe Bertrand wrote:
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



------------------------------------------------------------------------

_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe, visit: http://www.unidata.ucar.edu/mailing_lists/



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