Fortran compilation of solar system code -- netcdf issues

I am trying to compile a fortran solar system 3 body gravity code. The make process hangs with lnetcdff link errors as below:

(base)tom@mydesktop: ~/solar-system-model $ make
make -C osnf
make[1]: Entering directory '/home/tom/solar-system-model/osnf'
gfortran -c   numerics_type.f90 -cpp -DVAR_TYPE=1  -O3  -g -w -o numerics_type.o
gfortran -c   numerics.f90 -O3  -g -w -o numerics.o
gfortran -c   zeroin.f -O3  -g -w -o zeroin.o
gfortran -c   sfmin.f -O3  -g -w -o sfmin.o
gfortran -c   fmin.f -O3  -g -w -o fmin.o
gfortran -c   r1mach.f -O3  -g -w -o r1mach.o  
gfortran -c   d1mach.f -O3  -g -w -o d1mach.o  
gfortran -c   dfsid1.f -O3  -g -w -o dfsid1.o  
gfortran -c   poly_int.f90 -O3  -g -w -o poly_int.o
gfortran -c   find_pos.f90 -O3  -g -w -o find_pos.o
gfortran -c   svode.f -cpp -DDUAL -O3  -g -w -o svode.o  
gfortran -c   slinpk.f -w -O3  -g -w -o slinpk.o  
gfortran -c   vode.f -O3  -g -w -o vode.o  
gfortran -c   dlinpk.f -w -O3  -g -w -o dlinpk.o  
gfortran -c   vode_integrate.f90 -O3  -g -w -o vode_integrate.o  
gfortran -c   erfinv.f90 -O3  -g -w -o erfinv.o
gfortran -c   tridiagonal.f90 -O3  -g -w -o tridiagonal.o
gfortran -c   hygfx.for -O3  -g -w -o hygfx.o 
gfortran -c   random.f90 -O3  -g -w -o random.o
ar  rc osnf_lib.a numerics.o zeroin.o sfmin.o \
    fmin.o r1mach.o \
    d1mach.o dfsid1.o poly_int.o find_pos.o numerics_type.o \
            svode.o slinpk.o vode.o dlinpk.o vode_integrate.o \
            erfinv.o tridiagonal.o hygfx.o random.o
gfortran -c    main.f90 -I /usr/include/ -O3  -g -w -o main.o 
gfortran   -g -O3 -w -o main.exe main.o -lm osnf_lib.a \
        -L/usr/lib/x86_64-linux-gnu/ -I /usr/include/ -lnetcdff  -g
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: cannot find -lnetcdff: No such file or directory
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:32: main.exe] Error 1
make[1]: Leaving directory '/home/tom/solar-system-model/osnf'
make: *** [Makefile:67: osnf_code] Error 2

(base)tom@mydesktop: ~/solar-system-model $

The Makefile for the program has a description for incorporating netcdf libraries that is not clear at all to me. See below:

# these three lines should be edited for your system. On systems 
# that do not have separate fortran and c libraries, set NETCDF_FOR and NETCDF_C
# to the same, and set NETCDF_LIB to -lnetcdf (i.e. without the extra f)

I have netcfd installed. There are about 50 netcfd libraries in openSUSE software repos. I have about 15 installed.
Need an idea of what openSUSE modules to install and what mods to make for configuration in the Makefile to accommodate the openSUSE netcdf install locations.

Any netcdf experts out there? I am also contacting the author but he may not know the intricacies of openSUSE fie structure to be of help.

Any ideas?

@tckosvic an extra f

NETCDF_LIB to -lnetcdf (i.e. without the extra f) <===

NETCDF_LIB=-lnetcdff <===

You might also want to check the ./configure --help to see about prefixes, lib64 prefix etc

Still cannot get netcdf paths to libraries working to allow error-free compilation and linking. I have tried a myriad of paths for netcdf in both make files with no luck. Author talks about netcdf “module” and I am not clear what that means: is it the executibles?
This is what I am working on:

If anyone cares to look at this and offer suggestions for leap 15.5 install, I would like your suggestions.
I have tried user/local installs of netcdf-c and netcdf-fortran to no avail. I also tried on tumbleweed to no avail.

Further comments from author talking about “modules” for netcdf in a readme. Note he says to look at where “modules” are installed. I am trying to find where this location is on openSUSE and what files are needed to be installed. thanks, all

	*you will need to install NETCDF on your system and note the directories where the 
	library and module reside. 
	*in the Makefile change the variables NETCDF_FOR, NETCDF_C and NETCDF_LIB to suit 
	 your system. Sometimes when compiling NETCDF you may have to install both the 
	 fortran and c versions. If you do not need to do this, set NETCDF_FOR and NETCDF_C
	 equal to the same value. 
	*If you install both c and fortran versions, set NETCDF_LIB to -lnetcdff
	*If you only need to install one version, set NETCDF_LIB to lnetcdf
	*Finally, once netcdf is installed and the make file is edited, type "make" to compile
	 the code
        *Note, these variables are commented out in the Makefile. You may set them as environment
         variables in your .bashrc, or .bash_profile and the Makefile will pick them up.
Doxygen pages:
	*self generating documentation (from the source code) can be created by typing
	 "doxygen fortran.dxg" at the command line.
	*you can then view the html pages by opening the file at "doxygen/html/index.html"
Running code:
	*run the code by typing the following:
	* single processor: ./main.exe
Contributing development:
	* at the moment the code is under private repo with no development branches. Contact 
		the code owner to contribute ideas. 

Compilation problem I have been working on as I have found out is due to openSUSE netcdf binaries do not contain netcdf.mod file needed to allow netcdf to link with the fortran code.

A zypper search of all repos shows that this file is not available on openSUSE anywhere. In a rocky linux qemu/libviirt vm that file was available in their netcdf packages and I was able to compile the code very quickly.

Thus, I can never get this code to compile on openSUSE unless netcdf is rebuilt separately from the system binaries. I think openSUSE repos do not have netcdf properly/completely installed.

I will enter this as an openSUSE netcdf bug and see what response I get.

thanks, tom kosvic

@tckosvic It is (well on tumbleweed)…

find /usr/ -name netcdf.mod

netcdf.mod is part of the netcdf-fortran package, code can be found here:

In Tumbleweed it would be provided by one of these:

# zypper se netcdf-fortran
Refreshing service 'openSUSE'.
Loading repository data...
Reading installed packages...

S | Name                                        | Summary                                                            | Type
  | libnetcdf-fortran-gnu-hpc                   | Dependency package for libnetcdf-fortran_4_5_3-gnu-hpc             | package
  | libnetcdf-fortran-gnu-mpich-hpc             | Dependency package for libnetcdf-fortran_4_5_3-gnu-mpich-hpc       | package
  | libnetcdf-fortran-gnu-mvapich2-hpc          | Dependency package for libnetcdf-fortran_4_5_3-gnu-mvapich2-hpc    | package
  | libnetcdf-fortran-gnu-openmpi4-hpc          | Dependency package for libnetcdf-fortran_4_5_3-gnu-openmpi4-hpc    | package
  | libnetcdf-fortran_4_5_3-gnu-hpc             | Shared libraries for the NetCDF scientific data format             | package
  | libnetcdf-fortran_4_5_3-gnu-mpich-hpc       | Shared libraries for the NetCDF scientific data format             | package
  | libnetcdf-fortran_4_5_3-gnu-mvapich2-hpc    | Shared libraries for the NetCDF scientific data format             | package
  | libnetcdf-fortran_4_5_3-gnu-openmpi4-hpc    | Shared libraries for the NetCDF scientific data format             | package
  | netcdf-fortran-gnu-hpc-devel                | Dependency package for netcdf-fortran_4_5_3-gnu-hpc-devel          | package
  | netcdf-fortran-gnu-mpich-hpc-devel          | Dependency package for netcdf-fortran_4_5_3-gnu-mpich-hpc-devel    | package
  | netcdf-fortran-gnu-mvapich2-hpc-devel       | Dependency package for netcdf-fortran_4_5_3-gnu-mvapich2-hpc-devel | package
  | netcdf-fortran-gnu-openmpi4-hpc-devel       | Dependency package for netcdf-fortran_4_5_3-gnu-openmpi4-hpc-devel | package
  | netcdf-fortran_4_5_3-gnu-hpc-devel          | Development files for netcdf-fortran_4_5_3-gnu-hpc                 | package
  | netcdf-fortran_4_5_3-gnu-mpich-hpc-devel    | Development files for netcdf-fortran_4_5_3-gnu-mpich-hpc           | package
  | netcdf-fortran_4_5_3-gnu-mvapich2-hpc-devel | Development files for netcdf-fortran_4_5_3-gnu-mvapich2-hpc        | package
  | netcdf-fortran_4_5_3-gnu-openmpi4-hpc-devel | Development files for netcdf-fortran_4_5_3-gnu-openmpi4-hpc        | package

I do not know which has @malcolmlewis installed.

zypper se -si fortran

S  | Name                               | Type    | Version             | Arch   | Repository
i+ | gcc-fortran                        | package | 13-2.2              | x86_64 | Main Repository (OSS)
i  | gcc13-fortran                      | package | 13.3.0+git8781-1.1  | x86_64 | Main Repository (OSS)
i  | libgfortran5                       | package | 14.1.0+git10173-1.1 | x86_64 | Main Repository (OSS)
i  | libhdf5_fortran200                 | package | 1.12.3-1.1          | x86_64 | Main Repository (OSS)
i  | libhdf5_fortran_1_12_3-gnu-hpc     | package | 1.12.3-1.1          | x86_64 | Main Repository (OSS)
i  | libhdf5hl_fortran200               | package | 1.12.3-1.1          | x86_64 | Main Repository (OSS)
i  | libhdf5hl_fortran_1_12_3-gnu-hpc   | package | 1.12.3-1.1          | x86_64 | Main Repository (OSS)
i  | libnetcdf-fortran_4_5_3-gnu-hpc    | package | 4.5.3-5.3           | x86_64 | Main Repository (OSS)
i+ | netcdf-fortran-gnu-hpc-devel       | package | 4.5.3-5.3           | noarch | Main Repository (OSS)
i  | netcdf-fortran_4_5_3-gnu-hpc-devel | package | 4.5.3-5.3           | x86_64 | Main Repository (OSS)

I am still not finding netcdf.mod available in either leap15.5 or my tumbleweed vm repos.
on leap 15.5:

(base)tom@mydesktop: ~ $ sudo zypper search --provides netcdf.mod
Loading repository data...
Reading installed packages...
No matching items found.

(base)tom@mydesktop: ~ $

on tumbleweed

(base) tom@localhost:~> sudo zypper search --provides netcdf.mod
Loading repository data...
Reading installed packages...
No matching items found.
(base) tom@localhost:~> 

Of course, It is available from the netcdf github because it was properly compiled there.

My alternatives now are to compile netcdf (as user) on leap 15.5 to replicate the netcdf github or use rocky linux vm.

thanks, tom kosvic

@tckosvic what about the find command? Anyway sometimes zypper returns negative results…

Why not compiling from source then and stop worrying?

Get the code for the latest release here:

Download as root, in for instance:

Unpack and untar:
tar -xvf v.6.1.tar-gz

Change directory to the unpacked one:
cd netcdf-fortran-4.6.1 (or whatever it is named)

Configure, make and install:

make install

Do this a root, for example and then it should be available to all users in your system. Or do it in your users home directory, no need for root privileges, and it will be available to you.

Try installing the package (on TW at least) that malcolmlewis indicated he has installed. I tested in a distrobox container with TW, and I installed netcdf-fortran-gnu-hpc-devel and the file was in that package.

In your bugreport is the explanation how to load the fortran bindings…

@tckosvic So you need to source lmod first, then load and should be good to go…

. /etc/profile.d/
module load gnu netcdf-fortran
module list
Currently Loaded Modules:
  1) gnu/13   2) hdf5/1.12.3   3) netcdf/4.9.2   4) netcdf-fortran/4.5.3

Edit Makefile and osnf/Makefile as follows for your file location as this is Tumbleweed;


Thanks for the replies.

On tumbleweed the netcdf.mod package is actually in: netcdf-fortran_4_5_3-gnu-hpc-devel

Sourcing lmod is new to me. I need to research that for a while
I will eventually have all the netcdf packages installed.
I will get over to leap 15.5 in a while.

tom kosvic

@VariableStar, compiling netcdf-fortran is an option as I have expressed. I am finding that the package netcdf.mod is available (but hidden) in the openSUSE repos. It is version 4.5.3 though so compiling new one might not be necessary. If the code I am trying to compile needs a newer version of netcdf.mod, I will follow your instructions. As current version looks to be v4.6.1, I need to make sure, though, that netcdf will not get corrupted by having two versions in root. I will likely try to install into user directories to keep separate.
thanks for assistance

An update: successfully compiled on tumbleweed but code did not compile until I did the lmod commands offered by @malcolmlewi. The compiled code ran successfully for a test.

On leap 15.5, I now have netcdf.mod installed from: netcdf-fortran_4_5_3-gnu-hpc-devel ; same as on tumbleweed.
Running the same lmod commands that worked on tumbleweed do not work as below:

base) tom@mydesktop: ~/solar-system-model $ module load gnu netcdf-fortran
Lmod has detected the following error: These module(s) or extension(s) exist but cannot be loaded as
requested: "netcdf-fortran"
   Try: "module spider netcdf-fortran" to see how to load the module(s).

(base) tom@mydesktop: ~/solar-system-model $ module spider netcdf-fortran

      Command-line programs for the NetCDF scientific data format


  For detailed information about a specific "netcdf-fortran" package (including how to load the modules) use the module's full name.
  Note that names that have a trailing (E) are extensions provided by other modules.
  For example:

     $ module spider netcdf-fortran/4.5.3


(base) tom@mydesktop: ~/solar-system-model $type or paste code here

I am suspecting gnu version problem or fortran version or netcdf-fortran version problem between leap and tumbleweed might be issue.

Again, need your insights and knowledge as I wish to get code going on leap 15.5 as have more ancillary processes on there for post run diagnosis and display. thanks all

Compiling netCDF-fortran is not so straightforward. zlib, hdf4, hdf5, and curl need to be available to the compilation. netCDF-c needs to be installed ahead of netCDF-fortran and perhaps there are some version requirements. for consistency. I think I would need to install a consistent set of all of these in a user directory so as to not mess up system.

You could try running it in Distrobox with a Tumbleweed image. Just a thought if you can’t get it to compile on 15.5.

Right now, with all the help I have received, I can run cases in tumbleweed vm or rocky linux vm. I could move output files from either of them to leap 15.5 for post-run analyses and display by ssh.

I would like to get code running on leap 15.5 to make this a little less complex. But, for all intents and purposes, I guess I could call this solved.