CppEphem
cirs2gal.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * cirs2gal.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("cirs2gal");
38 
39  // Add a program version and description
40  opts.AddProgramDescription(std::string() +
41  "Converts from CIRS coordinates to Galactic coordinates for a given " +
42  "Julian date.");
43 
44  // Set the options
45  opts.AddCirsPars();
46  opts.AddJDPar();
47 
48  return opts;
49 }
50 
51 
52 /**********************************************************************/
54 void PrintResults(CEExecOptions& opts,
55  const CESkyCoord& results)
56 {
57  std::printf("\n") ;
58  std::printf("******************************************\n") ;
59  std::printf("* Results of CIRS -> Galactic conversion *\n") ;
60  std::printf("******************************************\n") ;
61  std::printf("Galactic Coordinates (output)\n") ;
62  std::printf(" Galactic Lon.: %f degrees\n", results.XCoord().Deg()) ;
63  std::printf(" Galactic Lat.: %+f degrees\n", results.YCoord().Deg()) ;
64  std::printf("CIRS Coordinates (input)\n") ;
65  std::printf(" Right Ascension: %f degrees\n", opts.AsDouble("ra")) ;
66  std::printf(" Declination : %+f degrees\n", opts.AsDouble("dec")) ;
67  std::printf(" Julian Date : %f\n", opts.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 cirs_coord(CEAngle::Deg(opts.AsDouble("ra")),
82  CEAngle::Deg(opts.AsDouble("dec")),
84  CESkyCoord gal_coord = cirs_coord.ConvertToGalactic(date);
85 
86  // Print the results
87  PrintResults(opts, gal_coord);
88 
89  return 0 ;
90 }
CESkyCoordType::CIRS
RA, Dec (referenced at the center of the Earth)
CEDate
Definition: CEDate.h:43
CESkyCoord
Definition: CESkyCoord.h:49
CEExecOptions.h
DefineOpts
CEExecOptions DefineOpts()
Define the command line options for this program.
Definition: cirs2gal.cpp:34
CppEphem.h
JD
Julian Date.
Definition: CEDate.h:56
CESkyCoord::ConvertToGalactic
CESkyCoord ConvertToGalactic(const CEDate &date=CEDate(), const CEObserver &observer=CEObserver())
Convert this coordinate to GALACTIC coordinates.
Definition: CESkyCoord.cpp:891
CEAngle::Deg
double Deg(void) const
Return angle in degrees as a double.
Definition: CEAngle.cpp:328
main
int main(int argc, char **argv)
Definition: cirs2gal.cpp:72
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
PrintResults
void PrintResults(CEExecOptions &opts, const CESkyCoord &results)
Definition: cirs2gal.cpp:53
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