Re: Reading data
- From: "Beliavsky" <beliavsky@xxxxxxx>
- Date: 30 Dec 2006 15:21:29 -0800
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?
.
- References:
- Reading data
- From: hhu
- Reading data
- Prev by Date: Reading data
- Next by Date: Re: allocation error
- Previous by thread: Reading data
- Next by thread: Re: Reading data
- Index(es):
Relevant Pages
|