test all available file formats in tst_def_var_fill.c
int main(int argc, char** argv) {
char filename[256];
- int i, j, err, nerrs=0, ncid, varid[2], dimid[2], *buf;
+ 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]);
@@ -49,7 +51,20 @@ int main(int argc, char** argv) {
printf("%-66s ------ ", cmd_str); fflush(stdout);
free(cmd_str);
- /* create a new file for writing ----------------------------------------*/
+ buf = (int*) malloc(NY*NX * sizeof(int));
+
+ for (k=0; k<5; k++) {
+#ifndef USE_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 */
@@ -68,7 +83,6 @@ int main(int argc, char** argv) {
err = nc_enddef(ncid); CHECK_ERR
/* write a subarray to both variables */
- buf = (int*) malloc(NY*NX * sizeof(int));
for (i=0; i<NY*NX; i++) buf[i] = 5;
start[0] = 0;
start[1] = 2;
@@ -121,6 +135,7 @@ int main(int argc, char** argv) {
}
err = nc_close(ncid); CHECK_ERR
+ }
free(buf);
if (nerrs) printf("fail with %d mismatches\n",nerrs);
