CppEphem
cal2jd.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * cal2jd.cpp: CppEphem *
3  * ----------------------------------------------------------------------- *
4  * Copyright © 2016-2019 JCardenzana *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 
22 #include <iostream>
23 #include <cmath>
24 #include "CppEphem.h"
25 
26 int main(int argc, const char * argv[]) {
27 
28  // variable to hold the julian date
29  double jd(0.0) ;
30 
31  // Check that we've been passed an actual argument
32  if ((argc != 2)&&(argc != 4)) {
33  // Print some usage information
34  std::cout << "cal2jd v" << CPPEPHEM_VERSION << "\n";
35  std::cout << "\nUSAGE: May be called in one of two ways:\n";
36  std::cout << " 1: cal2jd YYYYMMDD.<day fraction>\n" ;
37  std::cout << " 2: cal2jd <year> <month> <day>.<day fraction>\n" ;
38  std::cout << "RETURNED: Julian Date\n\n" ;
39  return 0 ;
40  } else if (argc == 2) {
41  jd = CEDate::Gregorian2JD(std::stod(argv[1])) ;
42  } else if (argc == 4) {
43  // First get the year, month, day information from the pass parameters
44  double year(std::stod(argv[1]));
45  double month(std::stod(argv[2]));
46  double day(std::stod(argv[3]));
47  std::vector<double> gregorian_vect = {year, month, std::floor(day), 0.0} ;
48  gregorian_vect[3] = day - gregorian_vect[2] ;
49 
50  // Now compute the julian date
51  jd = CEDate::GregorianVect2JD(gregorian_vect) ;
52  }
53 
54  // Print the result
55  std::printf("%f\n", jd) ;
56 
57  return 0 ;
58 }
CEDate::Gregorian2JD
static double Gregorian2JD(double gregorian)
Gregorian calendar date -> Julian date.
Definition: CEDate.cpp:287
CppEphem.h
CEDate::GregorianVect2JD
static double GregorianVect2JD(std::vector< double > gregorian)
Gregorian calendar vector formatted date -> Julian date converter.
Definition: CEDate.cpp:307
main
int main(int argc, const char *argv[])
Definition: cal2jd.cpp:25