CppEphem
obs2icrs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * obs2icrs.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("obs2icrs");
38 
39  // Add a program version and description
40  opts.AddProgramDescription(std::string() +
41  "Takes observed positions (azimuth,zenith angle) and computes the ICRS " +
42  "RA,Dec positions based on the observer location and atmospheric " +
43  "properties. The only values necessary to get rough coordinates are " +
44  "'longitude', 'latitude', 'azimuth', 'zenith', and 'juliandate'.") ;
45 
46  // Setup the input parameters
47  opts.AddObservedPars();
48  opts.AddObserverPars();
49  opts.AddJDPar();
50 
51  return opts;
52 }
53 
54 /**********************************************************************/
56 void PrintResults(CEExecOptions& inputs,
57  const CESkyCoord& results)
58 {
59  std::printf("\n") ;
60  std::printf("******************************************\n") ;
61  std::printf("* Results of Observed -> ICRS conversion *\n") ;
62  std::printf("******************************************\n") ;
63  std::printf("Observed Coordinates (input)\n") ;
64  std::printf(" Azimuth : %f degrees\n", inputs.AsDouble("azimuth")) ;
65  std::printf(" Zenith : %+f degrees\n", inputs.AsDouble("zenith")) ;
66  std::printf(" Altitude : %+f degrees\n", 90.0-inputs.AsDouble("zenith")) ;
67  std::printf("ICRS Coordinates (output)\n") ;
68  std::printf(" Right Ascension: %f degrees\n", results.XCoord().Deg()) ;
69  std::printf(" Declination : %+f degrees\n", results.YCoord().Deg()) ;
70  std::printf("Observer Info\n") ;
71  std::printf(" Julian Date : %f\n", inputs.AsDouble("juliandate")) ;
72  std::printf(" Longitude : %f deg\n", inputs.AsDouble("longitude")) ;
73  std::printf(" Latitude : %+f deg\n", inputs.AsDouble("latitude")) ;
74  std::printf(" Elevation : %f meters\n", inputs.AsDouble("elevation")) ;
75  std::printf(" Pressure : %f hPa\n", inputs.AsDouble("pressure")) ;
76  std::printf(" Temperature : %f Celsius\n", inputs.AsDouble("temperature")) ;
77  std::printf(" Relative Humid.: %f\n", inputs.AsDouble("humidity")) ;
78  std::printf("\n") ;
79 }
80 
81 /**********************************************************************/
83 int main(int argc, char** argv) {
84 
85  // Parse the command line options
86  CEExecOptions opts = DefineOpts() ;
87  if (opts.ParseCommandLine(argc, argv)) return 0;
88 
89  // Define the observer
90  CEObserver observer(opts.AsDouble("longitude"),
91  opts.AsDouble("latitude"),
92  opts.AsDouble("elevation"),
94  observer.SetPressure_hPa(opts.AsDouble("pressure"));
95  observer.SetTemperature_C(opts.AsDouble("temperature"));
96  observer.SetRelativeHumidity(opts.AsDouble("humidity"));
97  observer.SetWavelength_um(opts.AsDouble("wavelength"));
98 
99  // Define the date
100  CEDate date(opts.AsDouble("juliandate"), CEDateType::JD);
101 
102  // Convert the coordinates
103  CESkyCoord obs_coords(CEAngle::Deg(opts.AsDouble("azimuth")),
104  CEAngle::Deg(opts.AsDouble("zenith")),
106  CESkyCoord cirs_coords = obs_coords.ConvertToICRS(date, observer);
107 
108  // Print the results
109  PrintResults(opts, cirs_coords);
110 
111  return 0;
112 }
CEDate
Definition: CEDate.h:43
CESkyCoord
Definition: CESkyCoord.h:49
CEExecOptions.h
DefineOpts
CEExecOptions DefineOpts()
Definition: obs2icrs.cpp:34
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
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
main
int main(int argc, char **argv)
Definition: obs2icrs.cpp:82
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 &inputs, const CESkyCoord &results)
Definition: obs2icrs.cpp:55
CESkyCoord::ConvertToICRS
CESkyCoord ConvertToICRS(const CEDate &date=CEDate(), const CEObserver &observer=CEObserver())
Convert this coordinate to ICRS coordinates.
Definition: CESkyCoord.cpp:854
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