void InitDE431(const char* filepath) { ephem = jpl_init_ephemeris(filepath, nams, vals); if(jpl_init_error_code() != 0) { StelApp::getInstance().getCore()->setDe431Active(false); qDebug() << "Error "<< jpl_init_error_code() << "at DE431 init:" << jpl_init_error_message(); } else { initDone = true; double jd1, jd2; jd1=jpl_get_double(ephem, JPL_EPHEM_START_JD); jd2=jpl_get_double(ephem, JPL_EPHEM_END_JD); qDebug() << "DE431 init successful. startJD=" << QString::number(jd1, 'f', 4) << "endJD=" << QString::number(jd2, 'f', 4); } }
int main( const int argc, const char **argv) { char nams[JPL_MAX_N_CONSTANTS][6], buff[102]; double vals[JPL_MAX_N_CONSTANTS]; double max_err_found[10][6]; int line, n_failures[10]; size_t i, j; unsigned n_constants, n_columns; int output_frequency = 100; const char *ephfile_name = argv[1]; double start_jd, end_jd; double roundoff_error = 0.; bool report_all_errors = false; bool pause_on_errors = true; FILE *testfile; clock_t timer; void *ephem; const char *test_file_name = NULL; #if defined( __GNUC__) && !defined( __MINGW32__) const char path_separator = '/'; #else const char path_separator = '\\'; #endif const char *error_messages[7] = { "Result outside acceptable error tolerance", "Outside date range", "Read error", "Quantity not in index", "? Obsolete error; shouldn't happen", "Invalid index", "Seek error" }; const int n_errors = sizeof( error_messages) / sizeof( error_messages[0]); /***** Write a fingerprint to the screen. ***********************************/ setvbuf( stdout, NULL, _IONBF, 0); puts("\n JPL test-ephemeris program (v.1.2)\n" " C version translated from the original JPL FORTRAN code.\n"); if( argc < 2) error_exit( -1); for( i = 0; i < 10; i++) for( j = 0; j < 6; j++) max_err_found[i][j] = 0.; for( i = 2; i < (size_t)argc; i++) if( argv[i][0] == '-') switch( argv[i][1]) { case 'a': case 'A': report_all_errors = true; break; case 'f': case 'F': output_frequency = atoi( argv[i] + 2); break; case 'n': case 'N': pause_on_errors = false; break; case 't': case 'T': test_file_name = argv[i] + 2; break; default: printf( "Unrecognized option '%s'\n", argv[i]); error_exit( -2); break; } /****** Print the ephemeris constants. **************************************/ ephem = jpl_init_ephemeris( ephfile_name, nams, vals); if( !ephem) { printf( "Ephemeris file '%s' not loaded\n", ephfile_name); printf( "Error code: %d\n", jpl_init_error_code( )); error_exit( -2); } else printf( "Ephemeris initialized\n"); n_constants = (unsigned)jpl_get_long( ephem, JPL_EPHEM_N_CONSTANTS); printf( "%u constants\n", n_constants); if( n_constants > JPL_MAX_N_CONSTANTS) n_constants = JPL_MAX_N_CONSTANTS; start_jd = jpl_get_double( ephem, JPL_EPHEM_START_JD), end_jd = jpl_get_double( ephem, JPL_EPHEM_END_JD), printf("%.9f %.9f %.9f\n", start_jd, end_jd, jpl_get_double( ephem, JPL_EPHEM_STEP)); n_columns = (n_constants + 1) / 2; for( i = 0; i < (size_t)n_columns; i++) { printf("%.6s %24.16E",nams[i],vals[i]); if( i + n_columns < n_constants) printf(" %.6s %24.16E",nams[i + n_columns],vals[i + n_columns]); printf( "\n"); } printf( "emrat = %.15f AU = %.5f\n", jpl_get_double( ephem, JPL_EPHEM_EARTH_MOON_RATIO), jpl_get_double( ephem, JPL_EPHEM_AU_IN_KM)); /****** Skip the test points file header comments. *************************/ if( test_file_name) strcpy( buff, test_file_name); else { const char *extension; strcpy( buff, ephfile_name); for( i = strlen( buff); i && buff[i - 1] != path_separator; i--) ; strcpy( buff + i, "testpo"); extension = strchr( ephfile_name + i, '.'); if( extension) strcat( buff + i, extension); else sprintf( buff + strlen( buff), ".%3ld", jpl_get_long( ephem, JPL_EPHEM_EPHEMERIS_VERSION)); } testfile = fopen( buff, "r"); if( !testfile) { printf( "Test data file '%s' not found\n", buff); error_exit( -3); } while( fgets( buff, 100, testfile) && memcmp( buff, "EOT", 3)) ; puts(" LINE JED t# c# x# --- JPL value --- " "--- user value -- -- difference --"); line=0; timer = clock( ); for( i = 0; i < 10; i++) n_failures[i] = 0; while( fgets( buff, 100, testfile) != NULL) { int err_code, ntarg, nctr, ncoord; double del, et; double r[6], xi, xi_computed; bool fatal_error = false, report_this_error = false; /***** Read a value from the test case; Skip if not within the time-range of the present version of the ephemeris. */ line++; if( sscanf( buff + 15," %lf %d %d %d %lf", &et, &ntarg, &nctr, &ncoord, &xi) != 5) { printf( "Failure to parse line %d:\n%s\n", line, buff); fatal_error = true; } else { err_code = jpl_pleph(ephem, et, ntarg, nctr, r, 1); if( err_code > 0 || err_code < -n_errors) { printf( "Internal error: unknown error code %d\n", err_code); fatal_error = true; } else if( !roundoff_error) { char *tptr = strchr( buff + 30, '.'); assert( tptr); tptr++; roundoff_error = .5; while( *tptr >= '0' && *tptr <= '9') { tptr++; roundoff_error /= 10.; } } } if( fatal_error) { printf( "\nThis error shouldn't happen, ever. It indicates a bug\n"); printf( "that should be fixed.\n"); printf( "Please contact [email protected] and report this.\n"); return( -1); } xi_computed = r[ncoord - 1]; del = fabs( xi_computed - xi); if( err_code) { n_failures[-err_code]++; if( n_failures[-err_code] == 1 || report_all_errors) report_this_error = true; } else { const double tolerance = max_accepted_error( ntarg, ncoord) + fabs( xi) * 1e-14 + roundoff_error; const unsigned idx = (ntarg <= 13 ? 0 : ntarg - 13); if( max_err_found[idx][ncoord - 1] < del - tolerance) max_err_found[idx][ncoord - 1] = del - tolerance; if( del > tolerance) { n_failures[0]++; if( n_failures[-err_code] == 1 || report_all_errors) { report_this_error = true; printf( "***** warning : next difference >= tolerance *****\n"); printf( "%s", buff); } } } if( (!err_code && !(line % output_frequency)) || report_this_error) printf("%4d %10.1f %2d %2d %2d %25.20f %25.20f %22.20f\n", line,et,ntarg,nctr,ncoord,xi, xi_computed, xi_computed - xi); if( report_this_error) { printf( "Error message: '%s'\n", error_messages[-err_code]); if( err_code == JPL_EPH_OUTSIDE_RANGE) { const double J2000 = 2451545.; printf( "WARNING: The test file tests items outside the range\n"); printf( "of this ephemeris!\n"); printf( "The input ephemeris file covers years from %.1f to %.1f.\n", 2000. + (start_jd - J2000) / 365.25, 2000. + (end_jd - J2000) / 365.25); printf( "The test is for the year %.1f\n", 2000. + (et - J2000) / 365.25); printf( "It's common for DE files to be built that cover a subset of the\n"); printf( "range of the original ephemerides, so this may not be an error.\n"); } if( !report_all_errors) { printf( " Further errors of this type won't be shown, but you'll get a count\n"); printf( " of how many are found. (Use the '-a' switch to report all errors.)\n"); } if( pause_on_errors) { printf( " Hit any key:\n"); getchar( ); } } } for( i = 0; i < 10; i++) for( j = 0; j < 6; j++) if( max_err_found[i][j]) printf( "%d %d %.8e %c\n", (int)i, (int)j + 1, max_err_found[i][j], (max_err_found[i][j] > 0.) ? '*' : ' '); printf( "%d lines read and tested in %.3f seconds\n", line, (double)( clock( ) - timer) / (double)CLOCKS_PER_SEC); for( i = 0; i < (size_t)n_errors; i++) if( n_failures[i]) printf( "%d lines failed with error code %d ('%s').\n", n_failures[i], -(int)i, error_messages[i]); fclose( testfile); jpl_close_ephemeris( ephem); return( 0); }