CppEphem
cal2mjd.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * cal2mjd.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 mjd(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 << "cal2mjd v" << CPPEPHEM_VERSION << "\n";
35  std::cout << "\nUSAGE: May be called in one of two ways:\n";
36  std::cout << " 1: cal2mjd YYYYMMDD.<day fraction>\n" ;
37  std::cout << " 2: cal2mjd <year> <month> <day>.<day fraction>\n" ;
38  std::cout << "RETURNED: Modified Julian Date\n\n" ;
39  return 0 ;
40  } else if (argc == 2) {
41  mjd = CEDate::Gregorian2MJD(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])), month(std::stod(argv[2])), day(std::stod(argv[3])) ;
45  std::vector<double> gregorian_vect = {year, month, std::floor(day), 0.0} ;
46  gregorian_vect[3] = day - gregorian_vect[2] ;
47 
48  // Now compute the julian date
49  mjd = CEDate::GregorianVect2MJD(gregorian_vect) ;
50  }
51 
52  // Print the result
53  std::printf("%f\n", mjd) ;
54 
55  return 0 ;
56 }
CppEphem.h
CEDate::Gregorian2MJD
static double Gregorian2MJD(double gregorian)
Gregorian calendar formatted date -> Julian date converter.
Definition: CEDate.cpp:343
main
int main(int argc, const char *argv[])
Definition: cal2mjd.cpp:25
CEDate::GregorianVect2MJD
static double GregorianVect2MJD(std::vector< double > gregorian)
Gregorian calendar vector formatted date -> Modified Julian date converter.
Definition: CEDate.cpp:362