Re: [netcdfgroup] Problem using nc_put_vara_...() and nc_put_vars_...() functions.

Sergey Panov <sergey.panov@xxxxxxxxxxx> writes:

> Hello all,
>
> I suspect it is an "operator error", but I tried all possible
> interpretations of the API documentation and can not fill data block
> with either nc_put_vara_double() or  nc_put_vars_double().
> nc_put_var1_double() works as expected.
>
> A simple test program is attached ("#define WRITE_MODE ..." controls
> type of write).
>
> Here is a snapshot of non-working code:
>
> ...
> double ray_data[RANGE_BINS_COUNT] = {0.0};
> ...
>     for (sweep_idx = 0; sweep_idx < SWEEPS_COUNT; sweep_idx++ )
>         for(ray_idx = 0; ray_idx < RAYS_PER_SWEEP_COUNT; ray_idx++ ) {
>             size_t start[3] = {sweep_idx, ray_idx, 0};
>             size_t count[3] = {0, 0, RANGE_BINS_COUNT};
>
>             status = nc_put_vara_double(ncid, dbz_id, start, count, ray_data);
>             if (status != NC_NOERR)
>                 handle_error(status);
>         }
> ...
>
> nc_put_vara_double() call does not fail, but "dbz_id" data set remains
> uninitialized.  Everything works as expected when nc_put_var1_double()
> is used instead:
> ...
>     for (sweep_idx = 0; sweep_idx < SWEEPS_COUNT; sweep_idx++)
>         for (ray_idx = 0; ray_idx < RAYS_PER_SWEEP_COUNT; ray_idx++)
>           for (bin_idx = 0; bin_idx < RANGE_BINS_COUNT; bin_idx++) {
>               size_t index_3d[3] = {sweep_idx, ray_idx, bin_idx};
>               double val = 0.0;
>
>               status = nc_put_var1_double(ncid, dbz_id, index_3d, &val);
>               if (status != NC_NOERR)
>                 handle_error(status);
>           }
> ...
>

Your problem is that you are setting some of the count array to zero.

With the vara calls, multiply all the count elements together to get
the total number of values written. If one of the count elements is
zero, you are asking the library to write zero elements of data, and
it obliges by doing nothing and returning no error.

So probably you want to set count to:
             size_t count[3] = {1, 1, RANGE_BINS_COUNT};

Good luck!

Ed
-- 
Ed Hartnett  -- ed@xxxxxxxxxxxxxxxx


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