/* {{{ goemphp php_exec_file(filename) */ char * php_exec_file(char *filename) { char *result = NULL; zend_first_try { zend_file_handle file_handle = {0}; file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = filename; file_handle.free_filename = 0; file_handle.opened_path = NULL; php_execute_script(&file_handle TSRMLS_CC ); // executed failure, get error message if (PG(last_error_message)) { result = strdup(PG(last_error_message)); free(PG(last_error_message)); PG(last_error_message) = NULL; } if (!result && EG(exception)) { result = exception_error(EG(exception), E_ERROR TSRMLS_CC); EG(exception) = NULL; } // trigger_error & throw exception need to handle // if (error) { // // } else if (exception) { // // } } zend_end_try(); return result; }
/* {{{ goemphp php_eval_script(script) */ char * php_eval_script(char *script) { char *result = NULL; zend_first_try { zend_eval_string(script, NULL, "GoEmPHP" TSRMLS_CC); // executed failure, get error message if (PG(last_error_message)) { result = strdup(PG(last_error_message)); free(PG(last_error_message)); PG(last_error_message) = NULL; } if (PG(last_error_message)) { result = strdup(PG(last_error_message)); free(PG(last_error_message)); PG(last_error_message) = NULL; } if (!result && EG(exception)) { result = exception_error(EG(exception), E_ERROR TSRMLS_CC); EG(exception) = NULL; } // trigger_error & throw exception need to handle // if (error) { // // } else if (exception) { // // } } zend_end_try(); return result; }
/*************************************************************************** * @brief GSkymap_wcs_io ***************************************************************************/ void TestGSky::test_GSkymap_wcs_io(void) { // Set filenames const std::string file1 = "test_skymap_wcs_1.fits"; const std::string file2 = "test_skymap_wcs_2.fits"; // Define WCS map for comparison GSkymap refmap1("CAR", "GAL", 0.0, 0.0, -1.0, 1.0, 100, 100); GSkymap refmap2("CAR", "CEL", 0.0, 0.0, -0.3, 0.3, 200, 200); // Test WCS map saving test_try("Test WCS map saving"); try { for (int pix = 0; pix < refmap1.npix(); ++pix) { refmap1(pix) = pix+1; } refmap1.save(file1, 1); for (int pix = 0; pix < refmap2.npix(); ++pix) { refmap2(pix) = pix+1; } refmap2.save(file2, 1); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test WCS map loading (1) test_try("Test WCS map loading (1)"); try { GSkymap map; map.load(file1); int diff = 0; for (int pix = 0; pix < refmap1.npix(); ++pix) { if (map(pix) != refmap1(pix)) { diff++; } } if (diff > 0) { throw exception_error("Loaded file "+file1+" differs from saved file ."); } test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test WCS map loading (2) test_try("Test WCS map loading (2)"); try { GSkymap map; map.load(file2); int diff = 0; for (int pix = 0; pix < refmap2.npix(); ++pix) { if (map(pix) != refmap2(pix)) { diff++; } } if (diff > 0) { throw exception_error("Loaded file "+file2+" differs from saved file ."); } test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Exit test return; }
/*************************************************************************** * @brief GSkymap_healpix_io ***************************************************************************/ void TestGSky::test_GSkymap_healpix_io(void) { // Set filenames const std::string file1 = "test_skymap_hpx_1.fits"; // Define Healpix map for comparison GSkymap refmap("GAL", 4, "RING", 1); // Test Healpix map saving test_try("Test Healpix map saving"); try { for (int pix = 0; pix < refmap.npix(); ++pix) refmap(pix) = pix+1; refmap.save(file1, true); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test Healpix map loading test_try("Test Healpix map loading"); try { GSkymap map; map.load(file1); int diff = 0; for (int pix = 0; pix < refmap.npix(); ++pix) { if (map(pix) != refmap(pix)) diff++; } if (diff > 0) { throw exception_error("Loaded file differs from saved file."); } test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test Healpix map instantiation test_try("Test Healpix map instantiation"); try { GSkymap map(file1); int diff = 0; for (int pix = 0; pix < refmap.npix(); ++pix) { if (map(pix) != refmap(pix)) diff++; } if (diff > 0) { throw exception_error("Loaded file differs from saved file."); } test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Exit test return; }
/***********************************************************************//** * @brief Test GWcs projections * * This method tests all WCS projections that have been registered. ***************************************************************************/ void TestGSky::test_GWcs(void) { // Allocate parameters for testing double crval1 = 83.63; double crval2 = 22.01; double crpix1 = 100.5; double crpix2 = 100.5; double cdelt1 = 0.5; double cdelt2 = 0.5; int nx = 200; int ny = 200; // Loop over all non-HealPix projections GWcsRegistry registry; for (int i = 0; i < registry.size(); ++i) { // Set header std::string test_class = "GWcs" + registry.code(i); // Perform tests test_try("Test "+test_class); try { // Allocate projection CEL and GAL GWcs *cel = dynamic_cast<GWcs*>(registry.alloc(registry.code(i))); GWcs *gal = dynamic_cast<GWcs*>(registry.alloc(registry.code(i))); // Throw an error if allocation failed if (cel == NULL || gal == NULL) { std::cout << std::endl << "TEST ERROR: Could not allocate "+test_class+"." << std::endl; throw exception_error("Could not allocate"+test_class); } // Set projections test_try("Set projections"); try { cel->set("CEL", crval1, crval2, crpix1, crpix2, cdelt1, cdelt2); gal->set("GAL", crval1, crval2, crpix1, crpix2, cdelt1, cdelt2); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test forth-back CEL conversion test_try("Test forth-back CEL conversion"); try { double tol = 0.0; if ((tol = wcs_forth_back_pixel(cel, nx, ny, crpix1, crpix2)) > 1.0e-10) { throw exception_failure("CEL forth-back transformation tolerance 1.0e-10 exceeded: "+gammalib::str(tol)); } test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test forth-back GAL conversion test_try("Test forth-back GAL conversion"); try { double tol = 0.0; if ((tol = wcs_forth_back_pixel(gal, nx, ny, crpix1, crpix2)) > 1.0e-10) { throw exception_failure("GAL forth-back transformation tolerance 1.0e-10 exceeded: "+gammalib::str(tol)); } test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test CEL copy test_try("Test CEL copy"); try { double tol = 0.0; if ((tol = wcs_copy(cel, nx, ny, crpix1, crpix2)) > 1.0e-4) { throw exception_failure("CEL copy tolerance 1.0e-4 exceeded: "+gammalib::str(tol)); } test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test GAL copy test_try("Test GAL copy"); try { double tol = 0.0; if ((tol = wcs_copy(gal, nx, ny, crpix1, crpix2)) > 1.0e-4) { throw exception_failure("GAL copy tolerance 1.0e-4 exceeded: "+gammalib::str(tol)); } test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Free memory delete cel; delete gal; // Signal success test_try_success(); } catch (std::exception &e) { test_try_failure(e); } } // endfor: looped over all non-HealPix projections // Exit test return; }