CppEphem
cirs2obs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * cirs2obs.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 
33 /**********************************************************************/
37 {
38  CEExecOptions opts("cirs2obs");
39 
40  // Add a program version and description
41  opts.AddProgramDescription(std::string() +
42  "Converts from CIRS coordinates to observed altitude and zenith " +
43  "coordinates for a given Julian date. Additional observing conditions " +
44  "an also be specified to allow more accurate coordinate values.");
45 
46  // Set the options
47  opts.AddCirsPars();
48  opts.AddObserverPars();
49  opts.AddJDPar();
50 
51  return opts;
52 }
53 
54 
55 /**********************************************************************/
57 void PrintResults(CEExecOptions& inputs,
58  const CESkyCoord& obs_coords,
59  const CESkyCoord& obs_cirs_coords,
60  const CEAngle& hour_angle)
61 {
62  std::printf("\n") ;
63  std::printf("******************************************\n");
64  std::printf("* Results of CIRS -> Observed conversion *\n");
65  std::printf("******************************************\n");
66  std::printf("Observed Coordinates (output)\n");
67  std::printf(" Azimuth : %f degrees\n", obs_coords.XCoord().Deg());
68  std::printf(" Zenith : %+f degrees\n", obs_coords.YCoord().Deg());
69  std::printf(" Altitude : %+f degrees\n", 90.0-obs_coords.YCoord().Deg());
70  std::printf("CIRS Coordinates (input)\n");
71  std::printf(" Right Ascension: %f degrees\n", inputs.AsDouble("ra"));
72  std::printf(" Declination : %+f degrees\n", inputs.AsDouble("dec"));
73  std::printf(" Julian Date : %f\n", inputs.AsDouble("juliandate"));
74  std::printf("Apparent CIRS Coordinates\n");
75  std::printf(" Right Ascension: %f\n", obs_cirs_coords.XCoord().Deg());
76  std::printf(" Declination : %+f\n", obs_cirs_coords.YCoord().Deg());
77  std::printf(" Hour Angle : %+f\n", hour_angle.Deg());
78  std::printf("Observer Info\n");
79  std::printf(" Longitude : %f deg\n", inputs.AsDouble("longitude"));
80  std::printf(" Latitude : %+f deg\n", inputs.AsDouble("latitude"));
81  std::printf(" Elevation : %f meters\n", inputs.AsDouble("elevation"));
82  std::printf(" Pressure : %f hPa\n", inputs.AsDouble("pressure"));
83  std::printf(" Temperature : %f Celsius\n", inputs.AsDouble("temperature"));
84  std::printf(" Relative Humid.: %f\n", inputs.AsDouble("humidity"));
85  std::printf("\n");
86 }
87 
88 /**********************************************************************/
90 int main(int argc, char** argv) {
91 
92  // Get the options from the command line
93  CEExecOptions opts = DefineOpts();
94  if (opts.ParseCommandLine(argc, argv)) return 0;
95 
96  // Create a map to store the results
97  std::map<std::string, double> results;
98  results["azimuth"] = 0.0;
99  results["zenith"] = 0.0;
100  results["observed_ra"] = 0.0;
101  results["observed_dec"] = 0.0;
102  results["hour_angle"] = 0.0;
103 
104  // Create a date
105  CEDate date(opts.AsDouble("juliandate"), CEDateType::JD);
106 
107  // Create the observer
108  CEObserver obs(opts.AsDouble("longitude"),
109  opts.AsDouble("latitude"),
110  opts.AsDouble("elevation"),
112  obs.SetRelativeHumidity(opts.AsDouble("humidity"));
113  obs.SetPressure_hPa(opts.AsDouble("pressure"));
114  obs.SetWavelength_um(opts.AsDouble("wavelength"));
115 
116  // Convert the coordinates
117  CESkyCoord cirs_coord(CEAngle::Deg(opts.AsDouble("ra")),
118  CEAngle::Deg(opts.AsDouble("dec")),
120  CESkyCoord obs_coord;
121  CESkyCoord obs_cirs_coord;
122  CEAngle hour_angle;
123  CESkyCoord::CIRS2Observed(cirs_coord, &obs_coord, date, obs,
124  &obs_cirs_coord, &hour_angle);
125 
126  // Print the results
127  PrintResults(opts, obs_coord, obs_cirs_coord, hour_angle);
128 
129  return 0;
130 }
PrintResults
void PrintResults(CEExecOptions &inputs, const CESkyCoord &obs_coords, const CESkyCoord &obs_cirs_coords, const CEAngle &hour_angle)
Definition: cirs2obs.cpp:56
CESkyCoordType::CIRS
RA, Dec (referenced at the center of the Earth)
CEDate
Definition: CEDate.h:43
CESkyCoord
Definition: CESkyCoord.h:49
CEExecOptions.h
CESkyCoord::CIRS2Observed
static void CIRS2Observed(const CESkyCoord &in_cirs, CESkyCoord *out_observed, const CEDate &date, const CEObserver &observer, CESkyCoord *observed_cirs=nullptr, CEAngle *hour_angle=nullptr)
CIRS -> Observed (or observer specific) coordinate conversion.
Definition: CESkyCoord.cpp:258
CEObserver::SetRelativeHumidity
void SetRelativeHumidity(const double &humidity=0.0)
Set the observer's relative humidity.
Definition: CEObserver.h:349
DefineOpts
CEExecOptions DefineOpts()
Define the command line options for this program.
Definition: cirs2obs.cpp:35
CppEphem.h
CEAngle
Definition: CEAngle.h:38
CEAngleType::DEGREES
JD
Julian Date.
Definition: CEDate.h:56
main
int main(int argc, char **argv)
Definition: cirs2obs.cpp:89
CEObserver
Definition: CEObserver.h:28
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