int main(int argc, char* argv[]) { int err = 0; int ecode = 0; int ncid; int cmode, format; int nprocs, rank; MPI_Comm comm=MPI_COMM_SELF; MPI_Info info=MPI_INFO_NULL; printf("\n*** Testing nc_inq_format_extended for pnetcdf..."); MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (nprocs > 1 && rank == 0) printf("This test program is intended to run on ONE process\n"); if (rank > 0) goto fn_exit; /* first, use PnetCDF to create a file with default header/variable alignment */ #ifdef DISABLE_PNETCDF_ALIGNMENT MPI_Info_create(&info); MPI_Info_set(info, "nc_header_align_size", "1"); MPI_Info_set(info, "nc_var_align_size", "1"); #endif /* test CDF-1 file format */ cmode = NC_PNETCDF | NC_CLOBBER; if (nc_create_par(FILENAME, cmode, comm, info, &ncid)) ERR_RET; if (nc_enddef(ncid)) ERR; if(nc_inq_format_extended(ncid,&format,&cmode)) ERR; if((cmode & NC_PNETCDF) != NC_PNETCDF) { printf("***FAIL at line %d: mode was %08x ; expected %08x\n",__LINE__,cmode,NC_PNETCDF); ecode = 1; ERR; } if(format != NC_FORMATX_PNETCDF) { printf("***FAIL at line %d: format was %d ; expected %d\n",__LINE__,format,NC_FORMATX_PNETCDF); ecode = 1; ERR; } /* test CDF-2 file format */ cmode = NC_PNETCDF | NC_CLOBBER | NC_64BIT_OFFSET; if (nc_create_par(FILENAME, cmode, comm, info, &ncid)) ERR_RET; if (nc_enddef(ncid)) ERR; if(nc_inq_format_extended(ncid,&format,&cmode)) ERR; if((cmode & NC_64BIT_OFFSET) != NC_64BIT_OFFSET) { printf("***FAIL at line %d: mode was %08x ; expected %08x\n",__LINE__,cmode,NC_64BIT_OFFSET); ecode = 1; ERR; } if(format != NC_FORMATX_PNETCDF) { printf("***FAIL at line %d: format was %d ; expected %d\n",__LINE__,format,NC_FORMATX_PNETCDF); ecode = 1; ERR; } /* test CDF-5 file format */ cmode = NC_PNETCDF | NC_CLOBBER | NC_64BIT_DATA; if (nc_create_par(FILENAME, cmode, comm, info, &ncid)) ERR_RET; if (nc_enddef(ncid)) ERR; if(nc_inq_format_extended(ncid,&format,&cmode)) ERR; if((cmode & NC_64BIT_DATA) != NC_64BIT_DATA) { printf("***FAIL at line %d: mode was %08x ; expected %08x\n",__LINE__,cmode,NC_64BIT_DATA); ecode = 1; ERR; } if(format != NC_FORMATX_PNETCDF) { printf("***FAIL at line %d: format was %d ; expected %d\n",__LINE__,format,NC_FORMATX_PNETCDF); ecode = 1; ERR; } if (nc_abort(ncid)) ERR; fn_exit: MPI_Finalize(); SUMMARIZE_ERR; FINAL_RESULTS; return ecode; }
int main(int argc, char **argv) { printf("\n*** Testing user-defined formats.\n"); printf("*** testing simple user-defined format..."); { int ncid; NC_Dispatch *disp_in; int i; /* Create an empty file to play with. */ if (nc_create(FILE_NAME, 0, &ncid)) ERR; if (nc_close(ncid)) ERR; /* Test all available user-defined format slots. */ for (i = 0; i < NUM_UDFS; i++) { /* Add our user defined format. */ if (nc_def_user_format(mode[i], &tst_dispatcher, NULL)) ERR; /* Check that our user-defined format has been added. */ if (nc_inq_user_format(mode[i], &disp_in, NULL)) ERR; if (disp_in != &tst_dispatcher) ERR; /* Open file with our defined functions. */ if (nc_open(FILE_NAME, mode[i], &ncid)) ERR; if (nc_close(ncid)) ERR; /* Open file again and abort, which is the same as closing it. */ if (nc_open(FILE_NAME, mode[i], &ncid)) ERR; if (nc_inq_format(ncid, NULL) != TEST_VAL_42) ERR; if (nc_inq_format_extended(ncid, NULL, NULL) != TEST_VAL_42) ERR; if (nc_abort(ncid) != TEST_VAL_42) ERR; } } SUMMARIZE_ERR; printf("*** testing user-defined format with magic number..."); { int ncid; NC_Dispatch *disp_in; char magic_number[5] = "1111"; char dummy_data[11] = "0123456789"; char magic_number_in[NC_MAX_MAGIC_NUMBER_LEN]; FILE *FP; int i; /* Create a file with magic number at start. */ if (!(FP = fopen(FILE_NAME, "w"))) ERR; if (fwrite(magic_number, sizeof(char), strlen(magic_number), FP) != strlen(magic_number)) ERR; if (fwrite(dummy_data, sizeof(char), strlen(dummy_data), FP) != strlen(dummy_data)) ERR; if (fclose(FP)) ERR; /* Test all available user-defined format slots. */ for (i = 0; i < NUM_UDFS; i++) { /* Add our test user defined format. */ if (nc_def_user_format(mode[i], &tst_dispatcher, magic_number)) ERR; /* Check that our user-defined format has been added. */ if (nc_inq_user_format(mode[i], &disp_in, magic_number_in)) ERR; if (disp_in != &tst_dispatcher) ERR; if (strncmp(magic_number, magic_number_in, strlen(magic_number))) ERR; /* Open file with our defined functions. */ if (nc_open(FILE_NAME, mode[i], &ncid)) ERR; if (nc_close(ncid)) ERR; /* Open file again and abort, which is the same as closing * it. This time we don't specify a mode, because the magic * number is used to identify the file. */ if (nc_open(FILE_NAME, 0, &ncid)) ERR; if (nc_inq_format(ncid, NULL) != TEST_VAL_42) ERR; if (nc_inq_format_extended(ncid, NULL, NULL) != TEST_VAL_42) ERR; if (nc_abort(ncid) != TEST_VAL_42) ERR; } } SUMMARIZE_ERR; FINAL_RESULTS; }