DIM x(100), y(100), d(1500), g(1500)

SCREEN 9
count = 4: REM Amount of input data
x(1) = 831
y(1) = 30!
x(2) = 1130
y(2) = 21.1
x(3) = 1256
y(3) = 17.2
x(4) = 1538
y(4) = 10!



' Calculate number of step required in output data to
' give a wavelength interval of 1nm"
n1 = x(4) - x(1)

CLS

SCREEN 9: COLOR 15, 1: CLS
LOCATE 10, 20: PRINT "Calculating Responsivity at 1nm intervals"
OPEN "data.txt" FOR OUTPUT AS #1



n = count
e1 = .00001
DIM w(1500), s(1500), h(1500), e(1500)

N2 = x(n) - x(1)
N2 = N2 / n1
N3 = x(1)
FOR I = 1 TO n1
        d(I) = N3
        N3 = N3 + N2
NEXT I

FOR I = 2 TO n - 1
        X1 = x(I)
        X2 = x(I - 1)
        X3 = x(I + 1)
        Y1 = y(I)
        Y2 = y(I - 1)
        Y3 = y(I + 1)
        x = X1 - X2
        h = X3 - X2
        w(I) = .5 * x / h
        T = ((Y3 - Y1) / (X3 - X1) - (Y1 - Y2) / x) / h
        s(I) = 2 * T
        h(I) = 3 * T
NEXT I
s(1) = 0
s(n) = 0
w = 8 - 4 * SQR(3)
up:
u = 0
        FOR I = 2 TO n - 1
                T = w * (-s(I) - w(I) * s(I - 1) - (.5 - w(I)) * s(I + 1) + h(I))
                h = ABS(T)
                IF h > u THEN u = h
                s(I) = s(I) + T
        NEXT I
IF u >= e1 THEN GOTO up
FOR I = 1 TO n - 1
        h(I) = (s(I + 1) - s(I)) / (x(I + 1) - x(I))
NEXT I
IF n1 = 0 THEN GOTO DOWN1
FOR J = 1 TO n1
        I = 1
        T = d(J)
back2:
        I = I + 1
        IF T > x(I) THEN GOTO back2:
        I = I - 1
        h = d(J) - x(I)
        T = d(J) - x(I + 1)
        x = h * T
        s = s(I) + h * h(I)
        Z = 1 / 6
        u = Z * (s(I) + s(I + 1) + s)
        w = (y(I + 1) - y(I)) / (x(I + 1) - x(I))
        g(J) = w * h + y(I) + x * u
        e(J) = w + (h + T) * u + Z * x * h(I)
NEXT J
DOWN1:
I1 = 0
FOR I = 1 TO n - 1
        x = x(I + 1) - x(I)
        I1 = I1 + .5 * h * (y(I) + y(I + 1)) - 1 / 24 * h ^ 3 * (s(I) + s(I + 1))
NEXT I
d(n1 + 1) = x(count): g(n1 + 1) = y(count)


FOR n = 1 TO n1
PRINT d(n), g(n)
PRINT #1, d(n), g(n)

NEXT n
CLOSE #1

