CppEphem
mjd2cal.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * mjd2cal.cpp: CppEphem *
3  * ----------------------------------------------------------------------- *
4  * Copyright © 2016 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 "CppEphem.h"
24 
25 /**********************************************************************/
27 int main(int argc, const char * argv[]) {
28  // Set the default return type ID
29  int return_format(0) ;
30 
31  // Check that we've been passed an actual argument
32  if (argc < 2) {
33  // Print some usage information
34  std::cout << "mjd2cal v" << CPPEPHEM_VERSION << "\n";
35  std::cout << "\nUSAGE: mjd2cal <modified julian date> <return format ID>\n" ;
36  std::cout << "RETURNED: Gregorian calendar date in two formats:\n" ;
37  std::cout << " (default) ID=0: YYYYMMDD.<date fraction>\n" ;
38  std::cout << " ID=1: YYYY MM DD.<day fraction>" ;
39  std::cout << "\n\n" ;
40  return 0 ;
41  } else if (argc == 3) {
42  // Get the return format from the command line
43  return_format = std::stoi(argv[2]) ;
44  }
45 
46  // Convert the input variable to a double
47  double mjd = std::stod(std::string(argv[1])) ;
48 
49  if (return_format == 1) {
50  std::vector<double> gregorian_vect = CEDate::MJD2GregorianVect(mjd) ;
51  std::printf("%4.0f %02.0f %06.4f\n",
52  gregorian_vect[0], gregorian_vect[1], gregorian_vect[2]+gregorian_vect[3]) ;
53  } else {
54  std::printf("%f\n", CEDate::MJD2Gregorian(mjd)) ;
55  }
56 
57  return 0 ;
58 }
main
int main(int argc, const char *argv[])
Definition: mjd2cal.cpp:26
CppEphem.h
CEDate::MJD2GregorianVect
static std::vector< double > MJD2GregorianVect(double mjd)
Modified Julian date -> Gregorian calendar, vector formatted date.
Definition: CEDate.cpp:272
CEDate::MJD2Gregorian
static double MJD2Gregorian(double mjd)
Modified Julian date -> Gregorian calendar date conversion method.
Definition: CEDate.cpp:253