2019-07-18 08:23:43 +08:00
|
|
|
/*! \file
|
|
|
|
|
|
|
|
Copyright 2019
|
|
|
|
University Corporation for Atmospheric Research/Unidata.
|
|
|
|
|
2019-07-18 08:41:06 +08:00
|
|
|
Author: Even Rouault
|
|
|
|
|
2019-07-18 08:23:43 +08:00
|
|
|
See \ref copyright file for more info.
|
|
|
|
|
|
|
|
*/
|
|
|
|
#include <nc_tests.h>
|
|
|
|
#include "err_macros.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <netcdf.h>
|
|
|
|
|
2019-07-18 08:41:06 +08:00
|
|
|
#define FILENAME "tst_bug1442.nc"
|
2019-07-18 08:23:43 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
/* Test bugfix for https://github.com/Unidata/netcdf-c/pull/1442 */
|
|
|
|
/* that is using nc_get_vara_xxx() with a offset[] != 0 on a variable */
|
|
|
|
/* indexed by a unlimited dimension, and the size taken by that variable */
|
|
|
|
/* does not reach the actual size of that dimension */
|
|
|
|
int status;
|
|
|
|
int cdfid = -1;
|
|
|
|
int unlimited_dim;
|
|
|
|
int varid;
|
|
|
|
int other_var;
|
|
|
|
size_t start[1];
|
|
|
|
size_t count[1];
|
2019-07-18 09:05:20 +08:00
|
|
|
double five_zeros[5] = {0, 0, 0, 0, 0};
|
|
|
|
double one_two[2] = {1, 2};
|
|
|
|
double* four_double = (double*)calloc(4, sizeof(double));
|
2019-07-18 08:23:43 +08:00
|
|
|
|
|
|
|
status = nc_create(FILENAME, NC_NETCDF4, &cdfid);
|
|
|
|
if( status ) ERR;
|
|
|
|
|
|
|
|
status = nc_def_dim(cdfid, "unlimited_dim", NC_UNLIMITED, &unlimited_dim);
|
|
|
|
if( status ) ERR;
|
|
|
|
|
|
|
|
status = nc_def_var(cdfid, "my_var", NC_DOUBLE, 1, &unlimited_dim, &varid);
|
|
|
|
if( status ) ERR;
|
|
|
|
|
|
|
|
status = nc_def_var(cdfid, "other_var", NC_DOUBLE, 1, &unlimited_dim, &other_var);
|
|
|
|
if( status ) ERR;
|
|
|
|
|
|
|
|
status = nc_enddef(cdfid);
|
|
|
|
if( status ) ERR;
|
|
|
|
|
2019-07-18 09:05:20 +08:00
|
|
|
/* Write 5 elements to set the size of the unlimited dim to 5 */
|
2019-07-18 08:23:43 +08:00
|
|
|
start[0] = 0;
|
2019-07-18 09:05:20 +08:00
|
|
|
count[0] = 5;
|
|
|
|
status = nc_put_vara_double(cdfid, other_var, start, count, five_zeros);
|
2019-07-18 08:23:43 +08:00
|
|
|
if( status ) ERR;
|
|
|
|
|
2019-07-18 09:05:20 +08:00
|
|
|
/* Write 2 elements in my_var */
|
|
|
|
start[0] = 0;
|
2019-07-18 08:23:43 +08:00
|
|
|
count[0] = 2;
|
2019-07-18 09:05:20 +08:00
|
|
|
status = nc_put_vara_double(cdfid, varid, start, count, one_two);
|
|
|
|
if( status ) ERR;
|
|
|
|
|
|
|
|
/* Read 4 elements starting with index=1 */
|
|
|
|
start[0] = 1;
|
|
|
|
count[0] = 4;
|
|
|
|
status = nc_get_vara_double(cdfid, varid, start, count, four_double);
|
2019-07-18 08:23:43 +08:00
|
|
|
if( status ) ERR;
|
|
|
|
|
2019-07-18 09:05:20 +08:00
|
|
|
if( four_double[0] != 2 ) ERR;
|
|
|
|
if( four_double[1] != NC_FILL_DOUBLE ) ERR;
|
|
|
|
if( four_double[2] != NC_FILL_DOUBLE ) ERR;
|
|
|
|
if( four_double[3] != NC_FILL_DOUBLE ) ERR;
|
2019-07-18 08:23:43 +08:00
|
|
|
|
|
|
|
status = nc_close(cdfid);
|
|
|
|
if( status ) ERR;
|
|
|
|
|
2019-07-18 09:05:20 +08:00
|
|
|
free(four_double);
|
2019-07-18 08:23:43 +08:00
|
|
|
|
|
|
|
SUMMARIZE_ERR;
|
|
|
|
FINAL_RESULTS;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|