NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.
To learn about what's going on, see About the Archive Site.
On Mon, Jul 30, 2012 at 2:00 PM, <netcdfgroup-request@xxxxxxxxxxxxxxxx>wrote: > Hi, > > I need to represent a number of 'objects' detected in a NetCDF data set. > The objects basically comprise of N vectors of dimension D. > > 1 x1 y1 z1 > . > . > N xN yN zN > > The trouble is, that N varies from object to object. I was taking a look > at the C-API for variable length arrays, but couldn't really make heads nor > tails of it. Also, I have been using the C++ API heavily and it does not > seem to have any notion of variable length arrays. > > Any other (possibly backward compatible) way I can tackle this one? > > Kind Regards, > Ion > My company does a fair amount of this. We store polygons that can have anywhere from 3 to 20 or more sides. Knowing the old adage, "there's no such thing as a problem that can't be solved by adding a layer of indirection," our solution has been to store all of the vertex coordinates in a simple n_verts x 3 array. We then create two 1-D indexing arrays: the first (vertex_refs) gives the vertex indices of all of the polygons in succession. The second gives the index into the vertex_refs array to the first vertex of each polygon. So... dim n_polygons = ... dim nverts = ... dim nvertex_refs = ... dim ndims = 3 var vertex_coords(nverts,ndims) = vertex1(x,y,z), vertex2(x,y,z), ... var vertex_refs(nvertex_refs) = 0,1,2,3,2,3,4,34,37,52,91,0,10,11,... var start_vertex(n_polygons) = 0,4,7,14,... ...would be a file which starts with a quad (vertices 0,1,2,3), a triangle (vertices 2,3,4) and a heptagon (vertices 34,37,52,91,0,10,11). If quick indexing isn't an issue you could just use -1 in the vertex_refs array to demark polygons instead of the start_vertex array. The number of vertices/sides for each polygon is quickly extracted from start_vertex (w/ a guard on the last one). This works well for both classic and HDF5-format files, but might be painful if your objects aren't a simple type. Hope this helps. - Chuck
netcdfgroup
archives: