numFort is a numerical library for FORTRAN that includes quadpack, lapack, PLplot and Matplotlib source code. It enables the use of handy mathematical macros such as linspace. I have wasted so much of my life on this nonsense.
You will have to at least install PLplot or Pyplot in order to use one or the other for plotting algorithms or both. You may then comment out the other where specified below at run time.
- Before using numFort, make sure to download the ifort compiler and the necessary math kernel libraries for the use of LAPACK. These may be downloaded from the following link (free for students) Parallel studio XE, click the C++ link unless on mac
- Simply download the custom install, extract to a location and run under sudo privileges like so
# If you wish to install it globally use the below sudo prefix (not necessary)
sudo ./install_GUI.sh
- You may wish to install it locally instead though (hit option 3 i think after typing ./install_GUI.sh)
- Make sure to check the math kernel for install
- After installation you may need to export the path to the ifort compiler. Add code similar to below in your ~/.bashrc. Your exact path for the above libraries might be different (probably just different numbers for 2018.3.222)
source /path/to/intel/bin/compilervars.sh intel64
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/intel/compilers_and_libraries_2018.3.222/linux/mkl/lib/intel64_lin/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/intel/compilers_and_libraries_2018.3.222/linux/compiler/lib/intel64_lin/
- Close and open the terminal to refresh
- Check that it’s working by typing
ifort --version
- Your ifort version should display
Download anaconda from here download link. navigate in the terminal to where the final was downloaded and type the following. For us the title of the file was “Anaconda-latest-Linux-x86_64.sh”
bash Anaconda-latest-Linux-x86_64.sh
follow the prompts and it should install. Say yes to append the path to your .bashrc. If it didn’t add the necessary path in your .bashrc then simply type the following in your .bashrc.
export PATH="/path/to/anaconda3/bin:$PATH"
Try typing
python3.7 --version
If nothing pops up type
conda install python=3.7
This should come with matplotlib, numpy and math. To test this open a python shell with python3.7 and type the following
import matplotlib.pyplot as pypl
import numpy as np
import math as m
as long as no errors pop up you should be fine. Write the following lines in the terminal
cd
mkdir bin
ln -s /path/to/anaconda3/bin/python3.7 ~/bin/python3.7
This will create a symbolic link for python3.7. Add the following to your .bashrc
export PATH=$PATH:~/bin
- Simply run the install file with ./install.sh or bash install.sh (same for the uninstall file). Follow the prompts and you’re good. When using you may use any of the modules listed in the documentation. Copy the makefile template found after installation into your directory with you .f90 file.
- The install will create an example makefile. Simply copy this makefile to your .f90 file and run said commands depending on your plotting needs
- You may also choose to make a bashfile that runs these commands for you to save time e.g.
#!/bin/bash
make all
./program
# Run your perferred plotting
python pyplot.py
# or
python customPlot.py
# simply run this file by typing "chmod +x bashFile.sh" and then "./bashFile.sh"
The four modules you may include are kinds, lapack95 and numFort. Simply include in any .f90 file via a simple use statement as per usual.
program progName
use kinds
use lapack95
use numFort
implicit none
...
end progName
Below we will give short descriptions of the module files and the subroutines and functions contained inside.
Listed variables (some may be optional) and examples of how to call:
Precision parameter file. Main uses are for constants like pi and making variables double precision.
see online lapack documentation for an extensive list on possible linear algebra computations online documentation.
Calculates the factorial of n
Variable | Description |
---|---|
n | integer |
factorial | outputted factorial |
m = factorial(n)
Calculate the value of the 0<n<5 order bessel fucntion at x
Variable | Description |
---|---|
n | integer, order of bessel |
x | real double precision |
bessel | value of the bessel function |
value = bessel(x,n)
Numerically calculates the derivative via a centred finite difference method.
Variable | Description |
---|---|
f | Input function |
x0 | value to calculate |
deriv | value of numerical derivative |
function f(x)
value = deriv(f,x0)
Calculate the trace of a matrix
Variable | Description |
---|---|
M(N,N) | Matrix, SP or DP for real or complex matrices |
Trace | Same type as input matrix |
value = trace(M)
Calculates the inverse of a matrix
Variable | Description |
---|---|
M(N,N) | Matrix, SP or DP for real or complex matrices |
Minv | Inverse of M |
Minv = inv(M)
Creates a unique lattice of points for two given vectors x and y. Usually used for making a 3D grid for 3 dimensional plots.
Variable | Description |
---|---|
x(N) | double precision vector |
y(M) | double precision vector |
XX(M,N) | double precision matrix |
YY(M,N) | double precision matrix |
call meshgrid(x,y,XX,YY)
Calculates the fast Fourier transform
Variable | Description |
---|---|
x(N) | double precision vector |
call FFT(x)
Fits a cubic spline to inputted data. This function can return the coefficients or just a list of desired points to be interpolated at.
Variable | Description |
---|---|
x(N) | double precision vector |
y(N) | double precision vector |
xj(N) | this is the vector x for calculation use |
c(N) | coefficients for spline fit |
x | point to evaluate fit at |
splineval | output values for fit |
c = splinefit(x,y,c)
! should be called after splinefit
value = splineval(c,xj,x)
Exactly the same as SplineFit but for a Nth order polynomial.
Variable | Description |
---|---|
N | integer, order of polynomial |
x(N) | double precision vector |
y(N) | double precision vector |
c(N+1) | coefficient of fit |
c = polyfit(x,y,N)
! Should be called after polyfit
value = polyCal(c,x)
Given a set of values or a function with boundaries, returns the approximate value of where the function changes sign. An index is returned for inputted values method and the x value exactly is returned for the function method.
Variable | Description |
---|---|
f | input function |
fvals | list of y values for a function |
a,b | range for zero guess |
GuessZero | integer index of zero location |
value = guesszero(fvals)
function f(x)
value = guesszero(f,a,b)
Writes variables to a data file which can then be used with customPlot.py to use python to plot (requires numpy and matplotlib)
Variable | Description |
---|---|
x | real double precision |
y | real double precision |
z | real double precision |
w | real double precision |
title | name of the file to load |
! title variable is optional
call writeData(x,y,title)
call writeData(x,y,z,w,title)
Performs a 1 dimensional newtons method to find the zero of a function.
Variable | Description |
---|---|
fn | Input function |
guess | initial guess of zero of the function |
newton1D | zero of function guess location |
function fn(x)
value = newton1D(fn,x)
Performs Eulers method to solve a single or N coupled DE’s, same call notation as rk4
Variable | Description |
---|---|
t0 | initial value to start stepping at |
y0 | initial y value(s) |
f | input function(s) |
h | step size |
nEq | number of coupled equations |
rk4 | output (yn+1) |
function f(t,y)
value = eulerM(f,h,t0,y0)
! In the N DE case, y = y(N),f = f(N), values = values(N)
! i.e. N initial conditions and equations
function f(t,y,nEq)
values = eulerM(f,h,t0,y0)
Performs a 4th order Runge Kutta solving algorithm for a given DE. Algorithms giving for a single DE or N coupled DE.
Variable | Description |
---|---|
t0 | initial value to start stepping at |
y0 | initial y value(s) |
f | input function(s) |
h | step size |
nEq | number of coupled equations |
rk4 | output (yn+1) |
function f(t,y)
value = rk4(f,h,t0,y0)
! In the N DE case, y = y(N),f = f(N), values = values(N)
! i.e. N initial conditions and equations
function f(t,y,nEq)
values = rk4(f,h,t0,y0)
Numerically calculates an integral given a function and bounds. Using Gaussian quadrature.
Variable | Description |
---|---|
f | Input function |
a | left bound |
b | right bound |
absErr | absolute error |
relErr | relative error |
integral | numerical value of integral |
function f(x)
value = integral(f,a,b,absErr,relErr)
Numerically calculates a Cauchy-Principle value integral using Gaussian quadrature. For a given f(x), evaluates the integral of f(x)/(x-c).
Variable | Description |
---|---|
f | Input Function |
c | Pole |
a | Left bound |
b | Right bound |
absErr | absolute error |
relErr | relative error |
integralPV | numerical value of integral |
function f(x)
value = integralPV(f,c,a,b,absErr,relErr)
Creates a linear space of points between a and b with N points.
Variable | Description |
---|---|
start | left bound |
finish | right bound |
N | number of points, integer |
linspace | vector of points between a and b |
vector = linspace(a,b,N)
Prints the computation time after calls for cpu_time
Variable | Description |
---|---|
timeI | Initial time, real(DP) |
timeF | Final time, real(DP) |
call PrintTime(timeI,timeF)
python plotting wrappers, simply copy the makefile and bashFortran.sh files from the InsertCode directory into the necessary directory and then on execution of make all, the necessary plotting files will be created. Use the following commands inside your fortran files (see the bashFortran file to decide whether you wish to use custom plotting or automatic plotting)
Variable | Description |
---|---|
x(N,M) | multi-dimensional array |
x(N) | x values |
y(N) | y values |
xaxis | x axis title (optional) |
yaxis | y axis title (optional) |
legend | legend (optional) |
title | title (optional) |
call pyplot(x,title,xaxis,yaxis,legend)
call pyplot(x,y,title,xaxis,yaxis)
Call PLplot by using the subroutine plot() for example, this will call various wrappers to plplot which can be found within numFort. Below is a list of said wrappers and their arguments. Axes labels and title may be omitted in all below routines if one wishes.
standard x vs y plot or even x1,x2,… vs y1,y2,…
Variable | Description |
---|---|
x(N) | x values |
y(N) | y values |
data(N,M) | multi-dimensional data |
xlabel | x axis title (optional) |
ylabel | y axis title (optional) |
title | title (optional) |
call plot(x,y,xlabel,ylabel,title)
call plot(data,xlabel,ylabel,title)
standard scatter plot
Variable | Description |
---|---|
x(N) | x values |
y(N) | y values |
style | points style e.g. “+” |
xlabel | x axis title (optional) |
ylabel | y axis title (optional) |
title | title (optional) |
call scatterplot(x,y,style,xaxis,yaxis,title)
3D surface plot (goes well with meshgrid)
Variable | Description |
---|---|
x(N) | x values |
y(N) | y values |
z(N,N) | z values |
xlabel | x axis title (optional) |
ylabel | y axis title (optional) |
zlabel | z axis title (optional) |
title | title (optional) |
call surf(X,Y,Z,xlabel,ylabel,zlabel,title)
3D scatter plot.
Variable | Description |
---|---|
x(N) | x values |
y(N) | y values |
z(N) | z values |
xlabel | x axis title (optional) |
ylabel | y axis title (optional) |
zlabel | z axis title (optional) |
title | title (optional) |
call scatter3D(X,Y,Z,xlabel,ylabel,zlabel,title)