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

[netCDF #LRS-412716]: alignment problem with compound types



> 
> > Ed:  The fundamental problem I have is this.  For languages other than C
> > (such as python and fortran), structured arrays don't necessarily have
> > the same alignment as the default  for the C compiler.  In order the
> > write structured arrays from python using the netcdf C lib, I need to be
> > able to specify arbitrary offsets, and have the library actually use
> > those offsets when I write the data.  Reading is not a problem, since I
> > can intrepret the offsets that I read from the file to construct a
> > structured array to hold the data.  If you can tell me how to write
> > structured data with arbitrary offsets (usually packed) with netcdf,
> > I'll be happy.  If I can't do this, I'm afraid netcdf compound types
> > will be practically useless for languages other than C.
> 

Jeff, 

I have just generated a snapshot which does what you want: allows you to create 
a compound type with non-native offsets, and write oddly-packed structs of data 
into it.

Is this what we really want though?

Consider this: if you go back later and read this data into a packed struct 
(i.e. the same struct you used when writing it) it will not work! This will be 
confusing! It can only be read into the unpacked, native struct.

In fact, even the program that writes the data, if it closes and reopens the 
file, will not be able to append more data from a packed struct. Once the file 
is closed, the offsets you used go away. The packed struct cannot be read into, 
only written from, and only when the compound type has just been created, and 
the file not yet closed.

Is this really that helpful for you?

It seems like you face the same problem in almost all cases: you want a 
different in-memory type from the native type.

Seems like, to really fix this, you would need to be able to create an 
in-memory type for reading (perhaps by defining a type with a ncid of zero), 
and then specify that type as a read type for the variable.

Thanks,

Ed

Ticket Details
===================
Ticket ID: LRS-412716
Department: Support netCDF
Priority: Normal
Status: Open