HOME | DOWNLOAD | DOCUMENTATION | FAQ |
> Home > Documentation
Using SHTOOLS with Fortran 95
Calling SHTOOLS routines
To access the SHTOOLS functions and subroutines in your code, it is necessary to place the statement
use SHTOOLS
directly after the program, subroutine, or function declaration (i.e., before an implicit none statement). The SHTOOLS module contains an interface block that declares the subroutines and functions used in this archive and allows for the use of implicitly shaped arrays. It should be noted that all arrays passed to a subroutine or function can be larger than that specified in the documentation.
Linking to the SHTOOLS library
When compiling a code that references SHTOOLS, it will be necessary to link to the SHTOOLS library and module files. For this purpose, it may be useful to define the environment variables SHTOOLSMODPATH and SHTOOLSLIBPATH using the default file locations. For a C-shell login file, this is accomplished using
setenv SHTOOLSLIBPATH = "/usr/local/lib"
setenv SHTOOLSMODPATH = "/usr/local/include"
whereas for a bash shell, the syntax is
export SHTOOLSLIBPATH = "/usr/local/lib
export SHTOOLSMODPATH = "/usr/local/include"
In addition, some routines require linking to the fast Fourier transform package FFTW, and linear algebra packages LAPACK and BLAS. Typical examples of compiling and linking a program "MyProgram.f95" to the necessary library and module files are the following:
gfortran
gfortran MyProgram.f95 -I$SHTOOLSMODPATH -L$SHTOOLSLIBPATH -lSHTOOLS -lfftw3 ‑lm -llapack -lblas -O3 -m64 -o MyProgram
Absoft Pro Fortran
f95 MyProgram.f95 -p $SHTOOLSMODPATH -L$SHTOOLSLIBPATH -YEXT_NAMES=LCS ‑YEXT_SFX=_ -lSHTOOLS -lfftw3 -lm -llapack -lblas -O3 -m64 -o MyProgram
g95
g95 MyProgram.f95 -I$SHTOOLSMODPATH -L$SHTOOLSLIBPATH -fno-second-underscore ‑lSHTOOLS -lfftw3 -lm -llapack -lblas -O3 -m64 -o MyProgram
Intel Fortran ifort
ifort -free -I$SHTOOLSMODPATH -L$SHTOOLSLIBPATH -lSHTOOLS -lfftw3 -lm -llapack -lblas -O3 -m64 -Tf MyProgram.f95 -o MyProgram
Note that the position of the source file in the above examples might be important for some compilers. It may be necessary to modify some options in order to properly link to both the LAPACK and FFTW libraries (see Compilation Instructions for more details). If the library ATLAS exists on your system, this could be used instead of BLAS.
To use the SHTOOLS library with OpenMP, the library name libSHTOOLS.a in the above examples would need to be replaced by libSHTOOLS-mp.a. Furthermore, it would be necessary to add the compiler option to use OpenMP:
-fopenmp (gfortran)
-openmp (Absoft Pro Fortran)
Fortran array indices
Fortran arrays usually start with an index of 1. However, with spherical harmonic functions and coefficients a degree-0 term exists. In order to deal with this, all arrays that are a function of spherical harmonic degree l and order m have 1 added to each of these indices. For instance, the real Fortran array cilm is related to the spherical harmonic coefficients by

In this notation, c1lm and c2lm refer to the "cosine" and "sine" coefficients, respectively (see Real Spherical Harmonics).
Using optional parameters
Many of the subroutines and functions in this archive can accept one or more optional parameters. To specify these parameters, it is only necessary to use the following syntax,
call SHRead (FILENAME, CILM, LMAX, SKIP=1, ERROR=errorcoef)
where SKIP and ERROR are the names of two optional parameters, and the constant 1 and variable errorcoef are their respective arguments.
Documentation
Documentation for the Fortran 95 subroutines and functions in SHTOOLS can be accessed by their unix man pages, using all lower case letters. As an example, to access the MakeGridDH man page, use
man makegriddh
Alternatively, the man pages can be accessed from the documentation link on this web site.
> Home > Documentation
Institut de Physique du Globe de Paris | University of Sorbonne Paris Cité | © 2016 SHTOOLS |