EPIC-model / epic

Elliptical Parcel-in-Cell model for fluid dynamics
https://epic-model.github.io
BSD 3-Clause "New" or "Revised" License
8 stars 1 forks source link

NetCDF environment variables not set #582

Open philrosenberg opened 2 weeks ago

philrosenberg commented 2 weeks ago

When following the installation procedure during the ../configure step I received the error configure: error: No NETCDF_C_DIR environment variable.

Checking the configure script, this environment variable is used to set the default location for the netcdf C library and another similar variable is used to set the default location for the netcdf fortran library.

Neither are set. I was able to work around the configure error for the C directory by adding

--with-netcdf-c=`nc-config --libs | cut -d " " -f 1 | cut -c3-`

to my configure command. Perhaps there is a better way?

This then resulted in a similar error, but for the NETCDF_FORTRAN_DIR environment variable.

It turns out that netcdf fortran was not installed as part of the requirements. It used to be that the fortran and C libraries were packaged together, but that is no longer the case (see https://docs.unidata.ucar.edu/netcdf-c/current/building_netcdf_fortran.html). I installed the fortran package with conda install netcdf-fortran

The equivalent configure argument to get the netcdf-fortran is --with-netcdf-fortran=`nf-config --flibs | cut -d " " -f 1 | cut -c3-`

however this gave me the following error when running the configure script checking for function nf90_open... no checking for function nf90_open in -lnetcdff... no checking whether we can compile a NetCDF Fortran program... no

calling readelf -s /path/to/conda/env/lib/libnetcdff.so | grep open showed that there was no function with the nf90_ prefix, only nf_ prefix, which is the fortran 77 function

The link above indicates that the package can be built with or without f90 support, so perhaps this version is built without. Maybe I need to build fortran netcdf myself or maybe there is some other package

matt-frey commented 2 weeks ago

Even though you can install NetCDF-C and NetCDF-Fortran as part of the conda Python environment, I recommend you install them separately. We have install scripts in https://github.com/EPIC-model/epic/tree/main/dependencies that could give you a starting point. You can export the environment variables NETCDF_C_DIR and NETCDF_FORTRAN_DIR afterwards such that the configure script of EPIC finds your installations. I hope this helps.

philrosenberg commented 2 weeks ago

Ah - I read the manual as either use the scripts or use the conda environment, rather than both.

matt-frey commented 2 weeks ago

We only use the conda environment for our Python plotting and post-processing scripts. It is up to you really. Note that you also need a working MPI installation. I usually use OpenMPI.

philrosenberg commented 2 weeks ago

I tried building the netcdf and hdf5 libraries using the script, but I still get the same error regarding the F90 functions and readelf still shows the f90 functions don't appear to be present in libnetcdff.so

I think I'm stuck at the limit of my fortran/linux library knowledge now

matt-frey commented 2 weeks ago

Just to understand: Could you successfully install HDF5, netCDF-C and netCDF-Fortran? If so, the next steps are

  1. Export the environment variables NETCDF_C_DIR and NETCDF_FORTRAN_DIR. They should point to the root directory of the corresponding netCDF install directory.
  2. Go to the src root directory of EPIC. Type ./bootstrap
  3. mkdir build; cd build
  4. ../configure --enable-verbose --enable-3d --prefix=/path/where/to/install
  5. make
  6. make install
matt-frey commented 2 weeks ago

You should also ensure that you do not configure with the netCDF version of the conda environment. You should probably check the file config.log in the build directory.

philrosenberg commented 2 weeks ago

I have had a further play around and I think the problem might be with the configure script.

on line 16847 there is a line LIBS="-l$lib $LIBS" If I output the value of libs to the screen at that point I get -lnetcdff no I think the no is left over from the first look iteration, where it uses NONE for the library If I replace this line with LIBS=`nf-config --flibs --fflags` then the configure runs to the end.

However, there is a snag. In all the Makefiles I get the include command on a separate line after the LIBS variable is defined.

This causes an error in the Makefile due to the newline. If I go through all the Makefiles and remove the newline, then epic builds. However, I guess these include directories probably shouldn't be in the LIBS variable.

I'm kindof pushing at the boundaries of my knowledge of linux build systems, but maybe you know how to tidy this up properly and make sure the test code at this location gets the correct flags.

matt-frey commented 2 weeks ago

There should be no need for all of this. I think it still finds the conda netCDF installation. Could you ensure this is not happening? Also carefully check config.log.

philrosenberg commented 2 weeks ago

I will have another look when I'm back in the office on Tuesday