CppEphem
icrs2gal.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * icrs2gal.cpp: CppEphem *
3  * ----------------------------------------------------------------------- *
4  * Copyright © 2017-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("icrs2gal");
38 
39  // Add version and description
40  opts.AddProgramDescription(std::string() +
41  "Converts from ICRS (solar system barycentric) coordinates to " +
42  "Galactic coordinates.");
43 
44  // Set the options
45  opts.AddIcrsPars();
46 
47  return opts;
48 }
49 
50 /**********************************************************************/
53 void PrintResults(const CESkyCoord& input,
54  const CESkyCoord& output)
55 {
56  // Get the representation of the input icrs in hours, minutes, seconds
57  std::vector<double> input_hms = input.XCoord().HmsVect();
58 
59  std::printf("\n") ;
60  std::printf("******************************************\n") ;
61  std::printf("* Results of ICRS -> Galactic conversion *\n") ;
62  std::printf("******************************************\n") ;
63  std::printf("Galactic Coordinates (output)\n") ;
64  std::printf(" Galactic Lon.: %f degrees\n", output.XCoord().Deg()) ;
65  std::printf(" Galactic Lat.: %+f degrees\n", output.YCoord().Deg()) ;
66  std::printf("ICRS Coordinates (input)\n") ;
67  std::printf(" Right Ascension: %02dh %02dm %04.1fs (%f deg)\n",
68  int(input_hms[0]), int(input_hms[1]), input_hms[2],
69  input.XCoord().Deg()) ;
70  std::printf(" Declination : %+f degrees\n", input.YCoord().Deg()) ;
71  std::printf("\n") ;
72 }
73 
74 /**********************************************************************/
77 int main(int argc, char** argv)
78 {
79  // Get the options from the command line
80  CEExecOptions opts = DefineOpts();
81  if (opts.ParseCommandLine(argc, argv)) return 0;
82 
83  // Create a map to store the results
84  CESkyCoord icrs_coords(CEAngle::Deg(opts.AsDouble("ra")),
85  CEAngle::Deg(opts.AsDouble("dec")),
87 
88  // Convert the coordinates
89  CESkyCoord gal_coords = icrs_coords.ConvertToGalactic();
90 
91  // Print the results
92  PrintResults(icrs_coords, gal_coords);
93 
94  return 0 ;
95 }
CESkyCoordType::ICRS
RA, Dec (referenced at the barycenter of the solarsystem)
CESkyCoord
Definition: CESkyCoord.h:49
CEExecOptions.h
CEAngle::HmsVect
std::vector< double > HmsVect(void) const
Return vector of doubles representing the {hours, min, sec, sec-fraction}.
Definition: CEAngle.cpp:199
CppEphem.h
DefineOpts
CEExecOptions DefineOpts()
Define the command line options for this program.
Definition: icrs2gal.cpp:34
main
int main(int argc, char **argv)
Main method.
Definition: icrs2gal.cpp:76
CESkyCoord::ConvertToGalactic
CESkyCoord ConvertToGalactic(const CEDate &date=CEDate(), const CEObserver &observer=CEObserver())
Convert this coordinate to GALACTIC coordinates.
Definition: CESkyCoord.cpp:891
PrintResults
void PrintResults(const CESkyCoord &input, const CESkyCoord &output)
Print the results of the analysis.
Definition: icrs2gal.cpp:52
CEAngle::Deg
double Deg(void) const
Return angle in degrees as a double.
Definition: CEAngle.cpp:328
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