CppEphem
obs2gal.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * obs2gal.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 #include <getopt.h>
24 #include <map>
25 #include <string>
26 #include <time.h>
27 //#include <vector>
28 
29 // CppEphem HEADERS
30 #include "CppEphem.h"
31 #include "CEExecOptions.h"
32 
33 /**********************************************************************/
36 {
37  CEExecOptions opts("obs2gal");
38 
39  // Add a program version and description
40  opts.AddProgramDescription(std::string() +
41  "Takes observed positions (azimuth,zenith angle) and computes the " +
42  "Galactic longitude,latitude positions based on the observer location " +
43  "and atmospheric properties. The only values necessary to get rough " +
44  "coordinates are 'longitude', 'latitude', 'azimuth', 'zenith', and " +
45  "'juliandate'.") ;
46 
47  // Setup the defaults
48  opts.AddObserverPars();
49  opts.AddObservedPars();
50  opts.AddJDPar();
51 
52  return opts ;
53 }
54 
55 /**********************************************************************/
57 void PrintResults(CEExecOptions& inputs,
58  const CESkyCoord& results)
59 {
60  std::printf("\n") ;
61  std::printf("**********************************************\n") ;
62  std::printf("* Results of Observed -> Galactic conversion *\n") ;
63  std::printf("**********************************************\n") ;
64  std::printf("Observed Coordinates (input)\n") ;
65  std::printf(" Azimuth : %f degrees\n", inputs.AsDouble("azimuth")) ;
66  std::printf(" Zenith : %+f degrees\n", inputs.AsDouble("zenith")) ;
67  std::printf(" Altitude : %+f degrees\n", 90.0-inputs.AsDouble("zenith")) ;
68  std::printf("Galactic Coordinates (output)\n") ;
69  std::printf(" G. Longitude : %f degrees\n", results.XCoord().Deg()) ;
70  std::printf(" G. Latitude : %+f degrees\n", results.YCoord().Deg()) ;
71  std::printf("Observer Info\n") ;
72  std::printf(" Julian Date : %f\n", inputs.AsDouble("juliandate")) ;
73  std::printf(" Longitude : %f deg\n", inputs.AsDouble("longitude")) ;
74  std::printf(" Latitude : %+f deg\n", inputs.AsDouble("latitude")) ;
75  std::printf(" Elevation : %f meters\n", inputs.AsDouble("elevation")) ;
76  std::printf(" Pressure : %f hPa\n", inputs.AsDouble("pressure")) ;
77  std::printf(" Temperature : %f Celsius\n", inputs.AsDouble("temperature")) ;
78  std::printf(" Relative Humid.: %f\n", inputs.AsDouble("humidity")) ;
79  std::printf("\n") ;
80 }
81 
82 /**********************************************************************/
84 int main(int argc, char** argv) {
85 
86  // Parse the command line options
87  CEExecOptions opts = DefineOpts() ;
88  if (opts.ParseCommandLine(argc, argv)) return 0;
89 
90  // Define the observer
91  CEObserver observer(opts.AsDouble("longitude"),
92  opts.AsDouble("latitude"),
93  opts.AsDouble("elevation"),
95  observer.SetPressure_hPa(opts.AsDouble("pressure"));
96  observer.SetTemperature_C(opts.AsDouble("temperature"));
97  observer.SetRelativeHumidity(opts.AsDouble("humidity"));
98  observer.SetWavelength_um(opts.AsDouble("wavelength"));
99 
100  // Define the date
101  CEDate date(opts.AsDouble("juliandate"), CEDateType::JD);
102 
103  // Convert the coordinates
104  CESkyCoord obs_coords(CEAngle::Deg(opts.AsDouble("azimuth")),
105  CEAngle::Deg(opts.AsDouble("zenith")),
107  CESkyCoord gal_coords = obs_coords.ConvertToGalactic(date, observer);
108 
109  // Print the results
110  PrintResults(opts, gal_coords);
111 
112  return 0;
113 }
CEDate
Definition: CEDate.h:43
CESkyCoord
Definition: CESkyCoord.h:49
CEExecOptions.h
CEObserver::SetPressure_hPa
void SetPressure_hPa(const double &pressure=CppEphem::EstimatePressure_hPa(CppEphem::SeaLevelTemp_C()))
Set the observer's pressure.
Definition: CEObserver.h:338
CppEphem.h
CEAngleType::DEGREES
DefineOpts
CEExecOptions DefineOpts()
Definition: obs2gal.cpp:34
JD
Julian Date.
Definition: CEDate.h:56
PrintResults
void PrintResults(CEExecOptions &inputs, const CESkyCoord &results)
Definition: obs2gal.cpp:56
CESkyCoord::ConvertToGalactic
CESkyCoord ConvertToGalactic(const CEDate &date=CEDate(), const CEObserver &observer=CEObserver())
Convert this coordinate to GALACTIC coordinates.
Definition: CESkyCoord.cpp:891
CEObserver
Definition: CEObserver.h:28
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: obs2gal.cpp:83
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
CESkyCoordType::OBSERVED
Azimuth, Zenith (requires additional observer information)
CESkyCoord::YCoord
virtual CEAngle YCoord(const CEDate &jd=CppEphem::julian_date_J2000()) const
Return y coordinate at given Julian date.
Definition: CESkyCoord.h:240