void check_err(const int stat, const int line, const char* file) { if (stat != NC_NOERR) { fprintf(stderr, "ncgen: %s\n", nc_strerror(stat)); fprintf(stderr, "\t(%s:%d)\n", file,line); #ifdef USE_NETCDF4 H5Eprint1(stderr); #endif fflush(stderr); exit(1); } }
/*------------------------------------------------------------------------- * * Function: error_version_macros * * Purpose: Test H5E version compatibility macros. * * Return: Success: 0 * Failure: -1 * * Programmer: Neil Fortner * Saturday, October 11, 2008 * *------------------------------------------------------------------------- */ static int error_version_macros(void) { H5E_walk1_t walk_cb = &error_version_macros_cb; /* H5Ewalk callback function (test H5E_walk1_t) */ H5E_auto1_t auto_func; /* Automatic error handler (test H5E_auto1_t) */ void *client_data; /* Automatic error handler data */ FILE *file; /* File to redirect output to */ char filename[NAME_BUF_SIZE]; /* Output message about test being performed */ TESTING("H5E version compatibility macros"); /* Create the test file (used to prevent output of H5Eprint to the terminal) */ h5_fixname(ERR_VERS_NAME, H5P_DEFAULT, filename, sizeof filename); if (NULL == (file = HDfopen(filename, "w"))) TEST_ERROR; /* Print error stack (check H5Eprint1) */ if (H5Eprint1(file) < 0) TEST_ERROR; /* Get automatic error traversal function (check H5Eget_auto1) */ if (H5Eget_auto1(&auto_func, &client_data) < 0) TEST_ERROR; /* Set automatic error traversal function (check H5Eset_auto1) */ if (H5Eset_auto1(auto_func, client_data) < 0) TEST_ERROR; /* Push an error message (check H5Epush1) */ if (H5Epush1("somefile", "somefunc", 13241, H5E_STORAGE, H5E_BADATOM, "Hi! I'm an error message!") < 0) TEST_ERROR; /* Clear error stack (check H5Eclear1) */ if (H5Eclear1() < 0) TEST_ERROR; /* Walk the error stack (check H5Ewalk1) */ if (H5Ewalk1(H5E_WALK_DOWNWARD, walk_cb, NULL) < 0) TEST_ERROR; /* Close the file */ HDfclose(file); HDremove(filename); PASSED(); return 0; error: HDfclose(file); HDremove(filename); return -1; } /* end error_version_macros() */