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.

Re: [netcdfgroup] How to represent this data in NetCDF

Jürgen,

Chuck Alexander and I provided Netcdf-3 compatible methods because you
asked for a "backward compatible" method in your original message.
However, it seems that you really want to use the variable length
array feature of Netcdf-4.  I think you are on the right track.

I do not have the experience with VLEN types to identify your error.
However, there is a simple working example program that writes a
Netcdf-4 file containing a VLEN type, i.e. a true variable length
array.  It is in the test suite in the Netcdf-4.2 source distribution,
probably in 4.2.1 as well.  The program is src/ncdump/tst_vlen_data.c.
 It may be helpful to compare this example with your program.

Since it is in the test suite, it uses some special include files.
The following compile command command gave me a working executable
with no problems and no source code tweaking:

  gcc tst_vlen_data.c -I$HOME/netcdf/4.2/core/src/include \
       -I$HOME/netcdf/4.2/core/src -lnetcdf

Replace $HOME/netcdf/4.2/core with the path to your own distribution
source, of course.  I would expect that Netcdf's configure script must
have been run at least once, to get valid include files.  HTH.

--Dave

On Tue, Jul 31, 2012 at 7:34 AM, Jürgen Lorenz Simon
<juergen_simon@xxxxxxx> wrote:
> Hi,
>
> I have revised the code a little and found the point of failure:
>
>    NcDim *dim = file->add_dim("dim", (int)
> featureSpace->coordinate_system->size() );
>            NcDim *N = file->add_dim( "N", clusters.size() );
>
>             int var_id, dim_id;
>             nc_inq_dimid( ncid, "dim", &dim_id );
>             int dims[1] = {dim_id};
>             nc_def_var( ncid, ss.str().c_str(), type_id, 1, dims, &var_id );
>
> ...
>
>             size_t start=0, len=clusters[ci].points.size();
>
>             status = nc_put_vara_double( nc_file_id, var_id, &start, &len,
> &data[0][0] );
>
>             check_nc_error( "nc_put_vara_double", status );
>
>
> nc_put_vara_double returns status code -57, which according to the man page
> translates to:
>
> NC_EEDGE The specified edge lengths added to the specified corner would have
> referenced data out of range for the rank of the specified variable. For
> example, an edge length that is larger than the corresponding dimension
> length minus the corner index will cause an error.
>
> I revised the code again, making the dimension variable N 'unlimited' and
> the variables X1 ... X_n depending on N and d:
>
>     NcDim *dim = file->add_dim("dim", (int)
> featureSpace->coordinate_system->size() );
>     NcDim *N = file->add_dim( "N", NC_UNLIMITED );
>
> ....
>
>             int var_id, dim_id, N_id;
>             status = nc_inq_dimid( nc_file_id, "dim", &dim_id );
>             check_nc_error( "nc_inq_dimid", status );
>             status = nc_inq_dimid( nc_file_id, "N", &N_id );
>             check_nc_error( "nc_inq_dimid", status );
>             int dims[2] = {N_id,dim_id};
>             status = nc_def_var( nc_file_id, ss.str().c_str(), type_id, 2,
> dims, &var_id );
>
> and now I get the following error:
>
> NC_EINVALCOORDS The specified corner indices were out of range for the rank
> of the specified variable. For example, a negative index, or an index that
> is larger than the corresponding dimension length will cause an error.
>
> Something I'm overlooking here! Anyone know what it is?
>
> Kind Regards,
> Jürgen
>
>



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