Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few simple changes to allow code to cleanly compile on Linux/MacOS/Windows (VS2019/22) - add github action to do builds / add unit tests #11

Open
wants to merge 17 commits into
base: cmake-support
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/github_actions_build.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ Thumbs.db
*.aps
**/obj
**/x64
**/x86
**/x86

[Bb]uild/
CMakeSettings.json
settings.json
95 changes: 95 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
15 changes: 15 additions & 0 deletions CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -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 ""
)
19 changes: 19 additions & 0 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
68 changes: 68 additions & 0 deletions Tests/main.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
19 changes: 12 additions & 7 deletions include/p528.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#pragma once

#include <vector>
#include <algorithm>
#include <math.h>

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
Expand Down Expand Up @@ -68,10 +73,10 @@ using namespace std;
class data
{
public:
const static vector<double> P; // Percentages for interpolation and data tables
const static std::vector<double> P; // Percentages for interpolation and data tables

const static vector<vector<double>> NakagamiRiceCurves;
const static vector<int> K;
const static std::vector<std::vector<double>> NakagamiRiceCurves;
const static std::vector<int> K;
};

//
Expand Down
45 changes: 25 additions & 20 deletions include/p676.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#pragma once

#include <vector>
#include <algorithm>
#include <math.h>

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
Expand Down Expand Up @@ -34,31 +39,31 @@ struct RayTraceConfig
class OxygenData
{
public:
const static vector<double> f_0;
const static vector<double> a_1;
const static vector<double> a_2;
const static vector<double> a_3;
const static vector<double> a_4;
const static vector<double> a_5;
const static vector<double> a_6;
const static std::vector<double> f_0;
const static std::vector<double> a_1;
const static std::vector<double> a_2;
const static std::vector<double> a_3;
const static std::vector<double> a_4;
const static std::vector<double> a_5;
const static std::vector<double> a_6;
};

class WaterVapourData
{
public:
const static vector<double> f_0;
const static vector<double> b_1;
const static vector<double> b_2;
const static vector<double> b_3;
const static vector<double> b_4;
const static vector<double> b_5;
const static vector<double> b_6;
const static std::vector<double> f_0;
const static std::vector<double> b_1;
const static std::vector<double> b_2;
const static std::vector<double> b_3;
const static std::vector<double> b_4;
const static std::vector<double> b_5;
const static std::vector<double> 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);
Expand All @@ -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);
Expand Down
14 changes: 11 additions & 3 deletions include/p835.h
Original file line number Diff line number Diff line change
@@ -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 <math.h>

// Define DLLEXPORT for any platform
#ifdef _WIN32
#define DLLEXPORT extern "C" __declspec(dllexport)
#else
#define DLLEXPORT
#endif


//
// CONSTANTS
Expand Down
1 change: 0 additions & 1 deletion src/p528/CombineDistributions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <math.h>
#include "../../include/p528.h"

/*=============================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/p528/FindKForYpiAt99Percent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
Loading