CppEphem
gal2icrs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * gal2icrs.cpp: CppEphem *
3  * ----------------------------------------------------------------------- *
4  * Copyright © 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 
26 #include <stdio.h>
27 #include <getopt.h>
28 #include <map>
29 #include <string>
30 #include <time.h>
31 
32 // CppEphem HEADERS
33 #include "CppEphem.h"
34 #include "CEExecOptions.h"
35 
36 /**********************************************************************/
40 {
41  CEExecOptions opts("gal2icrs");
42 
43  // Add version and description
44  opts.AddProgramDescription(std::string() +
45  "Converts from Galactic longitude,latitude coordinates to ICRS " +
46  "(solar system barycentric) coordinates");
47 
48  // Set the options
49  opts.AddGalacticPars();
50 
51  return opts;
52 }
53 
54 /**********************************************************************/
57 void PrintResults(const CESkyCoord& input,
58  const CESkyCoord& output)
59 {
60  // Get the representation of the input icrs in hours, minutes, seconds
61  std::vector<double> out_hms = output.XCoord().HmsVect();
62  std::vector<double> out_dms = output.YCoord().DmsVect();
63 
64  std::printf("\n");
65  std::printf("******************************************\n");
66  std::printf("* Results of Galactic -> ICRS conversion *\n");
67  std::printf("******************************************\n");
68  std::printf("ICRS Coordinates (output)\n");
69  std::printf(" Right Ascension: %02dh %02dm %04.1fs (%f deg)\n",
70  int(out_hms[0]), int(out_hms[1]), out_hms[2]+out_hms[3],
71  output.XCoord().Deg());
72  std::printf(" Declination : %+f degrees\n", input.YCoord().Deg());
73  std::printf("Galactic Coordinates (input)\n");
74  std::printf(" Galactic Lon.: %f degrees\n", input.XCoord().Deg());
75  std::printf(" Galactic Lat.: %+f degrees\n", input.YCoord().Deg());
76  std::printf("\n");
77 }
78 
79 /**********************************************************************/
82 int main(int argc, char** argv) {
83 
84  // Get the options from the command line
85  CEExecOptions opts = DefineOpts();
86  if (opts.ParseCommandLine(argc, argv)) return 0;
87 
88  // Create a map to store the results
89  CESkyCoord gal_coord(CEAngle::Deg(opts.AsDouble("glon")),
90  CEAngle::Deg(opts.AsDouble("glat")),
92 
93  // Convert the coordinates
94  CESkyCoord output = gal_coord.ConvertToICRS();
95 
96  // Print the results
97  PrintResults(gal_coord, output);
98 
99  return 0 ;
100 }
main
int main(int argc, char **argv)
Main method.
Definition: gal2icrs.cpp:81
CEAngle::DmsVect
std::vector< double > DmsVect(void) const
Return vector of doubles representing the {degrees, arcmin, arcsec, arcsec-fraction}.
Definition: CEAngle.cpp:291
CESkyCoord
Definition: CESkyCoord.h:49
CEExecOptions.h
CESkyCoordType::GALACTIC
Galacitc longitude, latitude.
CEAngle::HmsVect
std::vector< double > HmsVect(void) const
Return vector of doubles representing the {hours, min, sec, sec-fraction}.
Definition: CEAngle.cpp:199
PrintResults
void PrintResults(const CESkyCoord &input, const CESkyCoord &output)
Print the results of the analysis.
Definition: gal2icrs.cpp:56
CppEphem.h
CEAngle::Deg
double Deg(void) const
Return angle in degrees as a double.
Definition: CEAngle.cpp:328
DefineOpts
CEExecOptions DefineOpts()
Define the command line options for this program.
Definition: gal2icrs.cpp:38
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::ConvertToICRS
CESkyCoord ConvertToICRS(const CEDate &date=CEDate(), const CEObserver &observer=CEObserver())
Convert this coordinate to ICRS coordinates.
Definition: CESkyCoord.cpp:854
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