1C$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
2C
3C QUADEOSS06
4C
5C$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
6
7 function quadeos06(ic,i,x,y1,y2,y3,x1,x2,x3)
8C 10/20/26 MHP via Claude
9C code changed to replace implicit typing with IMPLICIT NONE and
10C explicit declarations.
11 IMPLICIT NONE
12 REAL*8 C1,C2,C3,QUADEOS06,X,X1,X2,X3,XX,XX12,XX13,XX1PXX2,XX1SQ,
13 * * XX23,Y1,Y2,Y3,YY
14 INTEGER I,IC
15
16c..... this function performs a quadratic interpolation.
17
18 dimension xx(3),yy(3),xx12(30),xx13(30),xx23(30),xx1sq(30)
19 . . ,xx1pxx2(30)
20
21 save
22 xx(1)=x1
23 xx(2)=x2
24 xx(3)=x3
25 yy(1)=y1
26 yy(2)=y2
27 yy(3)=y3
28 if(ic .eq. 0) then
29 xx12(i)=1D0/(xx(1)-xx(2))
30 xx13(i)=1D0/(xx(1)-xx(3))
31 xx23(i)=1D0/(xx(2)-xx(3))
32 xx1sq(i)=xx(1)*xx(1)
33 xx1pxx2(i)=xx(1)+xx(2)
34 endif
35 c3=(yy(1)-yy(2))*xx12(i)
36 c3=c3-(yy(2)-yy(3))*xx23(i)
37 c3=c3*xx13(i)
38 c2=(yy(1)-yy(2))*xx12(i)-(xx1pxx2(i))*c3
39 c1=yy(1)-xx(1)*c2-xx1sq(i)*c3
40 quadeos06=c1+x*(c2+x*c3)
41 return
42 end
1"""Python version of quadeos06.f (YREC 7be4133): quadratic interpolation
2through three points, for the 2006 OPAL equation of state."""
3
4import numpy as np
5
6# The cache of abscissa factors, slots 1..30 (SAVE).
7xx12 = np.zeros(31)
8xx13 = np.zeros(31)
9xx23 = np.zeros(31)
10xx1sq = np.zeros(31)
11xx1pxx2 = np.zeros(31)
12
13
14def quadeos06(ic: int, i: int, x: float, y1: float, y2: float, y3: float, x1: float, x2: float, x3: float) -> float:
15 """The value at x of the quadratic through (x1, y1), (x2, y2),
16 (x3, y3). With ic = 0 the abscissa factors are computed and cached in
17 slot i; otherwise slot i is reused.
18
19 Translates: quadeos06.f#QUADEOS06 (7be4133)
20
21 Returns the interpolated value.
22
23 """
24
25 # The abscissa factors, computed or reused (Fortran lines 22–34).
26 if ic == 0:
27 xx12[i] = 1.0 / (x1 - x2)
28 xx13[i] = 1.0 / (x1 - x3)
29 xx23[i] = 1.0 / (x2 - x3)
30 xx1sq[i] = x1 * x1
31 xx1pxx2[i] = x1 + x2
32
33 # The coefficients and the value (Fortran lines 35–40).
34 c3 = (y1 - y2) * xx12[i]
35 c3 = c3 - (y2 - y3) * xx23[i]
36 c3 = c3 * xx13[i]
37 c2 = (y1 - y2) * xx12[i] - xx1pxx2[i] * c3
38 c1 = y1 - x1 * c2 - xx1sq[i] * c3
39 return c1 + x * (c2 + x * c3)