/* This is part of the netCDF package. * Copyright 2005 University Corporation for Atmospheric Research/Unidata * See COPYRIGHT file for conditions of use. * * Test per-variable fill mode for classic file formats. * * Author: Wei-keng Liao. */ #include #include #include #include #define CHECK_ERR { \ if (err != NC_NOERR) { \ nerrs++; \ printf("Error at line %d in %s: (%s)\n", \ __LINE__,__FILE__,nc_strerror(err)); \ } \ } #define EXP_ERR(exp) { \ if (err != exp) { \ nerrs++; \ printf("Error at line %d in %s: expecting %s but got %s\n", \ __LINE__,__FILE__,#exp, nc_strerror(err)); \ } \ } #define NY 8 #define NX 5 int main(int argc, char** argv) { char filename[256]; int i, j, k, err, nerrs=0, ncid, varid[2], dimid[2], *buf; size_t start[2], count[2]; int formats[5]={NC_FORMAT_CLASSIC, NC_FORMAT_64BIT_OFFSET, NC_FORMAT_CDF5, NC_FORMAT_NETCDF4, NC_FORMAT_NETCDF4_CLASSIC}; if (argc > 2) { printf("Usage: %s [filename]\n",argv[0]); return 1; } if (argc == 2) snprintf(filename, 256, "%s", argv[1]); else strcpy(filename, "tst_def_var_fill.nc"); char *cmd_str = (char*)malloc(strlen(argv[0]) + 256); sprintf(cmd_str, "*** TESTING C %s for def_var_fill ", argv[0]); printf("%-66s ------ ", cmd_str); fflush(stdout); free(cmd_str); buf = (int*) malloc(NY*NX * sizeof(int)); for (k=0; k<5; k++) { #ifndef ENABLE_CDF5 if (formats[k] == NC_FORMAT_CDF5) continue; #endif #ifndef USE_NETCDF4 if (formats[k] == NC_FORMAT_NETCDF4 || formats[k] == NC_FORMAT_NETCDF4_CLASSIC) continue; #endif nc_set_default_format(formats[k], NULL); /* create a new file for writing ------------------------------------*/ err = nc_create(filename, NC_CLOBBER, &ncid); CHECK_ERR /* define dimension */ err = nc_def_dim(ncid, "Y", NY, &dimid[0]); CHECK_ERR err = nc_def_dim(ncid, "X", NX, &dimid[1]); CHECK_ERR /* define variables */ err = nc_def_var(ncid, "var_nofill", NC_INT, 2, dimid, &varid[0]); CHECK_ERR err = nc_def_var(ncid, "var_fill", NC_INT, 2, dimid, &varid[1]); CHECK_ERR /* set fill mode for variables */ err = nc_def_var_fill(ncid, NC_GLOBAL, 0, NULL); EXP_ERR(NC_EGLOBAL) err = nc_def_var_fill(ncid, varid[0], 1, NULL); CHECK_ERR err = nc_def_var_fill(ncid, varid[1], 0, NULL); CHECK_ERR err = nc_enddef(ncid); CHECK_ERR /* write a subarray to both variables */ for (i=0; i 0); }