CppEphem
gal2obs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * gal2obs.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("gal2obs");
38 
39  // Add a program version and description
40  opts.AddProgramDescription(std::string() +
41  "Converts from Galactic coordinates to observed altitude and zenith " +
42  "coordinates for a given Julian date. Additional observing conditions " +
43  "an also be specified to allow more accurate coordinate values.");
44 
45  // Set the options
46  opts.AddGalacticPars();
47  opts.AddObserverPars();
48  opts.AddJDPar();
49 
50  return opts;
51 }
52 
53 
54 /**********************************************************************/
56 void PrintResults(CEExecOptions& inputs,
57  const CESkyCoord& obs_coords,
58  const CESkyCoord& obs_gal_coords)
59 {
60  std::printf("\n");
61  std::printf("**********************************************\n");
62  std::printf("* Results of GALACTIC -> Observed conversion *\n");
63  std::printf("**********************************************\n");
64  std::printf("Observed Coordinates (output)\n");
65  std::printf(" Azimuth : %f degrees\n", obs_coords.XCoord().Deg());
66  std::printf(" Zenith : %+f degrees\n", obs_coords.YCoord().Deg());
67  std::printf(" Altitude : %+f degrees\n", 90.0-obs_coords.YCoord().Deg());
68  std::printf("Galactic Coordinates (input)\n");
69  std::printf(" Gal. Longitude : %f degrees\n", inputs.AsDouble("glon"));
70  std::printf(" Gal. Latitude : %+f degrees\n", inputs.AsDouble("glat"));
71  std::printf(" Julian Date : %f\n", inputs.AsDouble("juliandate"));
72  std::printf("Apparent Galactic Coordinates\n");
73  std::printf(" Gal. Longitude : %f\n", obs_gal_coords.XCoord().Deg());
74  std::printf(" Gal. Latitude : %+f\n", obs_gal_coords.YCoord().Deg());
75  std::printf("Observer Info\n");
76  std::printf(" Longitude : %f deg\n", inputs.AsDouble("longitude"));
77  std::printf(" Latitude : %+f deg\n", inputs.AsDouble("latitude"));
78  std::printf(" Elevation : %f meters\n", inputs.AsDouble("elevation"));
79  std::printf(" Pressure : %f hPa\n", inputs.AsDouble("pressure"));
80  std::printf(" Temperature : %f Celsius\n", inputs.AsDouble("temperature"));
81  std::printf(" Relative Humid.: %f\n", inputs.AsDouble("humidity"));
82  std::printf("\n") ;
83 }
84 
85 /**********************************************************************/
87 int main(int argc, char** argv)
88 {
89  // Get the options from the command line
90  CEExecOptions opts = DefineOpts() ;
91  if (opts.ParseCommandLine(argc, argv)) return 0 ;
92 
93  // Create a date
94  CEDate date(opts.AsDouble("juliandate"), CEDateType::JD);
95 
96  // Create the observer
97  CEObserver obs(opts.AsDouble("longitude")*DD2R,
98  opts.AsDouble("latitude")*DD2R,
99  opts.AsDouble("elevation"),
101  obs.SetRelativeHumidity(opts.AsDouble("humidity"));
102  obs.SetPressure_hPa(opts.AsDouble("pressure"));
103  obs.SetWavelength_um(opts.AsDouble("wavelength"));
104 
105  // Convert the coordinates
106  CESkyCoord gal_coords(CEAngle::Deg(opts.AsDouble("glon")),
107  CEAngle::Deg(opts.AsDouble("glat")),
109  CESkyCoord obs_gal_coords;
110  CESkyCoord obs_coords;
111  CESkyCoord::Galactic2Observed(gal_coords, &obs_coords,
112  date, obs, &obs_gal_coords);
113 
114  // Print the results
115  PrintResults(opts, obs_coords, obs_gal_coords);
116 
117  return 0;
118 }
main
int main(int argc, char **argv)
Definition: gal2obs.cpp:86
CEDate
Definition: CEDate.h:43
CESkyCoord::Galactic2Observed
static void Galactic2Observed(const CESkyCoord &in_galactic, CESkyCoord *out_observed, const CEDate &date, const CEObserver &observer, CESkyCoord *observed_galactic=nullptr, CEAngle *hour_angle=nullptr)
GALACTIC -> OBSERVED coordinate conversion.
Definition: CESkyCoord.cpp:520
CESkyCoord
Definition: CESkyCoord.h:49
CEExecOptions.h
CESkyCoordType::GALACTIC
Galacitc longitude, latitude.
CEObserver::SetRelativeHumidity
void SetRelativeHumidity(const double &humidity=0.0)
Set the observer's relative humidity.
Definition: CEObserver.h:349
CppEphem.h
CEAngleType::DEGREES
JD
Julian Date.
Definition: CEDate.h:56
CEObserver
Definition: CEObserver.h:28
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: gal2obs.cpp:34
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
PrintResults
void PrintResults(CEExecOptions &inputs, const CESkyCoord &obs_coords, const CESkyCoord &obs_gal_coords)
Definition: gal2obs.cpp:55