Compiling JULES on Ubuntu Intrepid Linux
Thursday, February 5th, 2009I have obtained the source code for JULES which is one of the components that the Met Office uses to forecast the weather. Compiling it was not straightforward and required the modification of several source files.
The modified files and .patch files can be found here.
First I will outline the route I took to the most working binary.
An almost working way
1) in Makefile:
1.1) Setting the location of the netcdf libaries (you will probably need to install these)
JULESDIR=$(PWD)
CDF_LIB_PATH=/usr/lib/
CDF_MOD_PATH=/usr/include/
1.2) and to enable the use of the gfortran compiler
ifeq ($(COMPILER),g95)
include $(JULESDIR)/Makefile.comp.g95
endif
ifeq ($(COMPILER),gfortran)
include $(JULESDIR)/Makefile.comp.gfortran
endif
ifeq ($(COMPILER),nag)
include $(JULESDIR)/Makefile.comp.nag
endif
rather than
ifeq ($(COMPILER),g95)
include $(JULESDIR)/Makefile.comp.g95
endif
ifeq ($(COMPILER),nag)
include $(JULESDIR)/Makefile.comp.nag
endif
2) in Makefile.common.mk:
GRMPATH=$(which grm) ifneq ($(strip $(GRMPATH)),) RM=grm -f endif RMPATH=$(which rm) ifneq ($(strip $(RMPATH)),) RM=rm -f endif ifndef RM $(error No rm equivalent command found) endif
rather than
RM=grm -f
grm means GNU rm, on a linux system rm is GNU rm, so rm should be used rather than grm the conditionals mean that if the met office run the code on their setup it ‘should work’ and if someone runs it on a normal linux distribution it should still work.
cp Makefile.comp.g95 Makefile.comp.gfortran
3) in Makefile.comp.gfortran:
In order to select the gfortran compiler rather than g95, as gfortran is available for Ubutnu/debian while g95 is not.
FC=gfortran -fno-underscoring
rather than:
FC=g95
and
MOD_PUT=-J
rather than:
MOD_PUT=-fmod=
4) Then to compile
make BUILD=run COMPILER=gfortran CDFDUMMY=true
#BUILD could also be debug or fast.
#CDFDUMMY is needed even though you can install netcdf from the repositories – because if you set it false you get:
/home/daniel/dev/JULES/jules-v2-0/libjules.a(RWERR_MOD.o): In function `__rwerr_mod_MOD_rwerr': RWERR_MOD.f90:(.text+0xaae): undefined reference to `__netcdf_MOD_nf90_inquire_dimension' RWERR_MOD.f90:(.text+0xed7): undefined reference to `__netcdf_MOD_nf90_strerror' /home/daniel/dev/JULES/jules-v2-0/libjules.a(JULES_NETCDF.o): In function `__jules_netcdf_MOD_closecdf': JULES_NETCDF.f90:(.text+0xd): undefined reference to `__netcdf_MOD_nf90_close' /home/daniel/dev/JULES/jules-v2-0/libjules.a(JULES_NETCDF.o): In function `__jules_netcdf_MOD_check_nc_dims': JULES_NETCDF.f90:(.text+0x2e1): undefined reference to `__netcdf_MOD_nf90_inq_dimid' /home/daniel/dev/JULES/jules-v2-0/libjules.a(JULES_NETCDF.o): In function `__jules_netcdf_MOD_readvar2dreal_ncvector_gswp2': JULES_NETCDF.f90:(.text+0x566): undefined reference to `__netcdf_MOD_nf90_inq_varid' JULES_NETCDF.f90:(.text+0x8b1): undefined reference to `__netcdf_MOD_nf90_get_var_1d_fourbytereal' JULES_NETCDF.f90:(.text+0xbb9): undefined reference to `__netcdf_MOD_nf90_get_var_1d_fourbytereal' JULES_NETCDF.f90:(.text+0xeed): undefined reference to `__netcdf_MOD_nf90_get_var_1d_fourbytereal' JULES_NETCDF.f90:(.text+0x1160): undefined reference to `__netcdf_MOD_nf90_get_var_1d_fourbytereal' JULES_NETCDF.f90:(.text+0x1477): undefined reference to `__netcdf_MOD_nf90_get_var_1d_fourbytereal' /home/daniel/dev/JULES/jules-v2-0/libjules.a(JULES_NETCDF.o):JULES_NETCDF.f90:(.text+0x178e): more undefined references to `__netcdf_MOD_nf90_get_var_1d_fourbytereal' follow /home/daniel/dev/JULES/jules-v2-0/libjules.a(JULES_NETCDF.o): In function `__jules_netcdf_MOD_opencdf': JULES_NETCDF.f90:(.text+0x1c24): undefined reference to `__netcdf_MOD_nf90_open' collect2: ld returned 1 exit status make: *** [jules.exe] Error 1
Successful compilation should result in:
gfortran -fno-underscoring -o jules.exe /home/daniel/dev/JULES/jules-v2-0/JULES.o \ /home/daniel/dev/JULES/jules-v2-0/UTILS/netcdf_dummy/JULES_NETCDF_DUMMY.o \ -L/home/daniel/dev/JULES/jules-v2-0 -L/home/daniel/dev/JULES/jules-v2-0/UTILS/netcdf_dummy \ -J/home/daniel/dev/JULES/jules-v2-0/MODS -I/home/daniel/dev/JULES/jules-v2-0/MODS -I/home/daniel/dev/JULES/jules-v2-0/UTILS/netcdf_dummy \ -ljules
Alternatively try to use g95 as recommended
1) Install g95
From here: http://www.gfd-dennou.org/library/cc-env/g95/index.htm.en#label-5
g95 is not available in either Ubuntu or Debian repositories – for unknown reasons.
2) follow steps 1.1 and 2 from the instructions for gfortran.
3) try to compile
make BUILD=run COMPILER=g95 CDFDUMMY=true
If you do this there is no possibility of using netcdf prebuilt binaries according to: http://www.unidata.ucar.edu/support/help/MailArchives/netcdf/msg04125.html
This is because they were built for gfortran and so will only work with gfortran.
unfortunately this results in:
g95 -o jules.exe /home/daniel/dev/JULES/jules-v2-0/JULES.o \ /home/daniel/dev/JULES/jules-v2-0/UTILS/netcdf_dummy/JULES_NETCDF_DUMMY.o \ -L/home/daniel/dev/JULES/jules-v2-0 -L/home/daniel/dev/JULES/jules-v2-0/UTILS/netcdf_dummy \ -fmod=/home/daniel/dev/JULES/jules-v2-0/MODS -I/home/daniel/dev/JULES/jules-v2-0/MODS -I/home/daniel/dev/JULES/jules-v2-0/UTILS/netcdf_dummy \ -ljules /home/daniel/dev/JULES/jules-v2-0/libjules.a(SOILHY7A.o):(.data+0x0): undefined reference to `darcy_' /home/daniel/dev/JULES/jules-v2-0/libjules.a(SOILHY7A.o):(.data+0x4): undefined reference to `hyd_con__' make: *** [jules.exe] Error 1
Running Jules
To run jules you will need to
mkdir OUTPUT
after successfully compiling
and then to run a test run using one of the shipped examples:
./jules.exe < point_loobos_example.jin
unfortunately doing this I got:
At line 152 of file SFSNOW7A.f
Fortran runtime error: Array reference out of bounds for array 'snowcanpft', upper bound of dimension 1 exceeded (6 > 5)
Also trying:
./jules.exe < grid_gswp2_example.jin
fails because:
Opening /users/global/rjel/jules/gswp2_files/lsmask_vector.nc
fileFormat=nc
ERROR: attempting to use a netCDF procedure, but netCDF library not available.
This is a 'dummy' procedure.
To use netCDF, remake model with the 'proper' netCDF library.
as we compiled with CDFDUMMY=true …
Conclusion
It is possible to compile JULES on Ubuntu Linux with a bit of work. However compiling a working version of JULES on Ubuntu Linux may be beyond my current ability (I don’t know any FORTRAN).
Hopefully this will help someone.
Thanks as always go to the denizens of #srcf on irc.srcf.ucam.org