int main(int argc, char **argv) { int i; char testfile[NC_MAX_NAME + 1]; sprintf(testfile, "%s/%s", TEMP_LARGE, FILE_NAME); printf("\n*** Testing fix for 3.6.2 large file bug in %s.\n", testfile); /* Go thru formats and run all tests for each of two (for netCDF-3 * only builds), or 4 (for netCDF-4 builds) different formats. */ for (i = NC_FORMAT_CLASSIC; i <= NUM_FORMATS; i++) { nc_set_default_format(i, NULL); printf("*** testing format %d with a variable with 2**32 values...", i); test_big_var(testfile); (void) remove(testfile); SUMMARIZE_ERR; printf("*** testing format %d with a byte variable with > 2**32 values...", i); test_large_byte_var(testfile); (void) remove(testfile); SUMMARIZE_ERR; printf("*** testing format %d with a short variable with > 2**32 values...", i); test_large_short_var(testfile); (void) remove(testfile); SUMMARIZE_ERR; } /* Test CDF5 */ { i = NC_64BIT_DATA; nc_set_default_format(i, NULL); printf("*** testing format %d with a variable with 2**32 values...", i); test_big_var(testfile); (void) remove(testfile); SUMMARIZE_ERR; printf("*** testing format %d with a byte variable with > 2**32 values...", i); test_large_byte_var(testfile); (void) remove(testfile); SUMMARIZE_ERR; printf("*** testing format %d with a short variable with > 2**32 values...", i); test_large_short_var(testfile); (void) remove(testfile); SUMMARIZE_ERR; } FINAL_RESULTS; }
int main() { int ncid, temp_varid, dimids[NUMDIMS]; float temp[LAT_LEN][LON_LEN], *fp; char classic_file[] = "classic.nc", offset64_file[] = "offset.nc"; char *file = classic_file; int i, res; /* Create a bunch of phoney data so we have something to write in the example file. */ for (fp=(float *)temp, i=0; i<LAT_LEN*LON_LEN; i++) *fp++ = 10. + i/10.; /* Now create the file in both formats with the same code. */ for (i=0; i<2; i++) { if (i==1) /* 64-bit offset format file */ { file = offset64_file; if ((res = nc_set_default_format(NC_FORMAT_64BIT, NULL))) BAIL(res); } /* Create the netCDF file. */ if ((res = nc_create(file, NC_CLOBBER, &ncid))) BAIL(res); /* Define dimensions. */ if ((res = nc_def_dim(ncid, "latitude", LAT_LEN, dimids))) BAIL(res); if ((res = nc_def_dim(ncid, "longitude", LON_LEN, &dimids[1]))) BAIL(res); /* Define the variable. */ if ((res = nc_def_var(ncid, "sfc_temp", NC_FLOAT, NUMDIMS, dimids, &temp_varid))) BAIL(res); /* We're finished defining metadata. */ if ((res = nc_enddef(ncid))) BAIL(res); if ((res = nc_put_var_float(ncid, temp_varid, (float *)temp))) BAIL(res); /* We're done! */ if ((res = nc_close(ncid))) BAIL(res); } return 0; }
int main(int argc, char **argv) { int i; /* Set defaults */ persist = 0; usenetcdf4 = 0; mmap = 0; diskless = 0; file = 0; diskmode = 0; for(i=1;i<argc;i++) { if(strcmp(argv[i],"diskless")==0) diskless=1; else if(strcmp(argv[i],"mmap")==0) mmap=1; else if(strcmp(argv[i],"file")==0) file=1; else if(strcmp(argv[i],"persist")==0) persist=1; /* ignore anything not recognized */ } if(diskless && mmap) { fprintf(stderr,"NC_DISKLESS and NC_MMAP are mutually exclusive\n"); exit(1); } if(!diskless && !mmap && !file) { fprintf(stderr,"file or diskless or mmap must be specified\n"); exit(1); } if(diskless) diskmode |= NC_DISKLESS; if(mmap) diskmode |= NC_MMAP; if(persist) diskmode |= NC_PERSIST; printf("\n*** Testing create/modify file=%s mode=%s\n", NCFILENAME, diskless?"diskless":"mmap"); /* case NC_FORMAT_CLASSIC: only test this format */ nc_set_default_format(NC_FORMAT_CLASSIC, NULL); printf("*** testing diskless file with two growing record " "variables, with attributes added..."); test_two_growing_with_att(NCFILENAME); SUMMARIZE_ERR; FINAL_RESULTS; }
int main(int argc, char **argv) { int i; char testfile[NC_MAX_NAME + 1]; printf("\n*** Testing multidimensional variable with more than 2**32 values\n"); sprintf(testfile, "%s/%s", TEMP_LARGE, FILE_NAME); for (i = NC_FORMAT_CLASSIC; i <= NUM_FORMATS; i++) { printf("*** testing format %d file with short variable with > 2**32 values...", i); nc_set_default_format(i, NULL); if (test_big_var(testfile)) ERR_RET; (void) remove(testfile); SUMMARIZE_ERR; } FINAL_RESULTS; }
int main(int argc, char **argv) { int i; char testfile[NC_MAX_NAME + 1]; printf("\n*** Testing files with one very big variable.\n"); sprintf(testfile, "%s/%s", TEMP_LARGE, FILE_NAME); for (i = NC_FORMAT_CLASSIC; i <= NUM_FORMATS; i++) { printf("*** testing format %d file with byte variable with > 2**32 values...", i); nc_set_default_format(i, NULL); test_big_var(testfile); (void) remove(testfile); SUMMARIZE_ERR; } FINAL_RESULTS; }
int main(int argc, char **argv) { int i; /* Set defaults */ persist = 0; usenetcdf4 = 0; mmap = 0; diskless = 0; diskmode = 0; for(i=1;i<argc;i++) { if(strcmp(argv[i],"diskless")==0) diskless=1; else if(strcmp(argv[i],"mmap")==0) mmap=1; /* ignore anything not recognized */ } if(diskless) diskmode |= NC_DISKLESS; if(diskless && mmap) diskmode |= NC_MMAP; printf("\n*** Testing diskless file: create/modify %s", diskless?"in-memory":"in-file"); if(diskless && mmap) printf("+mmap"); printf(" %s\n",NCFILENAME); /* case NC_FORMAT_CLASSIC: only test this format */ nc_set_default_format(NC_FORMAT_CLASSIC, NULL); printf("*** testing diskless file with two growing record " "variables, with attributes added..."); test_two_growing_with_att(NCFILENAME); SUMMARIZE_ERR; FINAL_RESULTS; }
int main(int argc, char **argv) { int i; char testfile[NC_MAX_NAME + 1]; printf("\n*** Testing coordinate systems.\n"); /*nc_set_log_level(3);*/ /* Go thru formats and run all tests for each of two (for netCDF-3 * only builds), or 3 (for netCDF-4 builds) different formats. */ for (i = NUM_FORMATS; i >= 1; i--) { switch (i) { case NC_FORMAT_CLASSIC: nc_set_default_format(NC_FORMAT_CLASSIC, NULL); fprintf(stderr, "\nSwitching to netCDF classic format.\n"); strcpy(testfile, "tst_coords_classic.nc"); break; case NC_FORMAT_64BIT: nc_set_default_format(NC_FORMAT_64BIT, NULL); fprintf(stderr, "\nSwitching to 64-bit offset format.\n"); strcpy(testfile, "tst_coords_64bit.nc"); break; #ifdef USE_NETCDF4 case NC_FORMAT_NETCDF4_CLASSIC: nc_set_default_format(NC_FORMAT_NETCDF4_CLASSIC, NULL); strcpy(testfile, "tst_coords_netcdf4_classic.nc"); fprintf(stderr, "\nSwitching to netCDF-4 format (with NC_CLASSIC_MODEL).\n"); break; case NC_FORMAT_NETCDF4: /* actually it's _CLASSIC. */ nc_set_default_format(NC_FORMAT_NETCDF4, NULL); strcpy(testfile, "tst_coords_netcdf4.nc"); fprintf(stderr, "\nSwitching to netCDF-4 format.\n"); break; #endif default: fprintf(stderr, "Unexpected format!\n"); return 2; } printf("*** creating coordinate axis..."); test_axis(testfile); SUMMARIZE_ERR; printf("*** creating coordinate system..."); test_system(testfile); SUMMARIZE_ERR; printf("*** assigning a coordinate system..."); test_system_assign(testfile); SUMMARIZE_ERR; printf("*** creating coordinate transform..."); test_transform(testfile); SUMMARIZE_ERR; printf("*** assigning a coordinate transform..."); test_transform_assign(testfile); SUMMARIZE_ERR; } FINAL_RESULTS; }
int main(int argc, char **argv) { printf("\n*** Testing UTF-8 names.\n"); printf("*** creating UTF-8 names in classic model netcdf files..."); { int ncid, varid, dimids[NDIMS]; int f; for (f = NC_FORMAT_CLASSIC; f < NC_FORMAT_NETCDF4_CLASSIC; f++) { if (nc_set_default_format(f, NULL)) ERR; if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR; /* Define various netcdf objects with a Unicode UTF-8 encoded name * that must be normalized. Where possible, also use the utf8 * string as the value. The name will be normalized, but not the * value. */ if (nc_def_dim(ncid, name_utf8, NX, &dimids[0])) ERR; if (nc_def_var(ncid, name_utf8, NC_CHAR, NDIMS, dimids, &varid)) ERR; if (nc_put_att_text(ncid, varid, name_utf8, sizeof(name_utf8), name_utf8)) ERR; if (nc_enddef(ncid)) ERR; /* Write var data. */ if (nc_put_var_text(ncid, varid, name_utf8)) ERR; /* Check the file. */ check_classic_file(ncid); if (nc_close(ncid)) ERR; /* Reopen the file and check again. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; check_classic_file(ncid); if (nc_close(ncid)) ERR; } /* next format */ } SUMMARIZE_ERR; #define DIM1_NAME "d1" #define VAR1_NAME "v1" #define ATT1_NAME "a1" printf("*** renaming to UTF-8 names in classic model netcdf files..."); { int ncid, varid, dimids[NDIMS]; int f; for (f = NC_FORMAT_CLASSIC; f < NC_FORMAT_NETCDF4_CLASSIC; f++) { if (nc_set_default_format(f, NULL)) ERR; if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR; /* Create objects. */ if (nc_def_dim(ncid, DIM1_NAME, NX, &dimids[0])) ERR; if (nc_rename_dim(ncid, 0, name_utf8)) ERR; if (nc_def_var(ncid, name_utf8, NC_CHAR, NDIMS, dimids, &varid)) ERR; if (nc_put_att_text(ncid, varid, ATT1_NAME, sizeof(name_utf8), name_utf8)) ERR; if (nc_rename_att(ncid, 0, ATT1_NAME, name_utf8)) ERR; if (nc_enddef(ncid)) ERR; /* Write var data. */ if (nc_put_var_text(ncid, varid, name_utf8)) ERR; /* Check the file. */ check_classic_file(ncid); if (nc_close(ncid)) ERR; /* Reopen the file and check again. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; check_classic_file(ncid); if (nc_close(ncid)) ERR; } /* next format */ } SUMMARIZE_ERR; printf("*** creating UTF-8 names in netcdf-4 file..."); { int ncid, varid, grpid, comp_typeid, enum_typeid, grpid2, grpid3; int dimids[NDIMS]; char my_int = ENUM_VALUE; if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; /* Define various netcdf objects with a Unicode UTF-8 encoded name * that must be normalized. Where possible, also use the utf8 * string as the value. The name will be normalized, but not the * value. */ if (nc_def_grp(ncid, name_utf8, &grpid)) ERR; if (nc_def_dim(grpid, name_utf8, NX, &dimids[0])) ERR; if (nc_def_var(grpid, name_utf8, NC_CHAR, NDIMS, dimids, &varid)) ERR; if (nc_put_att_text(grpid, varid, name_utf8, sizeof(name_utf8), name_utf8)) ERR; if (nc_def_grp(grpid, "tmp", &grpid2)) ERR; if (nc_def_enum(grpid2, NC_BYTE, name_utf8, &enum_typeid)) ERR; if (nc_insert_enum(grpid2, enum_typeid, name_utf8, &my_int)) ERR; if (nc_def_grp(grpid2, "tmp", &grpid3)) ERR; if (nc_def_compound(grpid3, sizeof(struct comp), name_utf8, &comp_typeid)) ERR; if (nc_insert_compound(grpid3, comp_typeid, name_utf8, offsetof(struct comp, i), NC_INT)) ERR; /* Write var data. */ if (nc_put_var_text(grpid, varid, name_utf8)) ERR; /* Check the file. */ check_nc4_file(ncid); if (nc_close(ncid)) ERR; /* Reopen the file and check again. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; check_nc4_file(ncid); if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** ensuring UTF-8 normaization is applied in rename..."); { int ncid, varid; char name_in[NC_MAX_NAME + 1]; if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; if (nc_def_var(ncid, BORING_NAME, NC_CHAR, 0, NULL, &varid)) ERR; if (nc_rename_var(ncid, varid, name_utf8)) ERR; if (nc_inq_varname(ncid, 0, name_in)) ERR; if (!strcmp(name_in, norm_utf8)) ERR; if (nc_close(ncid)) ERR; /* Reopen the file and check again. */ if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; if (nc_inq_varname(ncid, 0, name_in)) ERR; if (!strcmp(name_in, norm_utf8)) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; FINAL_RESULTS; }
int main(int argc, char **argv) { int i; char testfile[NC_MAX_NAME + 1]; printf("\n*** Testing small files.\n"); /*nc_set_log_level(3);*/ /* Go thru formats and run all tests for each of two (for netCDF-3 * only builds), or 4 (for netCDF-4 builds) different formats. */ for (i = NUM_FORMATS; i >= 1; i--) { switch (i) { case NC_FORMAT_CLASSIC: nc_set_default_format(NC_FORMAT_CLASSIC, NULL); printf("Switching to netCDF classic format.\n"); strcpy(testfile, "tst_small_classic.nc"); break; case NC_FORMAT_64BIT: nc_set_default_format(NC_FORMAT_64BIT, NULL); printf("Switching to 64-bit offset format.\n"); strcpy(testfile, "tst_small_64bit.nc"); break; #ifdef USE_NETCDF4 case NC_FORMAT_NETCDF4_CLASSIC: nc_set_default_format(NC_FORMAT_NETCDF4_CLASSIC, NULL); strcpy(testfile, "tst_small_netcdf4_classic.nc"); printf("Switching to netCDF-4 format (with NC_CLASSIC_MODEL).\n"); break; case NC_FORMAT_NETCDF4: /* actually it's _CLASSIC. */ nc_set_default_format(NC_FORMAT_NETCDF4, NULL); strcpy(testfile, "tst_small_netcdf4.nc"); printf("Switching to netCDF-4 format.\n"); break; #endif default: printf("Unexpected format!\n"); return 2; } printf("*** testing simple small file with a global attribute..."); test_small_atts(testfile); SUMMARIZE_ERR; printf("*** testing simple small file with fixed dimensions..."); test_small_fixed(testfile); SUMMARIZE_ERR; printf("*** testing simple small file with an unlimited dimension..."); test_small_unlim(testfile); SUMMARIZE_ERR; printf("*** testing small file with one variable..."); test_small_one(testfile); SUMMARIZE_ERR; printf("*** testing small file with one variable and one att..."); test_one_with_att(testfile); SUMMARIZE_ERR; printf("*** testing small file with one record variable, which grows..."); test_one_growing(testfile); SUMMARIZE_ERR; printf("*** testing small file with one growing record " "variable, with attributes added..."); test_one_growing_with_att(testfile); SUMMARIZE_ERR; printf("*** testing small file with two growing record " "variables, with attributes added..."); test_two_growing_with_att(testfile); SUMMARIZE_ERR; } FINAL_RESULTS; }
int main(int argc, char **argv) { char *valid[] = { /* pressure in 23 languages */ "\xd8\xa7\xd9\x84\xd8\xb6\xd8\xba\xd8\xb7", "\xd0\xbd\xd0\xb0\xd0\xbb\xd1\x8f\xd0\xb3\xd0\xb0\xd0\xbd\xd0\xb5", "\xe5\x8e\x8b\xe5\x8a\x9b", "\xe5\xa3\x93\xe5\x8a\x9b", "pritisak", "tlaku", "pres", "druk", "pressure", "paine", "pression", "Druck", "\xcf\x80\xce\xaf\xce\xb5\xcf\x83\xce\xb7", "\xe0\xa4\xa6\xe0\xa4\xac\xe0\xa4\xbe\xe0\xa4\xb5", "pressione", "\xe5\x9c\xa7\xe5\x8a\x9b", "\xec\x95\x95\xeb\xa0\xa5", "press", "ci\xc5\x9bnienie", "Press\xc3\xa3o", "presiune", "\xd0\xb4\xd0\xb0\xd0\xb2\xd0\xbb\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5", "presi\xc3\xb3n", /* special characters in names, numeric characters at the start of names */ "has blank", "has:colon", "a", "A", "0leading_numeric_char", "1", "0x123" }; char *notvalid[] = { "-leading_special_char", "trailing_space ", "trailing_tab\t", "trailing_newline\n", "has_control_char_\a_in_name", "has ascii_del_\x7f_in name", /* Invalid UTF-8 of various sorts, thanks to Markus Kuhn */ "\xA0\xB0\xC0\xD0", "xyz\x80", /* unexpected continuation bytes */ "\x80xyz", "xyz\xBF", "\xBFxyz", "\xC0xyz", /* lonely start characters */ "x\xC0yz", "xy\xC0z", "xyz\xC0", "\xDFxyz", "x\xDFyz", "xy\xDFz", "xyz\xDF", "\xE0xyz", "x\xE0yz", "xy\xE0z", "xyz\xE0", "\xE0\xBFxy", "x\xE0\xBFy", "xy\xE0\xBF", "\xEFxyz", "x\xEFyz", "xy\xEFz", "xyz\xEF", "\xEF\x80xy", "x\xEF\x80y", "xy\xEF\x80", "\xF0xyz", "x\xF0yz", "xy\xF0z", "xyz\xF0", "\xF7xyz", "x\xF7yz", "xy\xF7z", "xyz\xF7", "\xF8xyz", "x\xF8yz", "xy\xF8z", "xyz\xF8", "\xFBxyz", "x\xFByz", "xy\xFBz", "xyz\xFB", "\xFCxyz", "x\xFCyz", "xy\xFCz", "xyz\xFC", "\xFDxyz", "x\xFDyz", "xy\xFDz", "xyz\xFD", "\xC0\xC0xy", /* last continuation byte missing */ "x\xC0\xC0y", "xy\xC0\xC0", "\xDF\xDFxy", "x\xDF\xDFy", "xy\xDF\xDF", "\xE0\x80xy", "x\xE0\x80y", "xy\xE0\x80", "\xEF\x80xy", "x\xEF\x80y", "xy\xEF\x80", "\xF0\x80\x80x", "x\xF0\x80\x80", "\xF7\x80\x80x", "x\xF7\x80\x80", "\xF8\x80\x80\x80x", "x\xF8\x80\x80\x80", "\xFB\x80\x80\x80x", "x\xFB\x80\x80\x80", "\xFC\x80\x80\x80\x80x", "x\xFC\x80\x80\x80\x80", "\xFD\x80\x80\x80\x80x", "x\xFD\x80\x80\x80\x80", "\xFExyz", /* impossible bytes */ "x\xFEyz", "xy\xFEz", "xyz\xFE", "\xFFxyz", "x\xFFyz", "xy\xFFz", "xyz\xFF", "\xC0\xAFxy", /* overlong sequences */ "x\xC0\xAFy", "xy\xC0\xAF", "\xE0\x80\xAFx", "x\xE0\x80\xAF", "\xF0\x80\x80\xAFx", "x\xF0\x80\x80\xAF", "\xF8\x80\x80\x80\xAFx", "x\xF8\x80\x80\x80\xAF", "\xFC\x80\x80\x80\x80\xAFx", "x\xFC\x80\x80\x80\x80\xAF", "\xC1\xBFxy", "x\xC1\xBFy", "xy\xC1\xBF", "\xE0\x9F\xBFx", "x\xE0\x9F\xBF", "\xF0\x8F\xBF\xBFx", "x\xF0\x8F\xBF\xBF", "\xF8\x87\xBF\xBF\xBFx", "x\xF8\x87\xBF\xBF\xBF", "\xFC\x83\xBF\xBF\xBF\xBFx", "x\xFC\x83\xBF\xBF\xBF\xBF", "x\xC0\x80", /* overlong NULs */ "x\xE0\x80\x80", "x\xF0\x80\x80\x80", "x\xF8\x80\x80\x80\x80", "x\xFC\x80\x80\x80\x80\x80", /* single UTF-16 surrogates */ "x\xED\xA0\x80", "x\xED\xAD\xBF", "x\xED\xAE\x80", "x\xED\xAF\xBF", "x\xED\xB0\x80", "x\xED\xBE\x80", "x\xED\xBF\xBF", "x\xED\xA0\x80\xED\xB0\x80", /* paired UTF-16 surrogates */ "x\xED\xA0\x80\xED\xBF\xBF", "x\xED\xAD\xBF\xED\xB0\x80", "x\xED\xAD\xBF\xED\xBF\xBF", "x\xED\xAE\x80\xED\xB0\x80", "x\xED\xAE\x80\xED\xBF\xBF", "x\xED\xAF\xBF\xED\xB0\x80", "x\xED\xAF\xBF\xED\xBF\xBF", "x\xEF\xBF\xBE", /* other illegal code positions */ "x\xEF\xBF\xBF" }; int i, j; #define NUM_BAD (sizeof notvalid / sizeof notvalid[0]) #define NUM_GOOD (sizeof valid / sizeof valid[0]) int ncid, dimid, varid, res; double attvals[] = {-2.0}; double attvals_in[1]; #define NATTVALS (sizeof attvals / sizeof attvals[0]) char *attstring = "text"; #define MAX_ATTSTRING_LEN 100 char attstr_in[MAX_ATTSTRING_LEN]; int dimids[NUM_GOOD]; int varids[NUM_GOOD]; #if 0 int attnums[NUM_GOOD]; #endif char *testfile = FILE_NAME; int formats[] = { NC_FORMAT_CLASSIC , NC_FORMAT_64BIT #ifdef USE_NETCDF4 , NC_FORMAT_NETCDF4 , NC_FORMAT_NETCDF4_CLASSIC #endif /* USE_NETCDF4 */ }; int num_formats = (sizeof formats) / (sizeof formats[0]); char *format_names[] = { "classic", "64-bit offset", "netCDF-4/HDF5", "netCDF-4 classic model" }; printf("\n*** testing names with file %s...\n", testfile); for (j = 0; j < num_formats; j++) { printf("*** switching to netCDF %s format...", format_names[j]); nc_set_default_format(formats[j], NULL); if((res = nc_create(testfile, NC_CLOBBER, &ncid))) ERR; /* Define dimensions, variables, and attributes with various * acceptable names */ for (i = 0; i < NUM_GOOD; i++) { if ((res = nc_def_dim(ncid, valid[i], DIMLEN, &dimid))) ERR; dimids[i] = dimid; /* Define variable with same name */ if ((res = nc_def_var(ncid, valid[i], NC_FLOAT, NDIMS, &dimids[i], &varid))) ERR; varids[i] = varid; /* Define variable and global attributes with same name and value */ if ((res = nc_put_att_text(ncid, varid, valid[i], strlen(valid[i]), valid[i]))) ERR; if ((res = nc_put_att_double(ncid, NC_GLOBAL, valid[i], NC_DOUBLE, NATTVALS, attvals))) ERR; #if 0 attnums[i] = i; #endif } /* Try defining dimensions, variables, and attributes with various * bad names and make sure these are rejected */ for (i = 0; i < NUM_BAD; i++) { if ((res = nc_def_dim(ncid, notvalid[i], DIMLEN, &dimid)) != NC_EBADNAME) ERR; if ((res = nc_def_var(ncid, notvalid[i], NC_FLOAT, NDIMS, dimids, &varid)) != NC_EBADNAME) ERR; if ((res = nc_put_att_text(ncid, varid, notvalid[i], strlen(attstring), attstring)) != NC_EBADNAME) ERR; if ((res = nc_put_att_double(ncid, NC_GLOBAL, notvalid[i], NC_DOUBLE, NATTVALS, attvals)) != NC_EBADNAME) ERR; } if ((res = nc_enddef(ncid))) ERR; if ((res = nc_close(ncid))) ERR; /* Check it out, make sure all objects with good names were defined OK */ if ((res = nc_open(testfile, NC_NOWRITE, &ncid))) ERR; for (i = 0; i < NUM_GOOD; i++) { size_t attlen; if ((res = nc_inq_dimid(ncid, valid[i], &dimid)) || dimid != dimids[i]) ERR; if ((res = nc_inq_varid(ncid, valid[i], &varid)) || varid != varids[i]) ERR; res = nc_inq_attlen(ncid, varid, valid[i], &attlen); if ((res = nc_get_att_text(ncid, varid, valid[i], attstr_in))) ERR; attstr_in[attlen] = '\0'; if (strcmp(valid[i], attstr_in) != 0) ERR; if ((res = nc_get_att_double(ncid, NC_GLOBAL, valid[i], attvals_in)) || attvals[0] != attvals_in[0]) ERR; } if ((res = nc_close(ncid))) ERR; /* (void) remove(testfile); */ SUMMARIZE_ERR; } FINAL_RESULTS; return 0; }
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<NY*NX; i++) buf[i] = 5; start[0] = 0; start[1] = 2; count[0] = NY; count[1] = 2; err = nc_put_vara_int(ncid, varid[0], start, count, buf); CHECK_ERR err = nc_put_vara_int(ncid, varid[1], start, count, buf); CHECK_ERR err = nc_close(ncid); CHECK_ERR /* Now, reopen the file and read variables back */ err = nc_open(filename, NC_WRITE, &ncid); CHECK_ERR /* get variable IDs */ err = nc_inq_varid(ncid, "var_nofill", &varid[0]); CHECK_ERR err = nc_inq_varid(ncid, "var_fill", &varid[1]); CHECK_ERR /* read variable "var_nofill" and check contents */ for (i=0; i<NY*NX; i++) buf[i] = -1; err = nc_get_var_int(ncid, varid[0], buf); CHECK_ERR for (i=0; i<NY; i++) { for (j=0; j<NX; j++) { if (2 <= j && j < 4) { if (buf[i*NX+j] != 5) { printf("Error at line %d in %s: expect get buf[%d]=%d but got %d\n", __LINE__,__FILE__,i*NX+j, 5, buf[i*NX+j]); nerrs++; } } else if (buf[i*NX+j] == NC_FILL_INT) { printf("Warning at line %d in %s: get buf[%d] same as NC_FILL_INT\n", __LINE__,__FILE__,i*NX+j); } } } /* read variable "var_fill" and check contents */ for (i=0; i<NY*NX; i++) buf[i] = -1; err = nc_get_var_int(ncid, varid[1], buf); CHECK_ERR for (i=0; i<NY; i++) { for (j=0; j<NX; j++) { int expect = NC_FILL_INT; if (2 <= j && j< 4) expect = 5; if (buf[i*NX+j] != expect) { printf("Error at line %d in %s: expect get buf[%d]=%d but got %d\n", __LINE__,__FILE__,i*NX+j, expect, buf[i*NX+j]); nerrs++; } } } err = nc_close(ncid); CHECK_ERR } free(buf); if (nerrs) printf("fail with %d mismatches\n",nerrs); else printf("pass\n"); return (nerrs > 0); }
int main(int argc, char **argv) { extern int ncopts; /* netCDF error options */ char *testfiles[] = {"nonesuch", "nctest_classic.nc", "nctest_64bit_offset.nc", "nctest_netcdf4.nc"}; char *testfile; int i, nerrs = 0; #ifdef USE_PARALLEL MPI_Init(&argc, &argv); #endif ncopts &= ~NC_FATAL; /* make errors nonfatal */ ncopts &= ~NC_VERBOSE; /* turn off error messages */ fprintf(stderr, "Testing V2 API with %d different netCDF formats.\n", NUM_FORMATS); for (i = 1; i <= NUM_FORMATS; i++) { switch (i) { case NC_FORMAT_CLASSIC: nc_set_default_format(NC_FORMAT_CLASSIC, NULL); fprintf(stderr, "\n\nSwitching to netCDF classic format.\n"); break; case NC_FORMAT_64BIT: nc_set_default_format(NC_FORMAT_64BIT, NULL); fprintf(stderr, "\n\nSwitching to 64-bit offset format.\n"); break; #ifdef USE_NETCDF4 case NC_FORMAT_NETCDF4: /* actually it's _CLASSIC. */ nc_set_default_format(NC_FORMAT_NETCDF4_CLASSIC, NULL); fprintf(stderr, "\n\nSwitching to netCDF-4 format (with NC_CLASSIC_MODEL).\n"); break; #endif default: fprintf(stderr, "Unexpected format!\n"); return 2; } testfile = testfiles[i]; /* Run all the tests for this format. */ nerrs += test_nccreate(testfile); nerrs += test_ncopen(testfile); nerrs += test_ncredef(testfile); nerrs += test_ncendef(testfile); nerrs += test_ncclose(testfile); nerrs += test_ncinquire(testfile); nerrs += test_ncsync(testfile); nerrs += test_ncabort(testfile); nerrs += test_ncdimdef(testfile); nerrs += test_ncdimid(testfile); nerrs += test_ncdiminq(testfile); nerrs += test_ncdimrename(testfile); nerrs += test_ncvardef(testfile); nerrs += test_ncvarid(testfile); nerrs += test_ncvarinq(testfile); nerrs += test_ncvarput1(testfile); nerrs += test_ncvarget1(testfile); nerrs += test_ncvarput(testfile); nerrs += test_ncvarget(testfile); nerrs += test_ncvarputg(testfile); nerrs += test_ncvargetg(testfile); nerrs += test_ncrecinq(testfile); nerrs += test_ncrecput(testfile); nerrs += test_ncrecget(testfile); nerrs += test_ncvarrename(testfile); nerrs += test_ncattput(testfile); nerrs += test_ncattinq(testfile); nerrs += test_ncattget(testfile); nerrs += test_ncattcopy(testfile, "test2.nc"); nerrs += test_ncattname(testfile); nerrs += test_ncattrename(testfile); nerrs += test_ncattdel(testfile); nerrs += test_nctypelen(); } fprintf(stderr, "\nTotal number of failures: %d\n", nerrs); if (nerrs) { fprintf(stderr, "nctest FAILURE!!!\n"); return 2; } else fprintf(stderr, "nctest SUCCESS!!!\n"); #ifdef USE_PARALLEL MPI_Finalize(); #endif return 0; }
int main(int argc, char *argv[]) { int i; int nfailsTotal = 0; /* total number of failures */ /* Both CRAY MPP and OSF/1 Alpha systems need this. Some of the * extreme test assignments in this program trigger floating point * exceptions on CRAY T90 */ (void) signal(SIGFPE, SIG_IGN); verbose = 0; max_nmpt = 8; /* Initialize global variables defining test file */ init_gvars(); /* If you uncomment the nc_set_log_level line, you will get a lot * of debugging info. If you set the number higher, you'll get * more. 6 is max, 0 shows only errors. 3 is a good place to * start. */ /*nc_set_log_level(3);*/ fprintf(stderr, "Testing %d different netCDF formats.\n", NUM_FORMATS); /* Go thru formats and run all tests for each of two (for netCDF-3 * only builds), or 3 (for netCDF-4 builds) different formats. Do * the netCDF-4 format last, however, because, as an additional * test, the ../nc_test4/tst_nc_test_file program looks at the * output of this program. */ for (i = 1; i <= NUM_FORMATS; i++) { switch (i) { case NC_FORMAT_CLASSIC: nc_set_default_format(NC_FORMAT_CLASSIC, NULL); fprintf(stderr, "\n\nSwitching to netCDF classic format.\n"); strcpy(testfile, "nc_test_classic.nc"); break; case NC_FORMAT_64BIT: nc_set_default_format(NC_FORMAT_64BIT, NULL); fprintf(stderr, "\n\nSwitching to 64-bit offset format.\n"); strcpy(testfile, "nc_test_64bit.nc"); break; #ifdef USE_NETCDF4 case NC_FORMAT_NETCDF4: /* actually it's _CLASSIC. */ nc_set_default_format(NC_FORMAT_NETCDF4_CLASSIC, NULL); strcpy(testfile, "nc_test_netcdf4.nc"); fprintf(stderr, "\n\nSwitching to netCDF-4 format (with NC_CLASSIC_MODEL).\n"); break; #endif default: fprintf(stderr, "Unexpected format!\n"); return 2; } /* Write the test file, needed for the read-only tests below. */ write_file(testfile); /* delete any existing scratch netCDF file */ (void) remove(scratch); /* Test read-only functions, using pre-generated test-file */ NC_TEST(nc_strerror); NC_TEST(nc_open); NC_TEST(nc_close); NC_TEST(nc_inq); NC_TEST(nc_inq_dimid); NC_TEST(nc_inq_dim); NC_TEST(nc_inq_dimlen); NC_TEST(nc_inq_dimname); NC_TEST(nc_inq_varid); NC_TEST(nc_inq_var); NC_TEST(nc_inq_natts); NC_TEST(nc_inq_ndims); NC_TEST(nc_inq_nvars); NC_TEST(nc_inq_unlimdim); NC_TEST(nc_inq_vardimid); NC_TEST(nc_inq_varname); NC_TEST(nc_inq_varnatts); NC_TEST(nc_inq_varndims); NC_TEST(nc_inq_vartype); NC_TEST(nc_get_var_text); NC_TEST(nc_get_var_uchar); NC_TEST(nc_get_var_schar); NC_TEST(nc_get_var_short); NC_TEST(nc_get_var_int); NC_TEST(nc_get_var_long); NC_TEST(nc_get_var_float); NC_TEST(nc_get_var_double); NC_TEST(nc_get_var1_text); NC_TEST(nc_get_var1_uchar); NC_TEST(nc_get_var1_schar); NC_TEST(nc_get_var1_short); NC_TEST(nc_get_var1_int); NC_TEST(nc_get_var1_long); NC_TEST(nc_get_var1_float); NC_TEST(nc_get_var1_double); NC_TEST(nc_get_var1); NC_TEST(nc_get_vara_text); NC_TEST(nc_get_vara_uchar); NC_TEST(nc_get_vara_schar); NC_TEST(nc_get_vara_short); NC_TEST(nc_get_vara_int); NC_TEST(nc_get_vara_long); NC_TEST(nc_get_vara_float); NC_TEST(nc_get_vara_double); NC_TEST(nc_get_vara); NC_TEST(nc_get_vars_text); NC_TEST(nc_get_vars_uchar); NC_TEST(nc_get_vars_schar); NC_TEST(nc_get_vars_short); NC_TEST(nc_get_vars_int); NC_TEST(nc_get_vars_long); NC_TEST(nc_get_vars_float); NC_TEST(nc_get_vars_double); NC_TEST(nc_get_vars); NC_TEST(nc_get_varm_text); NC_TEST(nc_get_varm_uchar); NC_TEST(nc_get_varm_schar); NC_TEST(nc_get_varm_short); NC_TEST(nc_get_varm_int); NC_TEST(nc_get_varm_long); NC_TEST(nc_get_varm_float); NC_TEST(nc_get_varm_double); NC_TEST(nc_get_varm); NC_TEST(nc_get_att_text); NC_TEST(nc_get_att_uchar); NC_TEST(nc_get_att_schar); NC_TEST(nc_get_att_short); NC_TEST(nc_get_att_int); NC_TEST(nc_get_att_long); NC_TEST(nc_get_att_float); NC_TEST(nc_get_att_double); NC_TEST(nc_get_att); NC_TEST(nc_inq_att); NC_TEST(nc_inq_attname); NC_TEST(nc_inq_attid); NC_TEST(nc_inq_attlen); NC_TEST(nc_inq_atttype); /* Test write functions */ NC_TEST(nc_create); NC_TEST(nc_redef); /* NC_TEST(nc_enddef); *//* redundant */ NC_TEST(nc_sync); NC_TEST(nc_abort); NC_TEST(nc_def_dim); NC_TEST(nc_rename_dim); NC_TEST(nc_def_var); NC_TEST(nc_put_var_text); NC_TEST(nc_put_var_uchar); NC_TEST(nc_put_var_schar); NC_TEST(nc_put_var_short); NC_TEST(nc_put_var_int); NC_TEST(nc_put_var_long); NC_TEST(nc_put_var_float); NC_TEST(nc_put_var_double); NC_TEST(nc_put_var1_text); NC_TEST(nc_put_var1_uchar); NC_TEST(nc_put_var1_schar); NC_TEST(nc_put_var1_short); NC_TEST(nc_put_var1_int); NC_TEST(nc_put_var1_long); NC_TEST(nc_put_var1_float); NC_TEST(nc_put_var1_double); NC_TEST(nc_put_var1); NC_TEST(nc_put_vara_text); NC_TEST(nc_put_vara_uchar); NC_TEST(nc_put_vara_schar); NC_TEST(nc_put_vara_short); NC_TEST(nc_put_vara_int); NC_TEST(nc_put_vara_long); NC_TEST(nc_put_vara_float); NC_TEST(nc_put_vara_double); NC_TEST(nc_put_vara); NC_TEST(nc_put_vars_text); NC_TEST(nc_put_vars_uchar); NC_TEST(nc_put_vars_schar); NC_TEST(nc_put_vars_short); NC_TEST(nc_put_vars_int); NC_TEST(nc_put_vars_long); NC_TEST(nc_put_vars_float); NC_TEST(nc_put_vars_double); NC_TEST(nc_put_vars); NC_TEST(nc_put_varm_text); NC_TEST(nc_put_varm_uchar); NC_TEST(nc_put_varm_schar); NC_TEST(nc_put_varm_short); NC_TEST(nc_put_varm_int); NC_TEST(nc_put_varm_long); NC_TEST(nc_put_varm_float); NC_TEST(nc_put_varm_double); NC_TEST(nc_put_varm); NC_TEST(nc_rename_var); NC_TEST(nc_put_att_text); NC_TEST(nc_put_att_uchar); NC_TEST(nc_put_att_schar); NC_TEST(nc_put_att_short); NC_TEST(nc_put_att_int); NC_TEST(nc_put_att_long); NC_TEST(nc_put_att_float); NC_TEST(nc_put_att_double); NC_TEST(nc_put_att); NC_TEST(nc_copy_att); NC_TEST(nc_rename_att); NC_TEST(nc_del_att); NC_TEST(nc_set_default_format); } fprintf(stderr, "\n*** Total number of failures: %d\n", nfailsTotal); if (nfailsTotal) { fprintf(stderr, "*** nc_test FAILURE!!!\n"); return 2; } else fprintf(stderr, "*** nc_test SUCCESS!!!\n"); return 0; }