program cfit1 c c -- linear least-squares fit c -- figure 5.1 c integer length, out, max real x(20), y(20) common /inout/ out, max c out = 6 max = 20 10 call input(x, y, length) call output(x, y, length) goto 10 end subroutine input(x, y, n) c -- get values for n and arrays x and y c integer n, out, i, j, max real x(n), y(n), fudge common /inout/ out, max data a/2.0/, b/5.0/ c write(out, 101) read(*,103) fudge if (fudge .lt. 0.0) goto 99 5 write(out, 102) read(*,104) n if (n .gt. max) goto 5 if (n .lt. 0) goto 99 do 10 i = 1, n j = n + 1 - i x(i) = j y(i) = (a + b*j)*(1.0+(2.0*rand(0) - 1.0)*fudge) 10 continue return 99 stop 101 format(/' fudge? ' ) 102 format(' how many points? ' ) 103 format(f10.0) 104 format(i2) end subroutine output(x, y, n) c c -- print out the answers c integer n, out, i real x(n), y(n) common /inout/ out, max c write(out, 101) write(out, 102) (i, x(i), y(i), i = 1, n) return 101 format(' i x y') 102 format(i4, f8.1, f9.2) end