Re: Reading data




hhu wrote:
Hi,

I am new to Fortran. Tried to write an OLS regression using the
following data:
12 39
10 42
6 33
15 43
8 35
13 35
11 33
16 44
12 37
9 34

PROGRAM REGRESSION
PARAMETER (M=10)
INTEGER I, N
REAL Y(M), X(M), ALPHA, BETA
REAL YSUM, XSUM, YXSUM, XXSUM
OPEN (UNIT=6,FILE='EXAMPLE2.CSV')
OPEN (UNIT=7, FILE='OUTPUT.DAT')
N=M
DO 10, I=1,N
READ (6, *) Y(I), X(I)
10 CONTINUE
CALL LSTSQR (Y, X, N, ALPHA, BETA)
WRITE (7, 200), ALPHA, BETA
200 FORMAT(/5X, 'ALPHA IS', F7.3,/
5X, 'BETA IS', F7.3)
STOP
END
SUBROUTINE LSTSQR(Y, X, N, A, B)
PARAMETER (M=10)
INTEGER N, I
REAL Y(M), X(M), A, B
REAL YSUM, XSUM, YXSUM, XXSUM
XSUM=0.0
YSUM=0.0
YXSUM=0.0
XXSUM=0.0
DO 10, I=1, N
XSUM=XSUM+X(I)
YSUM=YSUM+Y(I)
YXSUM=YXSUM+X(I)*Y(I)
XXSUM=XXSUM+X(I)**2
10 CONTINUE
A=(XSUM*YSUM-N*XYSUM)/(XSUM**2-N*XXSUM)
B=(YSUM-A*XSUM)/N
RETURN
END

The error was:

list in: end of file
apparent state: unit 6 named EXAMPLE2.CSV
last format: list io
lately reading direct formatted external IO
Aborted

Is there an end-of-line (EOL) character on the last line of the data
file? Some compilers cannot read from a line with a missing EOL. For
what value of I does the READ fail?

Separate comment, for a new Fortranner who appears to writing in
Fortran 77 (F77). Why are you restricting yourself to F77?

.



Relevant Pages

  • Re: Is it time to legitimise REAL*8 etc?
    ... Some vendors phased out their F77 compilers over 10 ... No need to support a seperate F77 compiler as, ... experience with F77) that the F95 programming is safer than the F77 ... Authors are not chosing more recent Fortran ...
    (comp.lang.fortran)
  • Re: Searching zeros of complex function
    ... But I have to find the value of beta that makes det=0. ... The strategy for finding the zeros, ... I have a fortran routine based in Muller's ... Method for complex functions that I used some time ago for a complex ...
    (comp.lang.fortran)
  • Re: Should I Start With Fortran77 of Fortran90/95?
    ... have read that the most common standard at the current time is Fortran ... There are a lot of areas in which F77 is quirky and more difficult to ... spend a fair amount of time learning its quirks and their workarounds. ...
    (comp.lang.fortran)
  • Re: Is it time to legitimise REAL*8 etc?
    ... Some vendors phased out their F77 compilers over 10 ... No need to support a seperate F77 compiler as, ... experience with F77) that the F95 programming is safer than the F77 ... COMMONs remain available with any FORTRAN version. ...
    (comp.lang.fortran)
  • Re: Fortran vs Python - Newbie Question
    ... development of Fortran and does a good job of summarizing the problems ... special purpose tool that manages large numerical arrays ... F77 interfaces smoothly and neatly with Python. ...
    (comp.lang.python)