From 231a76529d10a6a33a23c1ac9baac6d93654b1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Fri, 10 Apr 2020 23:19:18 +0300 Subject: [PATCH] Quit Fortran dependencies, using own f2c'd version of amos. TODO doc; submodule init needed Former-commit-id: 761fc06adffebb05d28a389243771f0bdde70cc0 --- .gitmodules | 4 ++++ CMakeLists.txt | 24 ++++++++++++++++++++---- amos/camos.h | 30 ++++++++++++++++++++++++++++++ camos | 1 + qpms/CMakeLists.txt | 3 ++- qpms/bessel.c | 20 ++++++++++---------- 6 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 .gitmodules create mode 100644 amos/camos.h create mode 160000 camos diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4230117 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "camos"] + path = camos + url = https://github.com/texnokrates/zbessel.git + branch = purec diff --git a/CMakeLists.txt b/CMakeLists.txt index 84410d3..be4752c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,17 @@ cmake_minimum_required(VERSION 3.0.2) + +option(QPMS_USE_FORTRAN_AMOS "Use the original AMOS Fortran libraries instead of the C ones" OFF) + +if (QPMS_USE_FORTRAN_AMOS) include(CMakeAddFortranSubdirectory) +endif (QPMS_USE_FORTRAN_AMOS) include(version.cmake) include(GNUInstallDirs) project (QPMS) + + macro(use_c99) if (CMAKE_VERSION VERSION_LESS "3.1") if (CMAKE_C_COMPILER_ID STREQUAL "GNU") @@ -22,10 +29,19 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) set (QPMS_VERSION_MAJOR 0) #set (QPMS_VERSION_MINOR 3) -cmake_add_fortran_subdirectory (amos - PROJECT amos - LIBRARIES amos - NO_EXTERNAL_INSTALL) + +if (QPMS_USE_FORTRAN_AMOS) + cmake_add_fortran_subdirectory (amos + PROJECT amos + LIBRARIES amos + NO_EXTERNAL_INSTALL) + set(QPMS_AMOSLIB amos) +else (QPMS_USE_FORTRAN_AMOS) + set(CAMOS_BUILD_STATIC ON) + add_subdirectory (camos) + set(QPMS_AMOSLIB camos) +endif (QPMS_USE_FORTRAN_AMOS) + add_subdirectory (qpms) diff --git a/amos/camos.h b/amos/camos.h new file mode 100644 index 0000000..56304b6 --- /dev/null +++ b/amos/camos.h @@ -0,0 +1,30 @@ +#ifndef CAMOS_H_ +#define CAMOS_H_ +#include "amos.h" + +// TODO what about all the INTEGER_t and DOUBLE_PRECISION_t? + +static inline int camos_zbesh(double zr, double zi, double fnu, int kode, int m, + int n, double *cyr, double *cyi, int *nz) { + int ierr; + amos_zbesh(&zr, &zi, &fnu, &kode, &m, &n, cyr, cyi, nz, &ierr); + return ierr; +} + +static inline int camos_zbesj(double zr, double zi, double fnu, int kode, int n, double *cyr, + double *cyi, int *nz) { + int ierr; + double cwrkr[n], cwrki[n]; + amos_zbesj(&zr, &zi, &fnu, &kode, &n, cyr, cyi, nz, &ierr); + return ierr; +} + +static inline int camos_zbesy(double zr, double zi, double fnu, int kode, int n, double *cyr, + double *cyi, int *nz, double *cwrkr, double *cwrki) { + int ierr; + amos_zbesy(&zr, &zi, &fnu, &kode, &n, cyr, cyi, nz, cwrkr, cwrki, &ierr); + return ierr; +} + + +#endif // CAMOS_H_ diff --git a/camos b/camos new file mode 160000 index 0000000..aafab16 --- /dev/null +++ b/camos @@ -0,0 +1 @@ +Subproject commit aafab167ffb4ed498945518d59fc7042f7a8e527 diff --git a/qpms/CMakeLists.txt b/qpms/CMakeLists.txt index 4a7f0cc..b2ae47b 100644 --- a/qpms/CMakeLists.txt +++ b/qpms/CMakeLists.txt @@ -21,11 +21,12 @@ use_c99() set(LIBS ${LIBS} ${GSL_LIBRARIES} ${GSLCBLAS_LIBRARIES}) + target_link_libraries (qpms gsl lapack blas - amos + ${QPMS_AMOSLIB} ) target_include_directories (qpms PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/qpms/bessel.c b/qpms/bessel.c index b22d4be..000ee49 100644 --- a/qpms/bessel.c +++ b/qpms/bessel.c @@ -7,7 +7,7 @@ #include #include #include "qpms_error.h" -#include +#include #include #ifndef M_LN2 @@ -94,30 +94,30 @@ qpms_errno_t qpms_sph_bessel_fill(qpms_bessel_t typ, qpms_l_t lmax, complex doub else { try_again: ; int retry_counter = 0; - const DOUBLE_PRECISION_t zr = creal(x), zi = cimag(x), fnu = 0.5; - const INTEGER_t n = lmax + 1, kode = 1 /* No exponential scaling */; - DOUBLE_PRECISION_t cyr[n], cyi[n]; - INTEGER_t ierr, nz; + const double zr = creal(x), zi = cimag(x), fnu = 0.5; + const int n = lmax + 1, kode = 1 /* No exponential scaling */; + double cyr[n], cyi[n]; + int ierr, nz; unsigned int kindchar; // Only for error output const complex double prefac = csqrt(M_PI_2/x); switch(typ) { case QPMS_BESSEL_REGULAR: kindchar = 'j'; - amos_zbesj(&zr, &zi, &fnu, &kode, &n, cyr, cyi, &nz, &ierr); + ierr = camos_zbesj(zr, zi, fnu, kode, n, cyr, cyi, &nz); break; case QPMS_BESSEL_SINGULAR: kindchar = 'y'; { - DOUBLE_PRECISION_t cwrkr[lmax + 1], cwrki[lmax + 1]; - amos_zbesy(&zr, &zi, &fnu, &kode, &n, cyr, cyi, &nz, cwrkr, cwrki, &ierr); + double cwrkr[lmax + 1], cwrki[lmax + 1]; + ierr = camos_zbesy(zr, zi, fnu, kode, n, cyr, cyi, &nz, cwrkr, cwrki); } break; case QPMS_HANKEL_PLUS: case QPMS_HANKEL_MINUS: kindchar = 'h'; { - const INTEGER_t m = (typ == QPMS_HANKEL_PLUS) ? 1 : 2; - amos_zbesh(&zr, &zi, &fnu, &kode, &m, &n, cyr, cyi, &nz, &ierr); + const int m = (typ == QPMS_HANKEL_PLUS) ? 1 : 2; + ierr = camos_zbesh(zr, zi, fnu, kode, m, n, cyr, cyi, &nz); } break; default: