CppEphem
gal2cirs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * gal2cirs.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 <stdio.h>
23 #include <getopt.h>
24 #include <map>
25 #include <string>
26 #include <time.h>
27 
28 // CppEphem HEADERS
29 #include "CppEphem.h"
30 #include "CEExecOptions.h"
31 
32 /**********************************************************************/
36 {
37  CEExecOptions opts("gal2cirs");
38 
39  // Add a program version and description
40  opts.AddProgramDescription(std::string() +
41  "Converts from Galactic coordinates to CIRS (Earth centric) " +
42  "coordinates for a given Julian date.");
43 
44  // Set the options
45  opts.AddGalacticPars();
46  opts.AddJDPar();
47 
48  return opts;
49 }
50 
51 
52 /**********************************************************************/
54 void PrintResults(CEExecOptions& inputs,
55  const CESkyCoord& results)
56 {
57  std::printf("\n") ;
58  std::printf("******************************************\n") ;
59  std::printf("* Results of Galactic -> CIRS conversion *\n") ;
60  std::printf("******************************************\n") ;
61  std::printf("CIRS Coordinates (output)\n") ;
62  std::printf(" Right Ascension: %f degrees\n", results.XCoord().Deg());
63  std::printf(" Declination : %+f degrees\n", results.YCoord().Deg());
64  std::printf("Galactic Coordinates (input)\n");
65  std::printf(" Galactic Lon. : %f degrees\n", inputs.AsDouble("glon"));
66  std::printf(" Galactic Lat. : %+f degrees\n", inputs.AsDouble("glat"));
67  std::printf(" Julian Date : %f\n", inputs.AsDouble("juliandate"));
68  std::printf("\n");
69 }
70 
71 /**********************************************************************/
73 int main(int argc, char** argv)
74 {
75  // Get the options from the command line
76  CEExecOptions opts = DefineOpts() ;
77  if (opts.ParseCommandLine(argc, argv)) return 0 ;
78 
79  // Convert the coordinates
80  CEDate date(opts.AsDouble("juliandate"), CEDateType::JD);
81  CESkyCoord gal_coord(CEAngle::Deg(opts.AsDouble("glon")),
82  CEAngle::Deg(opts.AsDouble("glat")),
84  CESkyCoord cirs_coord = gal_coord.ConvertToCIRS(date);
85 
86  // Print the results
87  PrintResults(opts, cirs_coord) ;
88 
89  return 0 ;
90 }
CESkyCoord::ConvertToCIRS
CESkyCoord ConvertToCIRS(const CEDate &date=CEDate(), const CEObserver &observer=CEObserver())
Convert this coordinate to CIRS coordinates.
Definition: CESkyCoord.cpp:817
CEDate
Definition: CEDate.h:43
CESkyCoord
Definition: CESkyCoord.h:49
CEExecOptions.h
CESkyCoordType::GALACTIC
Galacitc longitude, latitude.
CppEphem.h
JD
Julian Date.
Definition: CEDate.h:56
main
int main(int argc, char **argv)
Definition: gal2cirs.cpp:72
DefineOpts
CEExecOptions DefineOpts()
Define the command line options for this program.
Definition: gal2cirs.cpp:34
CEAngle::Deg
double Deg(void) const
Return angle in degrees as a double.
Definition: CEAngle.cpp:328
PrintResults
void PrintResults(CEExecOptions &inputs, const CESkyCoord &results)
Definition: gal2cirs.cpp:53
CEAngle::Deg
static CEAngle Deg(const double &angle)
Return angle (radians) constructed from a degree angle.
Definition: CEAngle.cpp:317
CEExecOptions
Definition: CEExecOptions.h:9
CESkyCoord::XCoord
virtual CEAngle XCoord(const CEDate &jd=CppEphem::julian_date_J2000()) const
Return x coordinate at given Julian date.
Definition: CESkyCoord.h:227
CESkyCoord::YCoord
virtual CEAngle YCoord(const CEDate &jd=CppEphem::julian_date_J2000()) const
Return y coordinate at given Julian date.
Definition: CESkyCoord.h:240