48 #include <curl/curl.h>
178 if (
this != &other) {
326 const std::string& url)
const
329 std::ifstream corrections_file(filename, std::ios::in);
332 if (!corrections_file.is_open()) {
335 corrections_file.close();
339 throw CEException::exception();
343 corrections_file.open(filename, std::ios::in);
346 if (!corrections_file.is_open()) {
347 std::string msg =
"Unable to load corrections file: " + filename;
352 return corrections_file;
362 const std::string& url)
const
370 curl = curl_easy_init();
373 fp = fopen(filename.c_str(),
"wb");
374 curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
375 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
376 curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
377 res = curl_easy_perform(curl);
378 curl_easy_cleanup(curl);
384 catch (std::exception& e) {
385 std::cerr <<
"ERROR trying to download corrections files: "
386 << e.what() << std::endl;
390 std::cout <<
"CppEphem was not compiled with curl support. To download "
391 <<
"the corrections file automatically, recompile with -DNOCURL=0."
410 std::string url =
"http://maia.usno.navy.mil/ser7/finals2000A.all";
433 while(std::getline(corrections_file, line)) {
434 mjd = std::stoi(line.substr(7,8));
438 dut1 = std::stod(line.substr(154,11));
439 xp = std::stod(line.substr(134,10));
440 yp = std::stod(line.substr(144,10));
441 deps = std::stod(line.substr(175,10));
442 dpsi = std::stod(line.substr(165,10));
445 catch (std::exception& e) {
447 dut1 = std::stod(line.substr(58,10));
448 xp = std::stod(line.substr(18, 9));
449 yp = std::stod(line.substr(37, 9));
450 deps = std::stod(line.substr(116,9));
451 dpsi = std::stod(line.substr(97,9));
453 catch (std::exception& e) {
470 corrections_file.close();
480 }
catch (std::exception& e) {
481 std::cerr <<
"ERROR Unable to load corrections from file" << std::endl;
482 std::cerr << e.what() << std::endl;
502 std::string url =
"http://maia.usno.navy.mil/ser7/deltat.data";
514 while(std::getline(corrections_file, line)) {
517 std::vector<double> greg_vect(4, 0.0);
518 greg_vect[0] = std::stod(line.substr(1,4));
519 greg_vect[1] = std::stod(line.substr(6,2));
520 greg_vect[2] = std::stod(line.substr(9,2));
525 delt = std::stod(line.substr(13,7));
528 catch (std::exception& e) {
539 corrections_file.close();
542 url =
"http://maia.usno.navy.mil/ser7/deltat.preds";
546 std::getline(corrections_file, line);
547 while(std::getline(corrections_file, line)) {
550 mjd = std::stoi(line.substr(3,9));
558 delt = std::stod(line.substr(24,5));
561 catch (std::exception& e) {
576 }
catch (std::exception& e) {
577 std::cerr <<
"ERROR Unable to load corrections from file" << std::endl;
578 std::cerr << e.what() << std::endl;
607 std::string msg =
"Invalid mjd: " + std::to_string(mjd) +
". Accepted " +
608 "range is " + min_mjd +
" - " + max_mjd;
667 if ((indx < 0) || (indx >=
ttut1_mjd_.size()-1)) {
669 std::string min_mjd(std::to_string(
ttut1_mjd_.front()));
670 std::string max_mjd(std::to_string(
ttut1_mjd_.back()));
671 std::string msg =
"Invalid mjd: " + std::to_string(mjd) +
". Accepted " +
672 "range is " + min_mjd +
" - " + max_mjd;
709 const double& x0,
const double& x1,
710 const double& y0,
const double& y1)
const
712 return (y0*(x1 - x) + y1*(x - x0)) / (x1-x0);