From c6d9e9ffdc69fd3b504da77a9ffd1a77cb941b62 Mon Sep 17 00:00:00 2001 From: Henri Menke Date: Thu, 4 Jan 2018 12:29:26 +1300 Subject: [PATCH] Fix compiler warnings --- CMakeLists.txt | 4 ++-- src/wignerSymbols-fortran.cpp | 18 +++++++----------- tests/gh-issue-1.cpp | 5 ++++- tests/gh-issue-2.cpp | 2 +- tests/testWigner.cpp | 8 ++++++-- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5eb5fd3..bd36bb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ endif() # Compiler config enable_language (Fortran) -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -march=native") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -Wextra -Wpedantic -Werror -march=native") # Coverage report option(WITH_COVERAGE "Generate code coverage report" OFF) @@ -25,7 +25,7 @@ if(WITH_COVERAGE) endif() # Included files -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include INC_LIST) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) # Source files aux_source_directory(./src SRC_LIST) diff --git a/src/wignerSymbols-fortran.cpp b/src/wignerSymbols-fortran.cpp index 14b3602..e199186 100644 --- a/src/wignerSymbols-fortran.cpp +++ b/src/wignerSymbols-fortran.cpp @@ -18,17 +18,13 @@ std::vector wigner3j_f(double l2, double l3, double m1, double m2, doubl // We prepare the output values. double l1min, l1max; - double thrcof [size]; + std::vector thrcof(size); int ierr; // External function call. - drc3jj_wrap(l2,l3,m2,m3,&l1min,&l1max,thrcof,size,&ierr); + drc3jj_wrap(l2,l3,m2,m3,&l1min,&l1max,thrcof.data(),size,&ierr); - // We copy the values of the array into a vector. - std::vector thrcof_v(size); - thrcof_v.assign(thrcof, thrcof + size); - - return thrcof_v; + return thrcof; } /*! Computes the Wigner-3j symbol for given l1,l2,l3,m1,m2,m3. We @@ -55,11 +51,11 @@ double wigner3j_f(double l1, double l2, double l3, // We prepare the output values. double l1min, l1max; - double thrcof [size]; + std::vector thrcof(size); int ierr; // External function call. - drc3jj_wrap(l2,l3,m2,m3,&l1min,&l1max,thrcof,size,&ierr); + drc3jj_wrap(l2,l3,m2,m3,&l1min,&l1max,thrcof.data(),size,&ierr); // We fetch and return the value with the proper l1 value. int index = (int)(l1-l1min); @@ -95,11 +91,11 @@ double wigner6j_f(double l1, double l2, double l3, // We prepare the output values double l1min, l1max; - double sixcof [size]; + std::vector sixcof(size); int ierr; // External function call - drc6j_wrap(l2,l3,l4,l5,l6,&l1min,&l1max,sixcof,size,&ierr); + drc6j_wrap(l2,l3,l4,l5,l6,&l1min,&l1max,sixcof.data(),size,&ierr); // We fetch and return the coefficient with the proper l1 value. int index = (int)(l1-l1min); diff --git a/tests/gh-issue-1.cpp b/tests/gh-issue-1.cpp index eaa4ec3..f20a9e8 100644 --- a/tests/gh-issue-1.cpp +++ b/tests/gh-issue-1.cpp @@ -18,7 +18,7 @@ #include -int main (int argc, char* argv[]) +int main () { double test11 = WignerSymbols::wigner3j(325, 999, 1221, 280, 899, -1179); double test12 = WignerSymbols::wigner3j(999, 1221, 325, 899, -1179, 280); @@ -69,6 +69,9 @@ int main (int argc, char* argv[]) std::vector test5 = WignerSymbols::wigner3j(856, 1200, 464, -828, 364); double test51 = WignerSymbols::wigner3j(751, 856, 1200, 464, -828, 364); double test52 = WignerSymbols::wigner3j_f(751, 856, 1200, 464, -828, 364); + std::cout << "C++ impl.: " << test51 << std::endl; + std::cout << "FOR impl.: " << test52 << std::endl; + std::cout << std::endl; /* [ 841 379 1011 -631 313 318] -2.44096504011e-41 -0.0 diff --git a/tests/gh-issue-2.cpp b/tests/gh-issue-2.cpp index 18abc4b..1b47297 100644 --- a/tests/gh-issue-2.cpp +++ b/tests/gh-issue-2.cpp @@ -18,7 +18,7 @@ #include -int main (int argc, char* argv[]) +int main () { double test11 = WignerSymbols::wigner3j(325, 999, 1221, 280, 899, -1179); double test12 = WignerSymbols::wigner3j(999, 1221, 325, 899, -1179, 280); diff --git a/tests/testWigner.cpp b/tests/testWigner.cpp index b256462..29b0532 100644 --- a/tests/testWigner.cpp +++ b/tests/testWigner.cpp @@ -52,6 +52,10 @@ int main(int argc, char* argv[]) timesF.save("timesF.dat",raw_ascii); // Generate values for l1, l2 and derive the rest of the allowed values. + if (argc != 2) { + std::cerr << "Usage: " << argv[0] << " \n"; + return 1; + } double lMax = atof(argv[1]); colvec lVec = linspace(0,lMax,lMax+1); @@ -204,7 +208,7 @@ double seconSumOverL3(double l1, double l2, double l6) double value = (l6==0.0 ? sqrt((2.*l1+1.)*(2.*l2+1.)) : 0.0) ; - double diff = std::fabs(value-sum); + //double diff = std::fabs(value-sum); return std::fabs(value-sum); @@ -229,7 +233,7 @@ double timingWignerSymbolsF(double l2, double l3, double m1, double m2, double m clock_t start = clock(); // We call the subroutine. - double test = WignerSymbols::wigner3j(l2+l3,l2,l3,m1,m2,m3); + WignerSymbols::wigner3j(l2+l3,l2,l3,m1,m2,m3); clock_t end = clock();