I have tried to implement a spline type subroutine. It correctly takes data from my text file (17x2 matrix), I write the following subroutine (provided by chatgpt, I’m just starting to program).
C gL
DO i=1,N
r_val=r_1(i)
idx=1
min_diff=ABS(r_val - matrizB(1,1))
DO iB=2,NB
diff=ABS(r_val - matriz(iB,1))
IF (diff< min_diff) THEN
idx=iB
min_diff = diff
END IF
END DO
CALL CUBIC_INTERPOLATION (r_val, matrizB(idx-1,1), matrizB(idx,1), matrizB(idx-1,2), matrizB(idx,2),h)
interpolated_values(i)=h
END DO
SUBROUTINE CUBIC_INTERPOLATION(x,x0,x1,y0,y1,h)
REAL, INTENT(IN) :: x,x0, x1, y0, y1
REAL, INTENT(OUT) :: h
REAL :: t, t2, t3
t = (x -x0)/(x1-x0)
t2=t*t
t3=t2*t
h =y0*(2*t3 - 3*t2+1) + y1*(-2*t3+3*t2)+(y1-y0)*(t3-2*t2+t)
END SUBROUTINE CUBIC_INTERPOLATION
This is only the problem part of my extensive fortran program.
And finally I make a call to the subroutine to create me a vector of 58 elements from another of the same dimension.
EDIT: I’ve trying some other interpolation, and this version is the one with less errors. I think a spline or a cubic interpolation could work. This is my data (Tabla2.txt):
0.00 1.010
0.10 1.010
0.15 1.018
0.25 1.030
0.50 1.030
0.75 1.020
1.00 1.000
1.50 0.937
2.00 0.857
3.00 0.689
4.00 0.538
5.00 0.409
6.00 0.313
7.00 0.232
8.00 0.176
9.00 0.134
10.00 0.0957
EDIT 2: Following the recommendation vmagnin, I’ll provide error message:
prueba2.f:358:72:
358 | CALL CUBIC_INTERPOLATION (r_val, matrizB(idx-1,1), matrizB(idx,1), matrizB(idx-1,2), matrizB(idx,2),h)
| 1
Error: Invalid form of array reference at (1)
What I expect. I expect to obtain a interpolation of Tabla2.txt, then create a array g_l what take every element of r_1(58 elements) and give me the array g_l(58 elements)
** I’m using Windows 11 GNU Fortran (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders) 12.2.0