CppEphem
angsep.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * angsep.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 
24 #include "CEExecOptions.h"
25 #include "CESkyCoord.h"
26 
27 /*********************************************
28  * Forward declarations
29  *********************************************/
30 
32 CESkyCoord ConstructCoords(const double& x, const double& y, bool isDeg);
33 
34 /*********************************************
35  * MAIN
36  *********************************************/
37 int main(int argc, char** argv)
38 {
39  // Create and parse the command line options
40  CEExecOptions opts = DefineOpts();
41  if (opts.ParseCommandLine(argc,argv)) return 0;
42 
43  // Establish the input coordinate type
44  CEAngleType in_ang_type = CEAngleType::DEGREES;
45 
46  if (!opts.AsBool("InputDegrees")) {
47  in_ang_type = CEAngleType::RADIANS;
48  }
49 
50  // Find coordinates for the first object
51  CESkyCoord coord1 = ConstructCoords(opts.AsDouble("xcoord1"),
52  opts.AsDouble("ycoord1"),
53  opts.AsBool("InputDegrees"));
54  CESkyCoord coord2 = ConstructCoords(opts.AsDouble("xcoord2"),
55  opts.AsDouble("ycoord2"),
56  opts.AsBool("InputDegrees"));
57 
58  CEAngle angsep = CESkyCoord::AngularSeparation(coord1, coord2);
59 
60  // Figure out whether we need to convert the output angular separation
61  if (opts.AsBool("OutputDegrees")) {
62  std::cout << angsep.Deg() << std::endl;
63  } else {
64  std::cout << angsep.Rad() << std::endl;
65  }
66 
67  return 0;
68 }
69 
70 /*********************************************
71  * Define the options available from the command line
72  *********************************************/
74 {
75  CEExecOptions opts("angsep");
76 
77  // Add program description
78  opts.AddProgramDescription(std::string() +
79  "Computes the angular separation between two coordinates. Note that " +
80  "the coordinate types need to be the same for both positions.");
81 
82  // Specify the actual options
83  opts.AddBoolParam("InputDegrees",
84  "Specifies whether input angles are in degrees (1) or radians (0)",
85  true);
86  opts.AddBoolParam("OutputDegrees",
87  "Specifies whether to output the angular separation in degrees (1) or radians (0)",
88  true);
89  opts.AddDoubleParam("xcoord1",
90  "X-coordinate for first position. Should be either 'right ascension' or 'galactic longitude'",
91  0.0);
92  opts.AddDoubleParam("ycoord1",
93  "Y-coordinate for first position. Should be either 'declination' or 'galactic latitude'",
94  0.0);
95  opts.AddDoubleParam("xcoord2",
96  "X-coordinate for second position. Should be either 'right ascension' or 'galactic longitude'",
97  0.0);
98  opts.AddDoubleParam("ycoord2",
99  "Y-coordinate for second position. Should be either 'declination' or 'galactic latitude'",
100  0.0);
101 
102  return opts;
103 }
104 
105 
106 /*****************************************/
114 CESkyCoord ConstructCoords(const double& x, const double& y, bool isDeg)
115 {
116  CESkyCoord coord;
117  if (isDeg) {
120  } else {
123  }
124 
125  return coord;
126 }
CESkyCoordType::ICRS
RA, Dec (referenced at the barycenter of the solarsystem)
ConstructCoords
CESkyCoord ConstructCoords(const double &x, const double &y, bool isDeg)
Construct the coordinates object.
Definition: angsep.cpp:110
CESkyCoord
Definition: CESkyCoord.h:49
CEExecOptions.h
CEAngleType
CEAngleType
Definition: CEAngle.h:30
CESkyCoord::AngularSeparation
virtual CEAngle AngularSeparation(const CESkyCoord &coords) const
Get the angular separation between the coordinates represented by this object and another coordinate ...
Definition: CESkyCoord.cpp:119
main
int main(int argc, char **argv)
Definition: angsep.cpp:34
CEAngle
Definition: CEAngle.h:38
CEAngle::Rad
double Rad(void) const
Return angle in radians as a double.
Definition: CEAngle.cpp:351
CEAngleType::DEGREES
DefineOpts
CEExecOptions DefineOpts()
Set the command line options.
Definition: angsep.cpp:69
CEAngleType::RADIANS
CEAngle::Deg
double Deg(void) const
Return angle in degrees as a double.
Definition: CEAngle.cpp:328
CESkyCoord::SetCoordinates
virtual void SetCoordinates(const CEAngle &xcoord, const CEAngle &ycoord, const CESkyCoordType &coord_type=CESkyCoordType::ICRS) const
Set the coordinates of this object.
Definition: CESkyCoord.cpp:1000
CESkyCoord.h
CEExecOptions
Definition: CEExecOptions.h:9