Fortran API Example
The following examples illustrate how to use the Fortran interface to the
NeoPDF
library and to evaluate distributions.
Prerequisites
Build and install the C API as described in the installation guide.
Then, copy the neopdf_fapi/neopdf.f90
in the working directory and include it in the
compilation. The following is an example of Makefile:
FC = gfortran
FFLAGS = -Wall -Wextra -O0 -g -ffree-line-length-none
NEOPDF_LIBS != pkg-config neopdf_capi --libs
LHAPDF_LIBS != pkg-config lhapdf --libs
PROGRAMS = check-fapi
all: $(PROGRAMS)
test-examples: $(PROGRAMS)
set -e && for i in $(PROGRAMS); do ./$${i} > output; diff -u $${i}.output output; done; rm output
neopdf.o: neopdf.f90
$(FC) $(FFLAGS) -c $< -o $@
check-fapi: check-fapi.f90 neopdf.o
$(FC) $(FFLAGS) $< neopdf.o $(LHAPDF_LIBS) $(NEOPDF_LIBS) -o $@
check-lazy-fapi: check-lazy-fapi.f90 neopdf.o
$(FC) $(FFLAGS) $< neopdf.o $(NEOPDF_LIBS) -o $@
check-writer-fapi: check-writer-fapi.f90 neopdf.o
$(FC) $(FFLAGS) $< neopdf.o $(NEOPDF_LIBS) -o $@
.PHONY: clean
clean:
rm -f *.o *.mod $(PROGRAMS)
Example 1: Loading and Evaluating PDFs
This example demonstrates the use of the NeoPDF
Fortran API to load a single PDF
member, evaluate parton distributions for a range of \(x\) values, and compare the
results to LHAPDF.
The above code would print the following results:
--------------------------------------
x LHAPDF NeOPDF
--------------------------------------
5.000E-02 2.35826E+00 2.35826E+00
1.500E-01 6.21341E-01 6.21341E-01
2.500E-01 2.34180E-01 2.34180E-01
3.500E-01 1.00192E-01 1.00192E-01
4.500E-01 3.86353E-02 3.86353E-02
5.500E-01 1.14658E-02 1.14658E-02
6.500E-01 2.41062E-03 2.41062E-03
7.500E-01 3.15737E-04 3.15737E-04
8.500E-01 1.94082E-05 1.94082E-05
9.500E-01 1.35325E-07 1.35325E-07
--------------------------------------
Example 2: Loading PDF Members in Lazy Mode
The following example illustrates how to load all the PDF members lazily. This presents some advantages in terms of speed and memory efficiency. However, the cost is delegated to when the interpolation is computed an usually loading the entire PDF members in eager mode when peforming evaluations on the members is generally much faster.
Example 3: Filling and Writing a NeoPDF Grid
The following example illustrates how to fill, write, and compress NeoPDF
grids using the
Fortran API.
The filling of the PDF grid in the following example assumes no dependence in the nucleon numbers \(A\) and strong coupling \(\alpha_s\) (ie. standard LHAPDF-like PDF). Refer to the C++ tutorials in the case the grid should explicitly depend on more parameters.
NOTE
The following example fills the NeoPDF
grid by re-computing the values of the subgrids
from an LHAPDF set. This makes it possible to explicitly check that the filling of the grid
is correct. However, this makes the codes very verbose. To easily spot the parts that
actually fills the grid, some lines are highlighted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|