netcdf-c/nc_test4/tst_large.c

61 lines
1.9 KiB
C
Raw Normal View History

/* This is part of the netCDF package.
Copyright 2018 University Corporation for Atmospheric Research/Unidata
See COPYRIGHT file for conditions of use.
2010-06-03 21:24:43 +08:00
2017-11-10 20:01:32 +08:00
Test netcdf-4 large file fill values.
Ed Hartnett.
2010-06-03 21:24:43 +08:00
*/
#include <nc_tests.h>
2016-11-19 06:48:58 +08:00
#include "err_macros.h"
#include "netcdf.h"
2015-08-16 06:26:35 +08:00
#include "ncdispatch.h"
2010-06-03 21:24:43 +08:00
#define FILE_NAME "tst_large.nc"
2017-11-10 20:01:32 +08:00
#define NUMDIMS 2 /* rank of each variable in tests */
#define DIM1 2048
2017-11-10 20:01:32 +08:00
#define DIM2 2097153 /* DIM1*DIM2*sizeof(char) > 2**32 */
2010-06-03 21:24:43 +08:00
int
main(int argc, char **argv)
{
printf("\n*** Testing netcdf-4 large files.\n");
printf("**** testing simple fill value attribute creation...");
{
int ncid, varid, dimids[NUMDIMS];
size_t index[NUMDIMS] = {0, 0};
signed char vals[DIM2];
signed char char_val_in;
size_t start[NUMDIMS] = {0, 0}, count[NUMDIMS] = {1, DIM2};
int j;
/* Create phony data. */
2016-11-19 06:48:58 +08:00
for (j = 0; j < DIM2; j++)
2017-11-10 20:01:32 +08:00
vals[j] = 9 * (j + 11); /* note vals[j] is 99 when j==0 */
/* Create file with 2 dims and one var. */
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_set_fill(ncid, NC_NOFILL, NULL)) ERR;
if (nc_def_dim(ncid, "dim1", DIM1, &dimids[0])) ERR;
if (nc_def_dim(ncid, "dim2", DIM2, &dimids[1])) ERR;
if (nc_def_var(ncid, "var", NC_BYTE, NUMDIMS, dimids, &varid)) ERR;
if (nc_enddef(ncid)) ERR;
/* Write one slice, then close. */
if (nc_put_vara_schar(ncid, varid, start, count, vals)) ERR;
if (nc_close(ncid)) ERR;
/* Reopen and read a value. */
2017-11-10 20:01:32 +08:00
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_inq_varid(ncid, "var", &varid)) ERR;
if (nc_get_var1_schar(ncid, varid, index, &char_val_in)) ERR;
if (char_val_in != 99) /* see above, the value written when start[0]==0, j==0 */
ERR;
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
FINAL_RESULTS;
2010-06-03 21:24:43 +08:00
}