From 48ff7f9c3bdf7de69a76a450e2e1a9e9fc9bc308 Mon Sep 17 00:00:00 2001 From: Stefano Carrazza Date: Wed, 15 Nov 2023 12:55:37 +0100 Subject: [PATCH] further improvements --- capi/examples/fortran/example.f90 | 12 ++++++++++-- capi/examples/fortran/pdfflow_f_interface.c | 10 +++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/capi/examples/fortran/example.f90 b/capi/examples/fortran/example.f90 index 957894f..afe4542 100644 --- a/capi/examples/fortran/example.f90 +++ b/capi/examples/fortran/example.f90 @@ -7,7 +7,8 @@ program example integer, parameter :: dp = kind(1.d0) integer :: pid(0:10), i - real(dp) :: alpha_s, q2(0:1), x(0:1), xfx(0:10) + real(dp) :: alpha_s, q2(0:1), x(0:1), xfx(0:11) + real(dp) :: q2_vectorized(0:2), as_vectorized(0:2) character(kind=c_char, len=21) :: ss = "NNPDF31_nlo_as_0118/0" character(kind=c_char, len=24) :: pp = "/usr/share/lhapdf/LHAPDF/" @@ -26,7 +27,14 @@ program example write(*, fmt=200)"Flavour: ", i - 5, " value: ", xfx(i) enddo -100 format (A, F6.2, A, F4.2) + q2_vectorized(0) = 1.65 + q2_vectorized(1) = 10.65 + call alphasq2(q2_vectorized, 2, as_vectorized); + + write(*, fmt=100)"alphas(q2=",q2_vectorized(0),") = ", as_vectorized(0) + write(*, fmt=100)"alphas(q2=",q2_vectorized(1),") = ", as_vectorized(1) + +100 format (A, F10.7, A, F10.7) 200 format (" ", A, I0, A, F10.7) end program diff --git a/capi/examples/fortran/pdfflow_f_interface.c b/capi/examples/fortran/pdfflow_f_interface.c index 9b9a7fb..234fcc2 100644 --- a/capi/examples/fortran/pdfflow_f_interface.c +++ b/capi/examples/fortran/pdfflow_f_interface.c @@ -15,10 +15,14 @@ void mkpdf_(const char *fname, const char *dirname) { mkpdf(fname, dirname); } -void alphasq2_(double *q2, int *n, double *alphas) { - alphas = alphasq2(q2, *n); +void alphasq2_(double *q2, const int *n, double *alphas) { + double *as = alphasq2(q2, *n); + for (int i = 0; i < *n; i++) + alphas[i] = as[i]; } void xfxq2_(int *pid, const int *n, double *x, const int *m, double *q2, const int *o, double *f) { - f = xfxq2(pid, *n, x, *m, q2, *o); + double *xf = xfxq2(pid, *n, x, *m, q2, *o); + for (int i = 0; i < *n * *m * *o; i++) + f[i] = xf[i]; }