CppEphem
test_CENamespace.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * test_CENamespace.cpp: CppEphem *
3  * ----------------------------------------------------------------------- *
4  * Copyright © 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 
26 #include <iostream>
27 
28 #include "test_CENamespace.h"
29 #include "CENamespace.h"
30 
31 
32 /**********************************************************************/
36  CETestSuite()
37 {}
38 
39 
40 /**********************************************************************/
44 {}
45 
46 
47 /**********************************************************************/
53 {
54  std::cout << "\nTesting CENamespace:\n";
55 
56  // Run each of the tests
60  test_StrOpt();
61 
62  return pass();
63 }
64 
65 
66 /**********************************************************************/
71 {
72  // Check the temperature at sea level
73  double sea_level_temp_K = 288.2;
74  test_double(CppEphem::SeaLevelTemp_K(), sea_level_temp_K, __func__, __LINE__);
75 
76  // Convert
77  double sea_level_temp_C = sea_level_temp_K - 273.15;
78  test_double(CppEphem::SeaLevelTemp_C(), sea_level_temp_C, __func__, __LINE__);
79 
80  double sea_level_temp_F = (9.0/5.0) * sea_level_temp_C + 32.0;
81  test_double(CppEphem::SeaLevelTemp_F(), sea_level_temp_F, __func__, __LINE__);
82 
83  return pass();
84 }
85 
86 
87 /**********************************************************************/
92 {
93  // Test julian date 2000
94  test_double(CppEphem::julian_date_J2000(), DJ00, __func__, __LINE__);
95 
96  // Speed of light (m/sec)
97  test_double(CppEphem::c(), DC * DAU / DAYSEC, __func__, __LINE__);
98 
99  // Speed of light (AU/day)
100  test_double(CppEphem::c_au_per_day(), DC, __func__, __LINE__);
101 
102  // Meters per AU
103  test_double(CppEphem::m_per_au(), DAU, __func__, __LINE__);
104 
105  // Seconds per day
106  test_double(CppEphem::sec_per_day(), DAYSEC, __func__, __LINE__);
107 
108  // Test temperature conversions
109  double temp_K(0.0);
110  double temp_C(-273.15);
111  double temp_F(-459.67);
112  // Reduce accuracy for the tests
113  double old_tol = DblTol();
114  SetDblTol(1.0e-11);
115  test_double(CppEphem::Temp_C2F(temp_C), temp_F, __func__, __LINE__);
116  test_double(CppEphem::Temp_C2K(temp_C), temp_K, __func__, __LINE__);
117  test_double(CppEphem::Temp_F2C(temp_F), temp_C, __func__, __LINE__);
118  test_double(CppEphem::Temp_F2K(temp_F), temp_K, __func__, __LINE__);
119  test_double(CppEphem::Temp_K2C(temp_K), temp_C, __func__, __LINE__);
120  test_double(CppEphem::Temp_K2F(temp_K), temp_F, __func__, __LINE__);
121  SetDblTol(old_tol);
122 
123  return pass();
124 }
125 
126 
127 /**********************************************************************/
132 {
133  double mjd(51544.5);
134 
135  // Get dut1 for J2000 (and test interpolation)
137  test_double(CppEphem::dut1(mjd), 0.355499, __func__, __LINE__);
139  test_double(CppEphem::dut1(mjd), 0.355066, __func__, __LINE__);
140 
141  // Turn off interpolation for future tests
143 
144  test_double(CppEphem::dut1Error(mjd), 0.0, __func__, __LINE__);
145  test_double(CppEphem::dut1Calc(mjd), 0.0, __func__, __LINE__);
146 
147  // Test x,y polar motion
148  test_double(CppEphem::xp(mjd), 0.043190 * DAS2R, __func__, __LINE__);
149  test_double(CppEphem::yp(mjd), 0.377700 * DAS2R, __func__, __LINE__);
150 
151  // Test dpsi,deps corrections
152  test_double(CppEphem::dpsi(mjd), -0.252*DMAS2R, __func__, __LINE__);
153  test_double(CppEphem::deps(mjd), -0.119*DMAS2R, __func__, __LINE__);
154 
155  // Estimate altitude/pressure based on pressure
156  test_double(CppEphem::EstimateAltitude_m(1013.25), 0.0, __func__, __LINE__);
157  test_double(CppEphem::EstimatePressure_hPa(0.0), 1013.25, __func__, __LINE__);
158 
159  // Test the name of the corrections files
160  std::string file_path(CECORRFILEPATH);
161  std::string nut_file = file_path + "/nutation.txt";
162  std::string ttut1_hist = file_path + "/ttut1_historic.txt";
163  std::string ttut1_pred = file_path + "/ttut1_predicted.txt";
164 
165  test_string(CppEphem::NutationFile(), nut_file, __func__, __LINE__);
166  test_string(CppEphem::TtUt1HistFile(), ttut1_hist, __func__, __LINE__);
167  test_string(CppEphem::TtUt1PredFile(), ttut1_pred, __func__, __LINE__);
168 
169  // Test setting the corrections filename
170  std::string newfilename("testfilename.txt");
171  CppEphem::SetNutationFile(newfilename);
172  CppEphem::SetTtUt1HistFile(newfilename);
173  CppEphem::SetTtUt1PredFile(newfilename);
174  test_string(CppEphem::NutationFile(), newfilename, __func__, __LINE__);
175  test_string(CppEphem::TtUt1HistFile(), newfilename, __func__, __LINE__);
176  test_string(CppEphem::TtUt1PredFile(), newfilename, __func__, __LINE__);
177 
178  // Reset the filenames
179  CppEphem::SetNutationFile(nut_file);
180  CppEphem::SetTtUt1HistFile(ttut1_hist);
181  CppEphem::SetTtUt1PredFile(ttut1_pred);
182 
183  return pass();
184 }
185 
186 
187 /**********************************************************************/
192 {
193  // Create a string for parsing
194  std::string test1 = "hello world!";
195  test_vect(CppEphem::StrOpt::split(test1, ' '), {"hello", "world!"}, __func__, __LINE__);
196 
197  // See if we can pass the vector and get the same results back
198  std::vector<std::string> test2;
199  CppEphem::StrOpt::split(test1, ' ', &test2);
200  test_vect(test2, {"hello", "world!"}, __func__, __LINE__);
201 
202  // Check if we can put it back together
203  std::string test3 = CppEphem::StrOpt::join<std::string>(test2, ',');
204  test_string(test3, "hello,world!", __func__, __LINE__);
205 
206  // See if we can join a vector of angle components into a legit string
207  std::vector<double> angles = {123, 34, 52, 0.542};
208  std::string angle_str = CppEphem::StrOpt::join_angle(angles, ':');
209  test_string(angle_str, "123:34:52.54200000", __func__, __LINE__);
210 
211  return pass();
212 }
213 
214 
215 /**********************************************************************/
218 int main(int argc, char** argv)
219 {
220  test_CENamespace tester;
221  return (!tester.runtests());
222 }
CppEphem::SetNutationFile
void SetNutationFile(const std::string &filename)
Set the name of the file to use for defining the nutation corrections.
Definition: CENamespace.cpp:66
CppEphem::NutationFile
std::string NutationFile(void)
Return the name of the file used for defining the corrections.
Definition: CENamespace.cpp:33
test_CENamespace
Definition: test_CENamespace.h:27
CENamespace.h
test_CENamespace::test_StrOpt
virtual bool test_StrOpt(void)
Tests the string operations.
Definition: test_CENamespace.cpp:191
CppEphem::yp
double yp(const double &mjd)
Polar motion (x) for a given modified julian date (radians)
Definition: CENamespace.cpp:160
CppEphem::Temp_C2F
double Temp_C2F(const double &temp_C)
Definition: CENamespace.h:59
CppEphem::c
double c()
speed of light (meters/second)
Definition: CENamespace.h:68
CppEphem::deps
double deps(const double &mjd)
Earth obliquity correction for a given modified julian date (radians)
Definition: CENamespace.cpp:172
CppEphem::sec_per_day
double sec_per_day()
Seconds per day.
Definition: CENamespace.h:71
CppEphem::TtUt1HistFile
std::string TtUt1HistFile(void)
Return the name of the file used for defining the corrections.
Definition: CENamespace.cpp:44
main
int main(int argc, char **argv)
Main method that actually runs the tests.
Definition: test_CENamespace.cpp:218
CppEphem::StrOpt::join_angle
std::string join_angle(const std::vector< double > &values, const char &delim)
Method for splitting a string based on some delimiter into a vector of strings.
Definition: CENamespace.cpp:267
test_CENamespace::test_CENamespace
test_CENamespace()
Default constructor.
Definition: test_CENamespace.cpp:35
CppEphem::dpsi
double dpsi(const double &mjd)
Earth longitude correction for a given modified julian date (radians)
Definition: CENamespace.cpp:184
CppEphem::SeaLevelTemp_C
double SeaLevelTemp_C()
Definition: CENamespace.h:55
CppEphem::Temp_F2K
double Temp_F2K(const double &temp_F)
Definition: CENamespace.h:62
CppEphem::julian_date_J2000
double julian_date_J2000()
Julian Date corresponding to J2000.
Definition: CENamespace.h:67
CppEphem::SeaLevelTemp_K
double SeaLevelTemp_K()
Definition: CENamespace.h:54
test_CENamespace::test_Corrections
virtual bool test_Corrections(void)
Tests basic coordinate conversion correction values.
Definition: test_CENamespace.cpp:131
test_CENamespace::test_Conversions
virtual bool test_Conversions(void)
Tests return values for basic unit conversion constants.
Definition: test_CENamespace.cpp:91
CppEphem::SetTtUt1PredFile
void SetTtUt1PredFile(const std::string &filename)
Set the name of the file to use for defining the predicted TT-UT1 corrections.
Definition: CENamespace.cpp:88
CppEphem::dut1Calc
double dut1Calc(const double &mjd)
Set the time from a vector representing Greenwich Apparent Sidereal Time.
Definition: CENamespace.cpp:133
CppEphem::Temp_F2C
double Temp_F2C(const double &temp_F)
Definition: CENamespace.h:61
CppEphem::dut1Error
double dut1Error(const double &mjd=51544.5)
Definition: CENamespace.cpp:123
test_CENamespace::~test_CENamespace
virtual ~test_CENamespace()
Destructor.
Definition: test_CENamespace.cpp:43
CppEphem::TtUt1PredFile
std::string TtUt1PredFile(void)
Return the name of the file used for defining the corrections.
Definition: CENamespace.cpp:55
CppEphem::Temp_K2C
double Temp_K2C(const double &temp_K)
Definition: CENamespace.h:63
CppEphem::EstimatePressure_hPa
double EstimatePressure_hPa(double elevation_m)
Method for estimating atmospheric pressure (in hPa) from altitude (in meters)
Definition: CENamespace.h:100
CppEphem::c_au_per_day
double c_au_per_day()
speed of light (astronomical units)/day
Definition: CENamespace.h:69
CppEphem::Temp_K2F
double Temp_K2F(const double &temp_K)
Definition: CENamespace.h:64
CppEphem::CorrectionsInterp
void CorrectionsInterp(bool set_interp)
Set the corrections object to use interpolation.
Definition: CENamespace.cpp:99
test_CENamespace::runtests
virtual bool runtests()
Run tests.
Definition: test_CENamespace.cpp:52
CppEphem::SeaLevelTemp_F
double SeaLevelTemp_F()
Definition: CENamespace.h:56
test_CENamespace.h
test_CENamespace::test_SeaLevelVals
virtual bool test_SeaLevelVals(void)
Tests return values for temperature at sea level.
Definition: test_CENamespace.cpp:70
CppEphem::dut1
double dut1(const double &mjd)
Return dut1 based on a given modified julian date (seconds)
Definition: CENamespace.cpp:111
CppEphem::m_per_au
double m_per_au()
meters per astronomical unit
Definition: CENamespace.h:70
CppEphem::Temp_C2K
double Temp_C2K(const double &temp_C)
Definition: CENamespace.h:60
CppEphem::StrOpt::split
void split(const std::string &s, const char &delim, std::vector< std::string > *elems)
Method for splitting a string based on some delimiter into a vector of strings.
Definition: CENamespace.cpp:209
CppEphem::SetTtUt1HistFile
void SetTtUt1HistFile(const std::string &filename)
Set the name of the file to use for defining the historic TT-UT1 corrections.
Definition: CENamespace.cpp:77
CppEphem::xp
double xp(const double &mjd)
Polar motion (x) for a given modified julian date (radians)
Definition: CENamespace.cpp:148
CppEphem::EstimateAltitude_m
double EstimateAltitude_m(double pressure_hPa)
Method for estimating altitude (in meters) from atmospheric pressure (in hPa)
Definition: CENamespace.h:97