diff --git a/.github/workflows/github_actions_build.yml b/.github/workflows/github_actions_build.yml new file mode 100644 index 0000000..7a1a39b --- /dev/null +++ b/.github/workflows/github_actions_build.yml @@ -0,0 +1,27 @@ +name: build + +on: [push, pull_request] + +jobs: + build: + strategy: + matrix: + os: [windows-latest, windows-2019, ubuntu-latest, macOS-latest] + include: + - os: windows-latest + generator: '"Visual Studio 17 2022"' + - os: windows-2019 + generator: '"Visual Studio 16 2019"' + - os: ubuntu-latest + generator: '"Unix Makefiles"' + - os: macOS-latest + generator: '"Unix Makefiles"' + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@master + - name: cmake + run: cmake -G ${{ matrix.generator }} + - name: build + run: cmake --build . + - name: test + run: ctest --verbose --parallel 4 -C Debug diff --git a/.gitignore b/.gitignore index af4667b..ec16f0e 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,8 @@ Thumbs.db *.aps **/obj **/x64 -**/x86 \ No newline at end of file +**/x86 + +[Bb]uild/ +CMakeSettings.json +settings.json \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..591908a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,95 @@ +# CMakeList.txt : Top-level CMake project file, do global configuration +# and include sub-projects here. +# +cmake_minimum_required (VERSION 3.15) + +project ("ITU-R-P528-5") + +set(CMAKE_CXX_STANDARD 11) + +enable_testing() + +# Include sub-projects. +add_subdirectory ("Tests") + +# Download and unpack googletest at configure time +configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) + +execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) + +if(result) + message(FATAL_ERROR "CMake step for googletest failed: ${result}") +endif() + +execute_process(COMMAND ${CMAKE_COMMAND} --build . + RESULT_VARIABLE result + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) + +if(result) + message(FATAL_ERROR "Build step for googletest failed: ${result}") +endif() + +# Prevent overriding the parent project's compiler/linker +# settings on Windows +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +# Add googletest directly to our build. This defines +# the gtest and gtest_main targets. +add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src + ${CMAKE_CURRENT_BINARY_DIR}/googletest-build + EXCLUDE_FROM_ALL) + +# The gtest/gtest_main targets carry header search path +# dependencies automatically when using CMake 2.8.11 or +# later. + +include_directories(${PROJECT_SOURCE_DIR}/include) + +set(Headers + include/p528.h + include/p676.h + include/p835.h) + +set(Sources + src/p528/CombineDistributions.cpp + src/p528/data.cpp + src/p528/FindKForYpiAt99Percent.cpp + src/p528/GetPathLoss.cpp + src/p528/InverseComplementaryCumulativeDistributionFunction.cpp + src/p528/LinearInterpolation.cpp + src/p528/LineOfSight.cpp + src/p528/LongTermVariability.cpp + src/p528/NakagamiRice.cpp + src/p528/P528.cpp + src/p528/RayOptics.cpp + src/p528/ReflectionCoefficients.cpp + src/p528/SmoothEarthDiffraction.cpp + src/p528/TerminalGeometry.cpp + src/p528/TranshorizonSearch.cpp + src/p528/Troposcatter.cpp + src/p528/ValidateInputs.cpp + src/p676/GlobalWetPressure.cpp + src/p676/LineShapeFactor.cpp + src/p676/NonresonantDebyeAttenuation.cpp + src/p676/OxygenData.cpp + src/p676/RayTrace.cpp + src/p676/RefractiveIndex.cpp + src/p676/Refractivity.cpp + src/p676/SlantPath.cpp + src/p676/SpecificAttenuation.cpp + src/p676/TerrestrialPath.cpp + src/p676/WaterVapourData.cpp + src/p676/WaterVapourDensityToPartialPressure.cpp + src/p835/Conversions.cpp + src/p835/MeanAnnualGlobalReferenceAtmosphere.cpp) + +# Add source to this project's executable. +add_library(${PROJECT_NAME} STATIC ${Sources} ${Headers}) + +if(MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) +else() + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic -Werror) +endif() diff --git a/CMakeLists.txt.in b/CMakeLists.txt.in new file mode 100644 index 0000000..226cf8c --- /dev/null +++ b/CMakeLists.txt.in @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8.2) + +project(googletest-download NONE) + +include(ExternalProject) +ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG main + SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" + BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) \ No newline at end of file diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt new file mode 100644 index 0000000..b81494d --- /dev/null +++ b/Tests/CMakeLists.txt @@ -0,0 +1,19 @@ +# CMakeList.txt : CMake project for ITU-R-P528-5, include source and define +# project specific logic here. +# +cmake_minimum_required (VERSION 3.15) +project(Tests) + +set(CMAKE_CXX_STANDARD 11) + +# Add source to this project's executable. +add_executable(${PROJECT_NAME} + main.cpp) + +target_link_libraries(${PROJECT_NAME} ITU-R-P528-5 gtest gtest_main) + +add_test( + NAME ${PROJECT_NAME} + COMMAND ${PROJECT_NAME}) + +target_include_directories(${PROJECT_NAME} PRIVATE ../include) diff --git a/Tests/main.cpp b/Tests/main.cpp new file mode 100644 index 0000000..7aaa221 --- /dev/null +++ b/Tests/main.cpp @@ -0,0 +1,68 @@ +#include "gtest/gtest.h" + +#include "p528.h" + + +TEST(Examples, TestCase1) +{ + Result res{}; + + const auto d__km = 15; + const auto h_1__meter = 10; + const auto h_2__meter = 1000; + const auto f__mhz = 500; + const int T_pol = 0; + const auto time_percentage = 50; + + auto ret = P528(d__km, h_1__meter, h_2__meter, f__mhz, T_pol, time_percentage, &res); + + EXPECT_NEAR(res.A__db, 110.0, 0.1); +} + +TEST(Examples, TestCase2) +{ + Result res{}; + + const auto d__km = 100; + const auto h_1__meter = 100; + const auto h_2__meter = 15000; + const auto f__mhz = 3600; + const int T_pol = 0; + const auto time_percentage = 90; + + auto ret = P528(d__km, h_1__meter, h_2__meter, f__mhz, T_pol, time_percentage, &res); + + EXPECT_NEAR(res.A__db, 151.6, 0.1); +} + +TEST(Examples, TestCase3) +{ + Result res{}; + + const auto d__km = 1500; + const auto h_1__meter = 15; + const auto h_2__meter = 10000; + const auto f__mhz = 5700; + const int T_pol = 0; + const auto time_percentage = 10; + + auto ret = P528(d__km, h_1__meter, h_2__meter, f__mhz, T_pol, time_percentage, &res); + + EXPECT_NEAR(res.A__db, 293.4, 0.1); +} + +TEST(Examples, TestCase4) +{ + Result res{}; + + const auto d__km = 30; + const auto h_1__meter = 8; + const auto h_2__meter = 20000; + const auto f__mhz = 22000; + const int T_pol = 1; + const auto time_percentage = 50; + + auto ret = P528(d__km, h_1__meter, h_2__meter, f__mhz, T_pol, time_percentage, &res); + + EXPECT_NEAR(res.A__db, 151.1, 0.1); +} \ No newline at end of file diff --git a/include/p528.h b/include/p528.h index c68ebad..c40b1da 100644 --- a/include/p528.h +++ b/include/p528.h @@ -1,11 +1,16 @@ +#pragma once + #include #include +#include -using namespace std; +// Define DLLEXPORT for any platform +#ifdef _WIN32 + #define DLLEXPORT extern "C" __declspec(dllexport) +#else + #define DLLEXPORT +#endif -#define DLLEXPORT extern "C" __declspec(dllexport) -#define MAX(x, y) (((x) > (y)) ? (x) : (y)) -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define PI 3.1415926535897932384 #define a_0__km 6371.0 @@ -68,10 +73,10 @@ using namespace std; class data { public: - const static vector P; // Percentages for interpolation and data tables + const static std::vector P; // Percentages for interpolation and data tables - const static vector> NakagamiRiceCurves; - const static vector K; + const static std::vector> NakagamiRiceCurves; + const static std::vector K; }; // diff --git a/include/p676.h b/include/p676.h index 42c32aa..1b94808 100644 --- a/include/p676.h +++ b/include/p676.h @@ -1,11 +1,16 @@ +#pragma once + #include #include +#include -using namespace std; +// Define DLLEXPORT for any platform +#ifdef _WIN32 + #define DLLEXPORT extern "C" __declspec(dllexport) +#else + #define DLLEXPORT +#endif -#define DLLEXPORT extern "C" __declspec(dllexport) -#define MAX(x, y) (((x) > (y)) ? (x) : (y)) -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define PI 3.1415926535897932384 #define a_0__km 6371.0 @@ -34,31 +39,31 @@ struct RayTraceConfig class OxygenData { public: - const static vector f_0; - const static vector a_1; - const static vector a_2; - const static vector a_3; - const static vector a_4; - const static vector a_5; - const static vector a_6; + const static std::vector f_0; + const static std::vector a_1; + const static std::vector a_2; + const static std::vector a_3; + const static std::vector a_4; + const static std::vector a_5; + const static std::vector a_6; }; class WaterVapourData { public: - const static vector f_0; - const static vector b_1; - const static vector b_2; - const static vector b_3; - const static vector b_4; - const static vector b_5; - const static vector b_6; + const static std::vector f_0; + const static std::vector b_1; + const static std::vector b_2; + const static std::vector b_3; + const static std::vector b_4; + const static std::vector b_5; + const static std::vector b_6; }; double LineShapeFactor(double f__ghz, double f_i__ghz, double delta_f__ghz, double delta); double NonresonantDebyeAttenuation(double f__ghz, double e__hPa, double p__hPa, double theta); double RefractiveIndex(double p__hPa, double T__kelvin, double e__hPa); -void GetLayerProperties(double f__ghz, double h_i__km, RayTraceConfig config, +void GetLayerProperties(double f__ghz, double h_i__km, const RayTraceConfig& config, double* n, double* gamma); double SpecificAttenuation(double f__ghz, double T__kelvin, double e__hPa, double p__hPa); @@ -69,7 +74,7 @@ double WaterVapourSpecificAttenuation(double f__ghz, double T__kelvin, double e_ double WaterVapourDensityToPartialPressure(double rho__g_m3, double T__kelvin); void RayTrace(double f__ghz, double h_1__km, double h_2__km, double beta_1__rad, - RayTraceConfig config, SlantPathAttenuationResult* result); + const RayTraceConfig& config, SlantPathAttenuationResult* result); int SlantPathAttenuation(double f__ghz, double h_1__km, double h_2__km, double beta_1__rad, SlantPathAttenuationResult* result); diff --git a/include/p835.h b/include/p835.h index 75d9fd9..a5011d8 100644 --- a/include/p835.h +++ b/include/p835.h @@ -1,6 +1,14 @@ -#define DLLEXPORT extern "C" __declspec(dllexport) -#define MAX(x, y) (((x) > (y)) ? (x) : (y)) -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) +#pragma once + +#include + +// Define DLLEXPORT for any platform +#ifdef _WIN32 + #define DLLEXPORT extern "C" __declspec(dllexport) +#else + #define DLLEXPORT +#endif + // // CONSTANTS diff --git a/src/p528/CombineDistributions.cpp b/src/p528/CombineDistributions.cpp index 29687fb..af7ddc6 100644 --- a/src/p528/CombineDistributions.cpp +++ b/src/p528/CombineDistributions.cpp @@ -1,4 +1,3 @@ -#include #include "../../include/p528.h" /*============================================================================= diff --git a/src/p528/FindKForYpiAt99Percent.cpp b/src/p528/FindKForYpiAt99Percent.cpp index 0f51499..0cca48d 100644 --- a/src/p528/FindKForYpiAt99Percent.cpp +++ b/src/p528/FindKForYpiAt99Percent.cpp @@ -17,7 +17,7 @@ double FindKForYpiAt99Percent(double Y_pi_99__db) return data::K.front(); // search the distribution data and interpolate to find K (dependent variable) - for (int i = 0; i < data::K.size(); i++) + for (size_t i = 0; i < data::K.size(); i++) if (Y_pi_99__db - data::NakagamiRiceCurves[i][Y_pi_99_INDEX] < 0) return (data::K[i] * (Y_pi_99__db - data::NakagamiRiceCurves[i - 1][Y_pi_99_INDEX]) - data::K[i - 1] * (Y_pi_99__db - data::NakagamiRiceCurves[i][Y_pi_99_INDEX])) / (data::NakagamiRiceCurves[i][Y_pi_99_INDEX] - data::NakagamiRiceCurves[i - 1][Y_pi_99_INDEX]); diff --git a/src/p528/GetPathLoss.cpp b/src/p528/GetPathLoss.cpp index 608c45f..ab35b42 100644 --- a/src/p528/GetPathLoss.cpp +++ b/src/p528/GetPathLoss.cpp @@ -1,7 +1,8 @@ -#include -#include #include "../../include/p528.h" +#include + + /*============================================================================= | | Description: This function computes the line of sight loss @@ -48,7 +49,7 @@ void GetPathLoss(double psi__rad, Path *path, double f__mhz, double psi_limit, } // Ray-length factor, [Eqn 8-6] - double F_r = MIN(params->r_0__km / params->r_12__km, 1); + double F_r = std::min(params->r_0__km / params->r_12__km, 1.0); *R_Tg = R_g * D_v * F_r; // [Eqn 8-7] @@ -77,7 +78,7 @@ void GetPathLoss(double psi__rad, Path *path, double f__mhz, double psi_limit, std::complex cplx = std::complex(*R_Tg * cos(phi_Tg), -*R_Tg * sin(phi_Tg)); // [Eqn 8-10] - double W_RL = MIN(abs(1.0 + cplx), 1.0); + double W_RL = std::min(abs(1.0 + cplx), 1.0); // [Eqn 8-11] double W_R0 = pow(W_RL, 2); diff --git a/src/p528/InverseComplementaryCumulativeDistributionFunction.cpp b/src/p528/InverseComplementaryCumulativeDistributionFunction.cpp index 9fda290..0b2ee19 100644 --- a/src/p528/InverseComplementaryCumulativeDistributionFunction.cpp +++ b/src/p528/InverseComplementaryCumulativeDistributionFunction.cpp @@ -1,4 +1,3 @@ -#include #include "../../include/p528.h" /*============================================================================= diff --git a/src/p528/LineOfSight.cpp b/src/p528/LineOfSight.cpp index fbb1d65..75ffc73 100644 --- a/src/p528/LineOfSight.cpp +++ b/src/p528/LineOfSight.cpp @@ -1,8 +1,7 @@ -#include #include "../../include/p528.h" #include "../../include/p676.h" -double FindPsiAtDistance(double d__km, Path *path, Terminal *terminal_1, Terminal *terminal_2) +double FindPsiAtDistance(double d__km, Path * /*path*/, Terminal *terminal_1, Terminal *terminal_2) { if (d__km == 0) return PI / 2; @@ -33,7 +32,7 @@ double FindPsiAtDistance(double d__km, Path *path, Terminal *terminal_1, Termina return psi; } -double FindPsiAtDeltaR(double delta_r__km, Path *path, Terminal *terminal_1, Terminal *terminal_2, double terminate) +double FindPsiAtDeltaR(double delta_r__km, Path * /*path*/, Terminal *terminal_1, Terminal *terminal_2, double terminate) { double psi = PI / 2; double delta_psi = -PI / 4; @@ -55,7 +54,7 @@ double FindPsiAtDeltaR(double delta_r__km, Path *path, Terminal *terminal_1, Ter return psi; } -double FindDistanceAtDeltaR(double delta_r__km, Path *path, Terminal *terminal_1, Terminal *terminal_2, double terminate) +double FindDistanceAtDeltaR(double delta_r__km, Path * /*path*/, Terminal *terminal_1, Terminal *terminal_2, double terminate) { double psi = PI / 2; double delta_psi = -PI / 4; @@ -228,7 +227,7 @@ void LineOfSight(Path *path, Terminal *terminal_1, Terminal *terminal_2, LineOfS else if (los_params->theta_h1__rad >= 1.0) f_theta_h = 0.0; else - f_theta_h = MAX(0.5 - (1 / PI) * (atan(20.0 * log10(32.0 * los_params->theta_h1__rad))), 0); + f_theta_h = std::max(0.5 - (1 / PI) * (atan(20.0 * log10(32.0 * los_params->theta_h1__rad))), 0.0); double Y_e__db, Y_e_50__db, A_Y; LongTermVariability(terminal_1->d_r__km, terminal_2->d_r__km, d__km, f__mhz, p, f_theta_h, los_params->A_LOS__db, &Y_e__db, &A_Y); diff --git a/src/p528/LongTermVariability.cpp b/src/p528/LongTermVariability.cpp index 71a29c7..8b5836f 100644 --- a/src/p528/LongTermVariability.cpp +++ b/src/p528/LongTermVariability.cpp @@ -1,4 +1,3 @@ -#include #include "../../include/p528.h" /*============================================================================= @@ -94,8 +93,8 @@ void LongTermVariability(double d_r1__km, double d_r2__km, double d__km, double else { // Source for values p < 10: [15], Table 10, Page 34, Climate 6 - vector ps = { 1, 2, 5, 10 }; - vector c_ps = { 1.9507, 1.7166, 1.3265, 1.0000 }; + std::vector ps = { 1, 2, 5, 10 }; + std::vector c_ps = { 1.9507, 1.7166, 1.3265, 1.0000 }; auto upper = upper_bound(data::P.begin(), data::P.end(), p); auto dist = distance(data::P.begin(), upper); @@ -114,7 +113,7 @@ void LongTermVariability(double d_r1__km, double d_r2__km, double d__km, double // amount when the variability about L_b(50) is large and L_b(50) is near its free-space level" [ES-83-3, p3-4] double A_YI = (A_T + Y_eI_10__db) - 3.0; // [Eqn 14-23] - *A_Y = MAX(A_YI, 0); // [Eqn 14-24] + *A_Y = std::max(A_YI, 0.0); // [Eqn 14-24] *Y_e__db = Y_eI__db - *A_Y; // [Eqn 14-25] // For percentages less than 10%, do a correction check to, @@ -122,7 +121,7 @@ void LongTermVariability(double d_r1__km, double d_r2__km, double d__km, double // by unrealistic amounts" [Gierhart 1970] if (p < 10) { - vector c_Y = { -5.0, -4.5, -3.7, 0.0 }; + std::vector c_Y = { -5.0, -4.5, -3.7, 0.0 }; auto upper = upper_bound(data::P.begin(), data::P.end(), p); auto dist = distance(data::P.begin(), upper); diff --git a/src/p528/NakagamiRice.cpp b/src/p528/NakagamiRice.cpp index d3b5df9..29e7936 100644 --- a/src/p528/NakagamiRice.cpp +++ b/src/p528/NakagamiRice.cpp @@ -26,7 +26,7 @@ double NakagamiRice(double K, double p) else return LinearInterpolation(data::P[d_p], data::NakagamiRiceCurves[0][d_p], data::P[d_p - 1], data::NakagamiRiceCurves[0][d_p - 1], p); } - else if (d_K == data::K.size()) // K > 20 + else if (d_K == static_cast(data::K.size())) // K > 20 { if (d_p == 0) return data::NakagamiRiceCurves[d_K - 1][0]; diff --git a/src/p528/P528.cpp b/src/p528/P528.cpp index b9ccb8a..6bbde53 100644 --- a/src/p528/P528.cpp +++ b/src/p528/P528.cpp @@ -1,4 +1,3 @@ -#include #include "../../include/p528.h" #include "../../include/p676.h" diff --git a/src/p528/RayOptics.cpp b/src/p528/RayOptics.cpp index 29b120f..d72c5a4 100644 --- a/src/p528/RayOptics.cpp +++ b/src/p528/RayOptics.cpp @@ -1,4 +1,3 @@ -#include #include "../../include/p528.h" /*============================================================================= @@ -47,10 +46,10 @@ void RayOptics(Terminal *terminal_1, Terminal *terminal_2, double psi, LineOfSig double delta_z = abs(params->z__km[0] - params->z__km[1]); // [Eqn 7-10] - params->d__km = MAX(params->a_a__km * (params->theta[0] + params->theta[1]), 0); // [Eqn 7-11] + params->d__km = std::max(params->a_a__km * (params->theta[0] + params->theta[1]), 0.0); // [Eqn 7-11] double alpha = atan((Hprime__km[1] - Hprime__km[0]) / (params->D__km[0] + params->D__km[1])); // [Eqn 7-12] - params->r_0__km = MAX(delta_z, (params->D__km[0] + params->D__km[1]) / cos(alpha)); // [Eqn 7-13] + params->r_0__km = std::max(delta_z, (params->D__km[0] + params->D__km[1]) / cos(alpha)); // [Eqn 7-13] params->r_12__km = (params->D__km[0] + params->D__km[1]) / cos(psi); // [Eqn 7-14] params->delta_r__km = 4.0 * Hprime__km[0] * Hprime__km[1] / (params->r_0__km + params->r_12__km); // [Eqn 7-15] diff --git a/src/p528/ReflectionCoefficients.cpp b/src/p528/ReflectionCoefficients.cpp index 770b21a..ba87c32 100644 --- a/src/p528/ReflectionCoefficients.cpp +++ b/src/p528/ReflectionCoefficients.cpp @@ -1,4 +1,3 @@ -#include #include "../../include/p528.h" /*============================================================================= diff --git a/src/p528/SmoothEarthDiffraction.cpp b/src/p528/SmoothEarthDiffraction.cpp index 5a6aab1..d0159dd 100644 --- a/src/p528/SmoothEarthDiffraction.cpp +++ b/src/p528/SmoothEarthDiffraction.cpp @@ -1,4 +1,3 @@ -#include #include "../../include/p528.h" // References: diff --git a/src/p528/TerminalGeometry.cpp b/src/p528/TerminalGeometry.cpp index 0a6bbe2..640e430 100644 --- a/src/p528/TerminalGeometry.cpp +++ b/src/p528/TerminalGeometry.cpp @@ -1,4 +1,3 @@ -#include #include "../../include/p528.h" #include "../../include/p676.h" diff --git a/src/p528/Troposcatter.cpp b/src/p528/Troposcatter.cpp index 2ed3f60..9a09c6c 100644 --- a/src/p528/Troposcatter.cpp +++ b/src/p528/Troposcatter.cpp @@ -1,4 +1,3 @@ -#include #include "../../include/p528.h" /*============================================================================= @@ -18,7 +17,7 @@ | Outputs: tropo - Struct containing resulting parameters | *===========================================================================*/ -void Troposcatter(Path *path, Terminal *terminal_1, Terminal *terminal_2, double d__km, double f__mhz, TroposcatterParams *tropo) +void Troposcatter(Path * /*path*/, Terminal *terminal_1, Terminal *terminal_2, double d__km, double f__mhz, TroposcatterParams *tropo) { double Q_o, Q_a, Q_b, Q_A, Q_B; double z_a__km, z_b__km, Z_a__km, Z_b__km; @@ -51,14 +50,14 @@ void Troposcatter(Path *path, Terminal *terminal_1, Terminal *terminal_2, double Q_o = A_m - dN; // [Eqn 11-12] - Q_a = A_m - dN / exp(MIN(35.0, z_a__km / gamma_e__km)); // [Eqn 11-13] - Q_b = A_m - dN / exp(MIN(35.0, z_b__km / gamma_e__km)); // [Eqn 11-13] + Q_a = A_m - dN / exp(std::min(35.0, z_a__km / gamma_e__km)); // [Eqn 11-13] + Q_b = A_m - dN / exp(std::min(35.0, z_b__km / gamma_e__km)); // [Eqn 11-13] Z_a__km = (7.0 * Q_o + 6.0 * Q_a - Q_b) * (pow(tropo->d_z__km, 2) / 96.0); // [Eqn 11-14] Z_b__km = (Q_o + 2.0 * Q_a) * (pow(tropo->d_z__km, 2) / 6.0); // [Eqn 11-15] - Q_A = A_m - dN / exp(MIN(35.0, Z_a__km / gamma_e__km)); // [Eqn 11-16] - Q_B = A_m - dN / exp(MIN(35.0, Z_b__km / gamma_e__km)); // [Eqn 11-16] + Q_A = A_m - dN / exp(std::min(35.0, Z_a__km / gamma_e__km)); // [Eqn 11-16] + Q_B = A_m - dN / exp(std::min(35.0, Z_b__km / gamma_e__km)); // [Eqn 11-16] tropo->h_v__km = (Q_o + 2.0 * Q_A) * (pow(tropo->d_z__km, 2) / 6.0); // [Eqn 11-17] @@ -76,7 +75,7 @@ void Troposcatter(Path *path, Terminal *terminal_1, Terminal *terminal_2, double double epsilon_1 = 5.67e-6 * pow(N_s, 2) - 0.00232 * N_s + 0.031; // [Eqn 11-20] double epsilon_2 = 0.0002 * pow(N_s, 2) - 0.06 * N_s + 6.6; // [Eqn 11-21] - double gamma = 0.1424 * (1.0 + epsilon_1 / exp(MIN(35.0, pow(tropo->h_v__km / 4.0, 6)))); // [Eqn 11-22] + double gamma = 0.1424 * (1.0 + epsilon_1 / exp(std::min(35.0, pow(tropo->h_v__km / 4.0, 6)))); // [Eqn 11-22] double S_e__db = 83.1 - epsilon_2 / (1.0 + 0.07716 * pow(tropo->h_v__km, 2)) + 20 * log10(pow(0.1424 / gamma, 2) * exp(gamma * tropo->h_v__km)); // [Eqn 11-23] diff --git a/src/p528/ValidateInputs.cpp b/src/p528/ValidateInputs.cpp index f86f233..78ae329 100644 --- a/src/p528/ValidateInputs.cpp +++ b/src/p528/ValidateInputs.cpp @@ -21,8 +21,6 @@ int ValidateInputs(double d__km, double h_1__meter, double h_2__meter, double f__mhz, int T_pol, double p, int* warnings) { - int rtn = SUCCESS; - if (d__km < 0) return ERROR_VALIDATION__D_KM; diff --git a/src/p528/data.cpp b/src/p528/data.cpp index 5d82797..7f7e02f 100644 --- a/src/p528/data.cpp +++ b/src/p528/data.cpp @@ -1,7 +1,7 @@ #include "../../include/p528.h" // Data curves corresponding Nakagami-Rice distributions -const vector> data::NakagamiRiceCurves = +const std::vector> data::NakagamiRiceCurves = { // K = -40 distribution { @@ -91,11 +91,11 @@ const vector> data::NakagamiRiceCurves = } }; -const vector data::K = +const std::vector data::K = { -40, -25, -20, -18, -16, -14, -12, -10, -8, -6, -4, -2, 0, 2, 4, 6, 20 }; // Percentages for interpolation and data tables -const vector data::P = { 1, 2, 5, 10, 15, 20, 30, 40, 50, +const std::vector data::P = { 1, 2, 5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 85, 90, 95, 98, 99 }; \ No newline at end of file diff --git a/src/p676/GlobalWetPressure.cpp b/src/p676/GlobalWetPressure.cpp index dad7394..aa3c0f4 100644 --- a/src/p676/GlobalWetPressure.cpp +++ b/src/p676/GlobalWetPressure.cpp @@ -18,7 +18,7 @@ double GlobalWetPressure(double h__km) { double T__kelvin = GlobalTemperature(h__km); double P__hPa = GlobalPressure(h__km); - double rho__g_m3 = MAX(GlobalWaterVapourDensity(h__km, RHO_0__M_KG), 2 * pow(10, -6) * 216.7 * P__hPa / T__kelvin); + double rho__g_m3 = std::max(GlobalWaterVapourDensity(h__km, RHO_0__M_KG), 2 * pow(10, -6) * 216.7 * P__hPa / T__kelvin); double e__hPa = WaterVapourDensityToPressure(rho__g_m3, T__kelvin); return e__hPa; diff --git a/src/p676/OxygenData.cpp b/src/p676/OxygenData.cpp index b4bae09..254f259 100644 --- a/src/p676/OxygenData.cpp +++ b/src/p676/OxygenData.cpp @@ -3,7 +3,7 @@ // Spectroscopic data for oxygen attenuation (Table 1) // -const vector OxygenData::f_0 = +const std::vector OxygenData::f_0 = { 50.474214, 50.987745, 51.503360, 52.021429, 52.542418, 53.066934, 53.595775, 54.130025, 54.671180, 55.221384, 55.783815, 56.264774, 56.363399, 56.968211, @@ -14,7 +14,7 @@ const vector OxygenData::f_0 = 715.392902, 773.839490, 834.145546 }; -const vector OxygenData::a_1 = +const std::vector OxygenData::a_1 = { 0.975, 2.529, 6.193, 14.320, 31.240, 64.290, 124.600, 227.300, 389.700, 627.100, 945.300, 543.400, 1331.800, 1746.600, 2120.100, 2363.700, @@ -24,7 +24,7 @@ const vector OxygenData::a_1 = 237.400, 98.100, 572.300, 183.100 }; -const vector OxygenData::a_2 = +const std::vector OxygenData::a_2 = { 9.651, 8.653, 7.709, 6.819, 5.983, 5.201, 4.474, 3.800, 3.182, 2.618, 2.109, 0.014, 1.654, 1.255, 0.910, 0.621, 0.083, 0.387, 0.207, 0.207, 0.386, 0.621, @@ -32,7 +32,7 @@ const vector OxygenData::a_2 = 6.818, 7.708, 8.652, 9.650, 0.010, 0.048, 0.044, 0.049, 0.145, 0.141, 0.145 }; -const vector OxygenData::a_3 = +const std::vector OxygenData::a_3 = { 6.690, 7.170, 7.640, 8.110, 8.580, 9.060, 9.550, 9.960, 10.370, 10.890, 11.340, 17.030, 11.890, 12.230, 12.620, 12.950, 14.910, 13.530, @@ -41,7 +41,7 @@ const vector OxygenData::a_3 = 6.690, 16.640, 16.400, 16.400, 16.000, 16.000, 16.200, 14.700 }; -const vector OxygenData::a_4 = +const std::vector OxygenData::a_4 = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, @@ -49,7 +49,7 @@ const vector OxygenData::a_4 = 0.0, 0.0 }; -const vector OxygenData::a_5 = +const std::vector OxygenData::a_5 = { 2.566, 2.246, 1.947, 1.667, 1.388, 1.349, 2.227, 3.170, 3.558, 2.560, -1.172, 3.525, -2.378, -3.545, -5.416, -1.932, 6.768, -6.561, 6.957, -6.395, @@ -58,7 +58,7 @@ const vector OxygenData::a_5 = 0.000, 0.000, 0.000, 0.000 }; -const vector OxygenData::a_6 = +const std::vector OxygenData::a_6 = { 6.850, 6.800, 6.729, 6.640, 6.526, 6.206, 5.085, 3.750, 2.654, 2.952, 6.135, -0.978, 6.547, 6.451, 6.056, 0.436, -1.273, 2.309, -0.776, 0.699, diff --git a/src/p676/RayTrace.cpp b/src/p676/RayTrace.cpp index 1e1ed0f..90c6e8b 100644 --- a/src/p676/RayTrace.cpp +++ b/src/p676/RayTrace.cpp @@ -37,11 +37,11 @@ double LayerThickness(double m, int i) | *===========================================================================*/ void RayTrace(double f__ghz, double h_1__km, double h_2__km, double beta_1__rad, - RayTraceConfig config, SlantPathAttenuationResult* result) + const RayTraceConfig& config, SlantPathAttenuationResult* result) { // Equations 16(a)-(c) - int i_lower = floor(100 * log(1e4 * h_1__km * (exp(1. / 100.) - 1) + 1) + 1); - int i_upper = ceil(100 * log(1e4 * h_2__km * (exp(1. / 100.) - 1) + 1) + 1); + int i_lower = static_cast(floor(100 * log(1e4 * h_1__km * (exp(1. / 100.) - 1) + 1) + 1)); + int i_upper = static_cast(ceil(100 * log(1e4 * h_2__km * (exp(1. / 100.) - 1) + 1) + 1)); double m = ((exp(2. / 100.) - exp(1. / 100.)) / (exp(i_upper / 100.) - exp(i_lower / 100.))) * (h_2__km - h_1__km); double gamma_i; @@ -88,10 +88,10 @@ void RayTrace(double f__ghz, double h_1__km, double h_2__km, double beta_1__rad, delta_i__km = LayerThickness(m, i); // Equation 19b - beta_i__rad = asin(MIN(1, (n_1 * r_1__km) / (n_i * r_i__km) * sin(beta_1__rad))); + beta_i__rad = asin(std::min(1.0, (n_1 * r_1__km) / (n_i * r_i__km) * sin(beta_1__rad))); // entry angle into the layer interface, Equation 18a - alpha_i__rad = asin(MIN(1, (n_1 * r_1__km) / (n_i * r_ii__km) * sin(beta_1__rad))); + alpha_i__rad = asin(std::min(1.0, (n_1 * r_1__km) / (n_i * r_ii__km) * sin(beta_1__rad))); // path length through ith layer, Equation 17 a_i__km = -r_i__km * cos(beta_i__rad) + sqrt(pow(r_i__km, 2) * pow(cos(beta_i__rad), 2) + 2 * r_i__km * delta_i__km + pow(delta_i__km, 2)); @@ -131,7 +131,7 @@ void RayTrace(double f__ghz, double h_1__km, double h_2__km, double beta_1__rad, | Returns: [void] | *===========================================================================*/ -void GetLayerProperties(double f__ghz, double h_i__km, RayTraceConfig config, +void GetLayerProperties(double f__ghz, double h_i__km, const RayTraceConfig& config, double* n, double* gamma) { // use function pointers to get atmospheric parameters diff --git a/src/p676/Refractivity.cpp b/src/p676/Refractivity.cpp index 4559552..7f636a3 100644 --- a/src/p676/Refractivity.cpp +++ b/src/p676/Refractivity.cpp @@ -19,7 +19,7 @@ double OxygenRefractivity(double f__ghz, double T__kelvin, double e__hPa, double double N = 0; - for (int i = 0; i < OxygenData::f_0.size(); i++) + for (size_t i = 0; i < OxygenData::f_0.size(); i++) { // Equation 3, for oxygen double S_i = OxygenData::a_1[i] * 1e-7 * p__hPa * pow(theta, 3) * exp(OxygenData::a_2[i] * (1 - theta)); @@ -67,7 +67,7 @@ double WaterVapourRefractivity(double f__ghz, double T__kelvin, double e__hPa, d double N_w = 0; - for (int i = 0; i < WaterVapourData::f_0.size(); i++) + for (size_t i = 0; i < WaterVapourData::f_0.size(); i++) { // Equation 3, for water vapour double S_i = 0.1 * WaterVapourData::b_1[i] * e__hPa * pow(theta, 3.5) * exp(WaterVapourData::b_2[i] * (1 - theta)); diff --git a/src/p676/WaterVapourData.cpp b/src/p676/WaterVapourData.cpp index 5e2d9cd..04bba49 100644 --- a/src/p676/WaterVapourData.cpp +++ b/src/p676/WaterVapourData.cpp @@ -3,7 +3,7 @@ // Spectroscopic data for water vapor attenuation (Table 2) // -const vector WaterVapourData::f_0 = +const std::vector WaterVapourData::f_0 = { 22.235080, 67.803960, 119.995940, 183.310087, 321.225630, 325.152888, 336.227764, 380.197353, 390.134508, 437.346667, 439.150807, 443.018343, 448.001085, 470.888999, @@ -12,7 +12,7 @@ const vector WaterVapourData::f_0 = 902.611085, 906.205957, 916.171582, 923.112692, 970.315022, 987.926764, 1780.000000 }; -const vector WaterVapourData::b_1 = +const std::vector WaterVapourData::b_1 = { 0.1079, 0.0011, 0.0007, 2.273, 0.0470, 1.514, 0.0010, 11.67, 0.0045, 0.0632, 0.9098, 0.1920, 10.41, 0.3254, 1.260, 0.2529, 0.0372, 0.0124, @@ -20,7 +20,7 @@ const vector WaterVapourData::b_1 = 0.0547, 0.0386, 0.1836, 8.400, 0.0079, 9.009, 134.6, 17506.0 }; -const vector WaterVapourData::b_2 = +const std::vector WaterVapourData::b_2 = { 2.144, 8.732, 8.353, .668, 6.179, 1.541, 9.825, 1.048, 7.347, 5.048, 3.595, 5.048, 1.405, 3.597, 2.379, 2.852, 6.731, 6.731, .158, .158, @@ -28,7 +28,7 @@ const vector WaterVapourData::b_2 = 1.441, 10.293, 1.919, .257, .952 }; -const vector WaterVapourData::b_3 = +const std::vector WaterVapourData::b_3 = { 26.38, 28.58, 29.48, 29.06, 24.04, 28.23, 26.93, 28.11, 21.52, 18.45, 20.07, 15.55, 25.64, 21.34, 23.20, 25.86, 16.12, 16.12, 26.00, 26.00, 30.86, 24.38, @@ -36,14 +36,14 @@ const vector WaterVapourData::b_3 = 29.85, 196.3 }; -const vector WaterVapourData::b_4 = +const std::vector WaterVapourData::b_4 = { .76, .69, .70, .77, .67, .64, .69, .54, .63, .60, .63, .60, .66, .66, .65, .69, .61, .61, .70, .70, .69, .71, .60, .69, .68, .33, .68, .68, .70, .70, .70, .70, .64, .68, 2.00 }; -const vector WaterVapourData::b_5 = +const std::vector WaterVapourData::b_5 = { 5.087, 4.930, 4.780, 5.022, 4.398, 4.893, 4.740, 5.063, 4.810, 4.230, 4.483, 5.083, 5.028, 4.506, 4.804, 5.201, 3.980, 4.010, 4.500, 4.500, 4.552, 4.856, @@ -51,7 +51,7 @@ const vector WaterVapourData::b_5 = 4.550, 24.15 }; -const vector WaterVapourData::b_6 = +const std::vector WaterVapourData::b_6 = { 1.00, .82, .79, .85, .54, .74, .61, .89, .55, .48, .52, .50, .67, .65, .64, .72, .43, .45, 1.00, 1.00, 1.00, .68, .50, 1.00, .84, .45, .84, diff --git a/src/p835/Conversions.cpp b/src/p835/Conversions.cpp index c6daf71..3fd7892 100644 --- a/src/p835/Conversions.cpp +++ b/src/p835/Conversions.cpp @@ -1,4 +1,3 @@ -#include "math.h" #include "../../include/p835.h" /*============================================================================= diff --git a/src/p835/MeanAnnualGlobalReferenceAtmosphere.cpp b/src/p835/MeanAnnualGlobalReferenceAtmosphere.cpp index 80f2938..2b6c233 100644 --- a/src/p835/MeanAnnualGlobalReferenceAtmosphere.cpp +++ b/src/p835/MeanAnnualGlobalReferenceAtmosphere.cpp @@ -1,4 +1,3 @@ -#include "math.h" #include "../../include/p835.h" /*=============================================================================