Fortran stdlib: sufficient for scientific programming?

hijacking this thread a little bit for a very small question regarding the stdlib; I am a fan of reducing the number of warnings in the code and I was thinking on going through the stdlib and trying to fix most of the warnings. Would this be a worthy/welcome addition?

2 Likes

I have setup on my personal and work computers both: Intel compilers with oneAPI and the GNU suite (gcc/gfortran) through the equation.com installers (Fortran, C, C++ for Windows) … msys2 is also a very good option, just don’t forget to add the path to the binaries to your environment variables in order to have the compilers accessible from any Terminal.

Having the compilers already set, my preferred way to use stdlib is through fpm using a local dependency with any other project. And for editors, my favorite is VSCode+ModernFortran plugin (which can also handle fypp). One can easily install fpm with PowerShell using winget:

winget install FortranLang.fpm

Then, I create a local folder for my fortran (fpm-ized) projects, among which is stdlib. In PowerShell git comes now integrated, so from the same PS terminal:

cd D:\my_fortran_path
git clone https://github.com/fortran-lang/stdlib.git

Create some project in the same folder and open with VSCode:

fpm new my_project
cd my_project
code .

In the fpm.toml, add stdlib as a dependency using your locally downloaded version fpm local dependencies:

[dependencies]
stdlib = { path = "../stdlib" }
3 Likes

There was a PR recently in this direction Fix warnings [-Wunused-xxx] from compilation by cyrilgandon · Pull Request #879 · fortran-lang/stdlib · GitHub

My only comment would be: while yes, it is a bit annoying to have a lot of warnings while compiling, not all warnings are actual problems. Some are actually best left alone. For instance, there are some procedures written as functions that require a mold variable just for the sake of enabling the compiler to disambiguate the kind. This variable not being actually used, will pop a warning. Adding a fake use of the variable is just artificial and prone to errors.

In other cases, the warnings are legitimate points of attention that can lead to improvements.

So yes, your help on that I think would be very welcomed, just some words of attention for you not to set a hard goal on eliminating every single warning.

1 Like

yeah like for example, do we want to fix the -Wcompare-reals ? thanks for the link, I’ll look at what I can do :slight_smile:

3 Likes

Thanks @jorgeg and everyone, great to see that there is growing interest in algebra from stdlib! This is what I’ve been using according to suggestions arisen in past discussions here on Discourse:

However, as @hkvzjal is suggesting, please be careful changing the behavior of the LAPACK library as that may have unintended consequences!

2 Likes

It’s very impressive to use stdlib, and I am slowly learning. Can anyone point me to how I can point stdlib to the local folder (say c:\stdlib_src) instead of

stdlib = { git=“GitHub - fortran-lang/stdlib: Fortran Standard Library”, branch=“stdlib-fpm” }?

Like this :point_up_2: fpm uses a relative path to the fpm.toml of the current project, so you should adapt to where stdlib is with respect to your project. In the example I assumed both being at the same folder hierarchy level.

1 Like

I am sorry, its not working and throwing error ( cmd_build Model error: ‘...\D:\Fortran_lib\stdlib\fpm.toml’ could not be found, check if the file exists
STOP 1) as I am keeping fortran library at D:\Fortran_lib\stdlib and main.f90 is at desktop.

In addition to my previous comment, I would like to highlight one web-link that is a bit absolute but useful as it shows table for the Fortran with similar code for Python, and Matlab.

(Numerical Analysis Software: Fortran, MATLAB, R, NumPy - Hyperpolyglot)

Could you share how you wrote your fpm.toml file for your current project?

Following is my fpm.toml file for my current project

name = “st”
version = “0.1.0”
license = “license”
author = “Bhanu”
copyright = “Copyright 2024, Bhanu”
[build]
auto-executables = false
auto-tests = true
auto-examples = true
[install]
library = false
[fortran]
implicit-typing = false
implicit-external = false
source-form = “free”
[dependencies]
stdlib = { path= “D:/Fortran_lib/stdlib” }

Try making the pathname relative, starting with … or make a link to it in the project area and change the path to point to the link. Not sure if it works as well on MSWindows but I find that if I make one directory that is nothing but soft links to all the dependent projects (which I call LINKS) then in projects that use those projects put a softlink to LINKS in the project and then use path=“LINKS” that works well for off-line use but still lets the projects be placed
anywhere on the system.

Another possibility is to build stdlib and do a “fpm install” and use stdlib as a conventional external library instead.

From the manual (note “relative pathname” and “/ separator on all platforms”

Local dependencies

To declare local dependencies use the path entry.

[dependencies] my-utils = { path = “utils” }

The local dependency path is given relative to the fpm.toml it is written to, and uses / as the path separator on all platforms.

In your toml file you are declaring stdlib location using an absolute path, fpm requires relative paths from the current toml file. Also, even if on windows use “/” instead of " \ ".

Last thing, make yourself a favor, do not work from your desktop folder. If you have a D drive, place your projects under that drive. It’ll make your life easier in the future (not a Fortran or fpm issue, just general good practice)

So say stdlib is in:
“D:\Fortran_lib\stdlib” and your project in “D:\my_projects\hello_fpm”

From your fpm.toml you should write in your dependencies path for stdlib something like: “…/…/Fortran_lib/stdlib” (go up two levels then go down two)

1 Like

Can I use stdlib along with lapack/blas? Also, how can I compile code with stdlib in a Windows environment using code::block (as it seems it is the only IDE I can use efficiently)?

If you downloaded the latest released version it already has blas and lapack, so you have two options: use stdlib internal versions of blas/lapack or link against an external library containing them, say intel MKL. Both are possible, the 1st one is the default, so nothing to do, the second one requires activation of two macros. which one are you trying to use?

Regarding the IDE, I use VSCode with the Modern Fortran plugin + fortls and it works just about right for me. I also use Microsoft Vosual Studio, but the linter is not as nice as with VSCode.

If you wanna add Fortran graphical library into your Fortran code you can do it too. The library Dislin is written in Fortran and is freely available.

Here you can find the windows Installation Guide

and some examples

1 Like