void usage(void) { derror("Usage: %s [ -b ] [ -c ] [ -f ] [ -k kind ] [ -x ] [-S struct-format] [-M <name> [ -o outfile] [ file ... ]", progname); derror("netcdf library version %s", nc_inq_libvers()); }
void usage(void) { derror("Usage: %s" " [-1]" " [-3]" " [-4]" " [-5]" " [-6]" " [-7]" " [-b]" " [-B buffersize]" " [-d]" " [-D debuglevel]" " [-h]" " [-k kind ]" " [-l language=b|c|f77|java]" " [-M <name>]" " [-n]" " [-o outfile]" " [-P]" " [-x]" " [-N datasetname]" " [-L loglevel]" " [-H]" " [file ... ]", progname); derror("netcdf library version %s", nc_inq_libvers()); }
int main() { printf("NetCDF version: %s\n", nc_inq_libvers()); printf("*** SUCCESS!\n"); return 0; }
void sdatio_add_standard_metadata(struct sdatio_file * sfile){ time_t current_time; char strtime[40]; size_t count = 40; current_time = time(NULL); strftime(strtime, count, "%c %z", localtime(¤t_time)); sdatio_add_metadata(sfile, SDATIO_CHAR, "creation_time", &strtime); sdatio_add_metadata(sfile, SDATIO_INT, "creation_time_in_seconds_after_epoch", (int *)¤t_time); sdatio_add_metadata(sfile, SDATIO_CHAR, "simpledatio_info", "This datafile was constructed using simpledatio, a simplified netCDF interface."); sdatio_add_metadata(sfile, SDATIO_CHAR, "simpledatio_url", "http://github.com/edmundhighcock/simpledataio"); sdatio_add_metadata(sfile, SDATIO_CHAR, "simpledatio_version", SDATIO_VERSION_STRING); sdatio_add_metadata(sfile, SDATIO_CHAR, "netcdf_version", nc_inq_libvers()); sdatio_add_metadata(sfile, SDATIO_CHAR, "netcdf_url", "http://www.unidata.ucar.edu/software/netcdf"); }
static void usage(void) { #define USAGE "\ [-c] Coordinate variable data and header information\n\ [-h] Header information only, no data\n\ [-v var1[,...]] Data for variable(s) <var1>,... only\n\ [-b [c|f]] Brief annotations for C or Fortran indices in data\n\ [-f [c|f]] Full annotations for C or Fortran indices in data\n\ [-l len] Line length maximum in data section (default 80)\n\ [-n name] Name for netCDF (default derived from file name)\n\ [-p n[,n]] Display floating-point values with less precision\n\ file File name of input netCDF file\n" (void) fprintf(stderr, "%s [-c|-h] [-v ...] [[-b|-f] [c|f]] [-l len] [-n name] [-p n[,n]] file\n%s", progname, USAGE); (void) fprintf(stderr, "netcdf library version %s\n", nc_inq_libvers()); exit(EXIT_FAILURE); }
int main(int argc, char **argv) { printf("\n*** Testing netcdf-4 file functions.\n"); { char str[NC_MAX_NAME+1]; /* Actually we never make any promises about the length of the * version string, but it is always smaller than NC_MAX_NAME. */ if (strlen(nc_inq_libvers()) > NC_MAX_NAME) ERR; strcpy(str, nc_inq_libvers()); printf("*** testing version %s...", str); } SUMMARIZE_ERR; printf("*** testing with bad inputs..."); { int ncid; /* Make sure bad create mode causes failure. */ /*if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;*/ /* Create an empty file. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_close(ncid)) ERR; if (nc_open(FILE_NAME, NC_MPIIO|NC_MPIPOSIX, &ncid) != NC_EINVAL) ERR; if (nc_create(FILE_NAME, NC_64BIT_OFFSET|NC_NETCDF4, &ncid) != NC_EINVAL) ERR; if (nc_create(FILE_NAME, NC_CLASSIC_MODEL|NC_MPIIO|NC_MPIPOSIX, &ncid) != NC_EINVAL) ERR; if (nc_create(FILE_NAME, NC_MPIIO|NC_MPIPOSIX, &ncid) != NC_EINVAL) ERR; } SUMMARIZE_ERR; printf("*** testing simple opens and creates..."); { int ncid, ncid2, ncid3, varid, dimids[2]; int ndims, nvars, natts, unlimdimid; int dimids_var[1], var_type; size_t dim_len; char dim_name[NC_MAX_NAME+1], var_name[NC_MAX_NAME+1]; unsigned char uchar_out[DIM1_LEN] = {0, 128, 255}; /* Open and close empty file. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_close(ncid)) ERR; /* Recreate it again. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR; if (nc_def_var(ncid, VAR1_NAME, NC_INT, 1, dimids, &varid)) ERR; if (nc_enddef(ncid)) ERR; if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR; if (nc_close(ncid)) ERR; /* Check the contents. Then define a new variable. Since it's * netcdf-4, nc_enddef isn't required - it's called * automatically. */ if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != 2 || nvars != 2 || natts != 0 || unlimdimid != -1) ERR; if (nc_redef(ncid)) ERR; if (nc_enddef(ncid)) ERR; if (nc_def_var(ncid, VAR3_NAME, NC_INT, 2, dimids, &varid)) ERR; if (nc_close(ncid)) ERR; /* Open three copies of the same file. */ if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; if (nc_open(FILE_NAME, NC_WRITE, &ncid2)) ERR; if (nc_open(FILE_NAME, NC_WRITE, &ncid3)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != 2 || nvars != 3 || natts != 0 || unlimdimid != -1) ERR; if (nc_inq(ncid2, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != 2 || nvars != 3 || natts != 0 || unlimdimid != -1) ERR; if (nc_inq(ncid3, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != 2 || nvars != 3 || natts != 0 || unlimdimid != -1) ERR; if (nc_close(ncid)) ERR; if (nc_close(ncid2)) ERR; if (nc_close(ncid3)) ERR; /* Open and close empty file. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_close(ncid)) ERR; /* Check the contents. */ if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != 0 || nvars != 0 || natts != 0 || unlimdimid != -1) ERR; if (nc_close(ncid)) ERR; /* Create a file with one dimension and nothing else. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; if (nc_enddef(ncid)) ERR; if (nc_close(ncid)) ERR; /* Check the contents. */ if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != 1 || nvars != 0 || natts != 0 || unlimdimid != -1) ERR; if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR; if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR; if (nc_close(ncid)) ERR; /* Create a simple file, and write some data to it. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; if (nc_def_var(ncid, VAR1_NAME, NC_BYTE, 1, dimids, &varid)) ERR; if (nc_enddef(ncid)) ERR; if (nc_put_var_uchar(ncid, varid, uchar_out) != NC_ERANGE) ERR; if (nc_close(ncid)) ERR; /* Check the contents. */ if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != 1 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR; if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR; if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR; if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR; if (ndims != 1 || strcmp(var_name, VAR1_NAME) || var_type != NC_BYTE || dimids_var[0] != dimids[0] || natts != 0) ERR; if (nc_close(ncid)) ERR; /* Recreate the file. */ if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR; if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; if (nc_def_var(ncid, VAR1_NAME, NC_BYTE, 1, dimids, &varid)) ERR; if (nc_enddef(ncid)) ERR; if (nc_put_var_uchar(ncid, varid, uchar_out)) ERR; if (nc_close(ncid)) ERR; /* Recreate it, then make sure NOCLOBBER works. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_close(ncid)) ERR; if (nc_create(FILE_NAME, NC_NETCDF4|NC_NOCLOBBER, &ncid) != NC_EEXIST) ERR; /* Recreate it again. */ if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR; if (nc_def_var(ncid, VAR1_NAME, NC_INT, 1, dimids, &varid)) ERR; if (nc_enddef(ncid)) ERR; if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR; if (nc_close(ncid)) ERR; /* Check the contents. Then define a new variable. Since it's * netcdf-4, nc_enddef isn't required - it's called * automatically. */ if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != 2 || nvars != 2 || natts != 0 || unlimdimid != -1) ERR; if (nc_redef(ncid)) ERR; if (nc_enddef(ncid)) ERR; if (nc_def_var(ncid, VAR3_NAME, NC_INT, 2, dimids, &varid)) ERR; if (nc_close(ncid)) ERR; /* Recreate it again with netcdf-3 rules turned on. */ if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLASSIC_MODEL, &ncid)) ERR; if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; if (nc_def_var(ncid, VAR1_NAME, NC_INT, 1, dimids, &varid)) ERR; if (nc_enddef(ncid)) ERR; if (nc_close(ncid)) ERR; /* Check the contents. Check that netcdf-3 rules are in effect. */ if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != 1 || nvars != 1 || natts != 0 || unlimdimid != -1) ERR; if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid) != NC_ENOTINDEFINE) ERR; if (nc_close(ncid)) ERR; /* Check some other stuff about it. Closing and reopening the * file forces HDF5 to tell us if we forgot to free some HDF5 * resource associated with the file. */ if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR; if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR; if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR; if (ndims != 1 || strcmp(var_name, VAR1_NAME) || var_type != NC_INT || dimids_var[0] != dimids[0] || natts != 0) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing more complex opens and creates..."); { int ncid, varid, dimids[2]; int ndims, nvars, natts, unlimdimid; int dimids_var[2], var_type; size_t dim_len; char dim_name[NC_MAX_NAME+1], var_name[NC_MAX_NAME+1]; float float_in, float_out = 99.99; int int_in, int_out = -9999; /* Create a file, this time with attributes. */ if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR; if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR; if (nc_def_var(ncid, VAR1_NAME, NC_INT, 2, dimids, &varid)) ERR; if (nc_def_var(ncid, VAR2_NAME, NC_UINT, 2, dimids, &varid)) ERR; if (nc_put_att_float(ncid, NC_GLOBAL, ATT1_NAME, NC_FLOAT, 1, &float_out)) ERR; if (nc_put_att_int(ncid, NC_GLOBAL, ATT2_NAME, NC_INT, 1, &int_out)) ERR; if (nc_close(ncid)) ERR; /* Reopen the file and check it. */ if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; if (ndims != 2 || nvars != 2 || natts != 2 || unlimdimid != -1) ERR; if (nc_close(ncid)) ERR; /* Reopen it and check each dim, var, and att. */ if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_inq_dim(ncid, 0, dim_name, &dim_len)) ERR; if (dim_len != DIM1_LEN || strcmp(dim_name, DIM1_NAME)) ERR; if (nc_inq_dim(ncid, 1, dim_name, &dim_len)) ERR; if (dim_len != DIM2_LEN || strcmp(dim_name, DIM2_NAME)) ERR; if (nc_inq_var(ncid, 0, var_name, &var_type, &ndims, dimids_var, &natts)) ERR; if (ndims != 2 || strcmp(var_name, VAR1_NAME) || var_type != NC_INT || dimids_var[0] != dimids[0] || natts != 0) ERR; if (nc_inq_var(ncid, 1, var_name, &var_type, &ndims, dimids_var, &natts)) ERR; if (ndims != 2 || strcmp(var_name, VAR2_NAME) || var_type != NC_UINT || dimids_var[1] != dimids[1] || natts != 0) ERR; if (nc_get_att_float(ncid, NC_GLOBAL, ATT1_NAME, &float_in)) ERR; if (float_in != float_out) ERR; if (nc_get_att_int(ncid, NC_GLOBAL, ATT2_NAME, &int_in)) ERR; if (int_in != int_out) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing redef for netCDF classic..."); test_redef(NC_FORMAT_CLASSIC); SUMMARIZE_ERR; printf("*** testing redef for netCDF 64-bit offset..."); test_redef(NC_FORMAT_64BIT); SUMMARIZE_ERR; printf("*** testing redef for netCDF-4 ..."); test_redef(NC_FORMAT_NETCDF4); SUMMARIZE_ERR; printf("*** testing redef for netCDF-4, with strict netCDF-3 rules..."); test_redef(NC_FORMAT_NETCDF4_CLASSIC); SUMMARIZE_ERR; printf("*** testing different formats..."); { int ncid; int format; /* Create a netcdf-3 file. */ if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR; if (nc_inq_format(ncid, &format)) ERR; if (format != NC_FORMAT_CLASSIC) ERR; if (nc_close(ncid)) ERR; /* Create a netcdf-3 64-bit offset file. */ if (nc_create(FILE_NAME, NC_64BIT_OFFSET|NC_CLOBBER, &ncid)) ERR; if (nc_inq_format(ncid, &format)) ERR; if (format != NC_FORMAT_64BIT) ERR; if (nc_close(ncid)) ERR; /* Create a netcdf-4 file. */ if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR; if (nc_inq_format(ncid, &format)) ERR; if (format != NC_FORMAT_NETCDF4) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing CLASSIC_MODEL flag with classic formats..."); { int ncid; int format; /* Create a netcdf-3 file. */ if (nc_create(FILE_NAME, NC_CLOBBER|NC_CLASSIC_MODEL, &ncid)) ERR; if (nc_inq_format(ncid, &format)) ERR; if (format != NC_FORMAT_CLASSIC) ERR; if (nc_close(ncid)) ERR; /* Create a netcdf-3 64-bit offset file. */ if (nc_create(FILE_NAME, NC_64BIT_OFFSET|NC_CLOBBER|NC_CLASSIC_MODEL, &ncid)) ERR; if (nc_inq_format(ncid, &format)) ERR; if (format != NC_FORMAT_64BIT) ERR; if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; printf("*** testing multiple open files..."); { #define VAR_NAME "Captain_Kirk" #define NDIMS 1 #define NUM_FILES 30 #define TEXT_LEN 15 #define D1_NAME "tl" int ncid[NUM_FILES], varid; int dimid; size_t count[NDIMS], index[NDIMS] = {0}; const char ttext[TEXT_LEN + 1] = "20051224.150000"; char ttext_in[TEXT_LEN + 1]; char file_name[NC_MAX_NAME + 1]; size_t chunks[NDIMS] = {TEXT_LEN + 1}; int f; /* Create a bunch of files. */ for (f = 0; f < NUM_FILES; f++) { sprintf(file_name, "tst_files2_%d.nc", f); if (nc_create(file_name, NC_NETCDF4, &ncid[f])) ERR; if (nc_def_dim(ncid[f], D1_NAME, TEXT_LEN + 1, &dimid)) ERR; if (nc_def_var(ncid[f], VAR_NAME, NC_CHAR, NDIMS, &dimid, &varid)) ERR; if (f % 2 == 0) if (nc_def_var_chunking(ncid[f], varid, 0, chunks)) ERR; /* Write one time to the coordinate variable. */ count[0] = TEXT_LEN + 1; if (nc_put_vara_text(ncid[f], varid, index, count, ttext)) ERR; } /* Read something from each file. */ for (f = 0; f < NUM_FILES; f++) { if (nc_get_vara_text(ncid[f], varid, index, count, (char *)ttext_in)) ERR; if (strcmp(ttext_in, ttext)) ERR; } /* Close all open files. */ for (f = 0; f < NUM_FILES; f++) if (nc_close(ncid[f])) ERR; } SUMMARIZE_ERR; FINAL_RESULTS; }
main() { (void) printf("Version: %s\n", nc_inq_libvers()); return 0; }
/* This prints out a helpful message to the user when they screw up or * are confused and ask for help. */ static void usage() { fprintf(stderr, "cfcheck file\n%s", USAGE); fprintf(stderr, "netcdf library version %s\n", nc_inq_libvers()); }