CppEphem
icrs2obs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * icrs2obs.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 
28 // CppEphem HEADERS
29 #include "CppEphem.h"
30 #include "CEExecOptions.h"
31 
32 /**********************************************************************/
35 {
36  CEExecOptions opts("icrs2obs");
37 
38  // Add version and description
39  opts.AddProgramDescription(std::string() +
40  "Converts from ICRS (solar system barycentric) coordinates to " +
41  "observed altitude, zenith coordinates for a given Julian date. " +
42  "Additional observing parameters can also be supplied for more " +
43  "accurate coordinate values");
44 
45  // Setup the options
46  opts.AddIcrsPars();
47  opts.AddObserverPars();
48  opts.AddJDPar();
49 
50  return opts;
51 }
52 
53 
54 /**********************************************************************/
56 void PrintResults(const CESkyCoord& input_icrs,
57  const CESkyCoord& observed_altaz,
58  const CESkyCoord& observed_icrs,
59  const CEObserver& observer,
60  const CEDate & date)
61 {
62  std::printf("\n") ;
63  std::printf("******************************************\n") ;
64  std::printf("* Results of ICRS -> Observed conversion *\n") ;
65  std::printf("******************************************\n") ;
66  std::printf("Observed Coordinates (output)\n") ;
67  std::printf(" Azimuth : %f deg\n", observed_altaz.XCoord().Deg()) ;
68  std::printf(" Zenith : %+f deg\n", observed_altaz.YCoord().Deg()) ;
69  std::printf(" Altitude : %+f deg\n", 90.0-observed_altaz.YCoord().Deg()) ;
70  std::printf("ICRS Coordinates (input)\n") ;
71  std::printf(" Right Ascension: %f deg\n", input_icrs.XCoord().Deg()) ;
72  std::printf(" Declination : %+f deg\n", input_icrs.YCoord().Deg()) ;
73  std::printf(" Julian Date : %f\n", date.JD()) ;
74  std::printf("Apparent ICRS Coordinates\n");
75  std::printf(" Right Ascension: %f deg\n", observed_icrs.XCoord().Deg());
76  std::printf(" Declination : %f deg\n", observed_icrs.YCoord().Deg());
77  std::printf("Observer Info\n") ;
78  std::printf(" Longitude : %f deg\n", observer.Longitude_Deg()) ;
79  std::printf(" Latitude : %+f deg\n", observer.Latitude_Deg()) ;
80  std::printf(" Elevation : %f meters\n", observer.Elevation_m()) ;
81  std::printf(" Pressure : %f hPa\n", observer.Pressure_hPa()) ;
82  std::printf(" Temperature : %f Celsius\n", observer.Temperature_C()) ;
83  std::printf(" Relative Humid.: %f\n", observer.RelativeHumidity()) ;
84  std::printf("\n") ;
85 }
86 
87 /**********************************************************************/
90 int main(int argc, char** argv)
91 {
92  CEExecOptions opts = DefineOpts();
93  if (opts.ParseCommandLine(argc, argv)) return 0;
94 
95  // Create the input and output coordinates
96  CESkyCoord icrs_coords(CEAngle::Deg(opts.AsDouble("ra")),
97  CEAngle::Deg(opts.AsDouble("dec")),
99 
100  // Define the date
101  CEDate date(opts.AsDouble("juliandate"), CEDateType::JD);
102 
103  // Define the observer
104  CEObserver observer(opts.AsDouble("longitude"),
105  opts.AsDouble("latitude"),
106  opts.AsDouble("elevation"),
108  observer.SetPressure_hPa(opts.AsDouble("pressure"));
109  observer.SetTemperature_C(opts.AsDouble("temperature"));
110  observer.SetRelativeHumidity(opts.AsDouble("humidity"));
111  observer.SetWavelength_um(opts.AsDouble("wavelength"));
112 
113  // Convert the coordinates
114  CESkyCoord obs_coords;
115  CESkyCoord obs_icrs_coords;
116  CESkyCoord::ICRS2Observed(icrs_coords, &obs_coords, date, observer, &obs_icrs_coords);
117 
118  // Print the results
119  PrintResults(icrs_coords, obs_coords, obs_icrs_coords, observer, date);
120 
121  return 0 ;
122 }
CEObserver::Elevation_m
double Elevation_m() const
Return altitude in meters above sea level.
Definition: CEObserver.h:166
CESkyCoordType::ICRS
RA, Dec (referenced at the barycenter of the solarsystem)
CEDate
Definition: CEDate.h:43
CEObserver::Temperature_C
double Temperature_C() const
Return temperature in degrees Celsius.
Definition: CEObserver.h:186
CESkyCoord
Definition: CESkyCoord.h:49
CEExecOptions.h
CEObserver::RelativeHumidity
double RelativeHumidity() const
Return relative humidity.
Definition: CEObserver.h:216
DefineOpts
CEExecOptions DefineOpts()
Definition: icrs2obs.cpp:33
CEObserver::SetRelativeHumidity
void SetRelativeHumidity(const double &humidity=0.0)
Set the observer's relative humidity.
Definition: CEObserver.h:349
CEObserver::SetWavelength_um
void SetWavelength_um(const double &new_wavelength_um)
Set the observer's observing wavelength (micrometers)
Definition: CEObserver.h:393
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
CEObserver::Pressure_hPa
double Pressure_hPa() const
Return atmospheric pressure in units of hPa.
Definition: CEObserver.h:176
CEObserver::SetTemperature_C
void SetTemperature_C(const double &temp_C=CppEphem::SeaLevelTemp_C())
Set the observer's temperature (Celsius)
Definition: CEObserver.h:360
CEAngleType::DEGREES
JD
Julian Date.
Definition: CEDate.h:56
CESkyCoord::ICRS2Observed
static void ICRS2Observed(const CESkyCoord &in_icrs, CESkyCoord *out_observed, const CEDate &date, const CEObserver &observer, CESkyCoord *observed_cirs=nullptr, CEAngle *hour_angle=nullptr)
ICRS -> OBSERVED coordinate conversion.
Definition: CESkyCoord.cpp:407
main
int main(int argc, char **argv)
Main.
Definition: icrs2obs.cpp:89
CEObserver::Latitude_Deg
double Latitude_Deg() const
Return geographic latitude in degrees.
Definition: CEObserver.h:156
CEObserver
Definition: CEObserver.h:28
CEAngle::Deg
double Deg(void) const
Return angle in degrees as a double.
Definition: CEAngle.cpp:328
CEObserver::Longitude_Deg
double Longitude_Deg() const
Return observer geographic longitude in degrees.
Definition: CEObserver.h:136
CEDate::JD
virtual double JD() const
Get the Julian date represented by this object.
Definition: CEDate.h:150
PrintResults
void PrintResults(const CESkyCoord &input_icrs, const CESkyCoord &observed_altaz, const CESkyCoord &observed_icrs, const CEObserver &observer, const CEDate &date)
Definition: icrs2obs.cpp:55
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