Help with levin2d & fpm & stdlib

Dear all,

I’m lost little bit in various options & general picture.

What I need: I want to use Levin integration method for a rapidly oscillating function. This is for Henkel-Bessel integral for a diffraction problem, Eq. 4 from Aime (2020) (some years ago I already implemented it using Lommel series & numerical integration; now I want it faster).

There exist Levin method for such types of integrals, with a realization here. They provide a makefile, which after some efforts I managed to compile. I need 1D integral which is provided by levin.f90, which relies on provided utils.f90; linalg0.f90; chebyshev.f90; chebpw.f90 (all provided); but then during linking it requires also dgeem (or something from BLAS/LAPACK)

I thought it’s time to try to learn something new for me, trying to check out fpm and stdlib. If I understand correctly, in an ideal case everything missing will be downloaded & complied & path’s automatically. I just need to create a manifest … with which I’m currently struggling.

Is it correct?

Now I have fpm installed, the first example from the manual works. But not further :slight_smile:

Should I install stdlib separately system-wide? How to specify in the manifest that I just need few files to be compiled? (if I’m correct, there are some missing files). I actually need levin.f90 …

name = "levin2d"
version = "0.1.0"
license = "license"
author = "Murdock Aurby"
maintainer = "murdock-aurby@email.com"
copyright = "Copyright 2026"

[library]
source-dir="./"
build-script="make with options?"

Thanks in advance for help & suggestions.

Maybe the discussions in this thread can come in handy with respect to your needs:

you could start testing using stdlib as a meta-package with the stdlib = "*" declaration in the dependencies of your manifest, and if you are happy, then go for a local registry or system-wide installation. All options are possible, for prototyping maybe the first is faster.

Have you tried adding

[build]
link = ["blas", "lapack"]

to your toml file?

Well, yes/no. No, I did not put this line to my toml file; but it looks if I remove levin dependency from my project and keep stdlib, the latter appears there in dependencies with its BLAS/LAPACK implementation/interfaces.

What is the problem in my case (I think) is that I can not compile the levin “library” with fpm. If I try to compile it separately (not from within my project) with fpm it fails for several reasons: there are clearly some missing files, thus all the included f90 files can not be compiled. I have not figured out how to specify to fpm that only some files need to be compiled. Second, when I modify its own makefile (I need only levin.f90, which depends only on few others - utils.f90, linalg0.f90, chebyshev.f90) I can get modules and *o files; but when I manually try to link levin.o to my program, it turns out it requires BLAS/LAPACK. Which I did not specify, because I thought initially it would be done by fpm.

So I’m not sure if fpm is capable of compiling just few files from a repository (please point if it’s written somewhere) and if I still should use fpm

I checked your code and here are some observations that should help you:

  • put all the source files in a src/ folder
  • put the test files in a test/ folder
  • your code is missing the ‘legendre’ module
  • I noticed that you are using implicit integer and implicit double precision. While this is not recommanded, if you want to keep it, you can declare once ‘implicit double precision (a-h,o-z)’ at the module level (rather than per function) and you should add ‘implicit integer(i-n)’ at the module level too.

Once done, the fpm.toml file at the root of your repo should look like this

name = “levin2d”
version = “0.1.0”
license = “license”
author = “Murdock Aurby”
maintainer = “murdock-aurby@email.com”
copyright = “Copyright 2026”

[build]
link = [“blas”, “lapack”]


David, thanks for checking out!

UPDATE: I’ve found legendre.f90 from the original authors, now I can build the static library with additional

[fortran]
implicit-external = true # default: false
implicit-typing = true # default: false

in the manifest.

***********************************************************************************************

I’m afraid however, your suggestions do not work immediately for me.

First, it’s not my package; it’s clear I will need to do some modifications, but I would like to limit them to minimum. So, there was no legendre module on git and I was not able to find something, that can be immediately used for the whole package. Thus the whole package could not be assembled with the toml you propose. (the message cmd_build Target error: Unable to find source for module dependency: “legendre” used by “././src/adapgauss2d.f90” )

However, the module levin, which I need, depends on a smaller number of files that are present and on dgeev from BLAS. I was not able to figure out if it is possible to compile just some files using fpm; thus I modified by hand the makefile and after some efforts managed to compile levin.o (may be I should have stick with fpm).

Third, during the compilation I was struggling to link against BLAS for quite some time. I compiled/installed stdlib separately (using fpm) and it was installed into ~/.local (libstdlib.a in .local/lib; modules in .local/include). However, on all my efforts to link against libstdlib.a (-lstdlib -L/home/sergeis/.local/lib/ or similar combinations) the linker it was complaining:

chebyshev.o: in function __chebyshev_MOD_chebyshev_roots': chebyshev.f90:(.text+0x8245): undefined reference to dgeev_’

(do I need to modify dgeev to stdlib_dgeev in chebyshev.f90? I tried, it did not seem to work)

Finally, I’ve installed system-wide OpenBLAS, and now with -lblas -llapack -flto -L/usr/lib/x86_64-linux-gnu/openblas-pthread/ to the linker I can compile levin.o

But may be I should do it in a different way? Thanks for help!