
This command instructs Fortran to read the next line in the file numbered 7, but to jump to the statement labelled 10 in the program in the event that the last line in that file has already been read. You can also use format specifiers in read statements, but this can be somewhat tedious and we will not go into the details.
Here's my problem: I don't know in which way I have to change these lines, to get a program which doesn't skip into the next line after the first value that has been readed. Any line should be read till its end and contemporary the values should be counted. Here are the lines: DO READ (10,., IOSTAT = fehler) zahl IF (fehler 0) THEN summe = summe + zahl n = n + 1 ENDIF IF (fehler /= 0) EXIT ENDDO I want to read a file which looks for example like this: 3.5 7.9 30.5 21.3 2.9 3.7 2.8 3.7 4.1 3.2 19.8 210.7 (blanks between the values and no fixed format/size) Thank you very much for any support! RE: How to read values line by line AND count them? Or just read it here.;) PROGRAM mittelwert! Variablen-Deklaration IMPLICIT NONE REAL:: zahl, summe, mittw CHARACTER (LEN = 128):: datnam INTEGER:: i, n, fehler integer:: ii, jj, k character.80:: line! The line buffer integer, parameter:: linemax=50!
Max on a line real:: val(linemax)! Initialisierung n = 0 summe = 0.0! Startmeldung call system ('cls') PRINT.
PRINT., 'Dieses Programm liest Zahlen aus einer Datei ein' PRINT., 'und berechnet anschliessend den Mittelwert.' Beginn Schleife - Datei oeffnen DO! Eingabe des Dateinamens WRITE (., '('Geben Sie den Dateinamen ein: ')', advance='no') READ (., '(A)') datnam! Datei oeffnen OPEN (10, FILE = datnam, STATUS = 'OLD', IOSTAT = fehler)! Fehlermeldung, wenn Datei nicht existiert IF (fehler /= 0) PRINT., 'Datei existiert nicht!' IF (fehler 0) EXIT END DO!
Ende Schleife - Datei oeffnen! Datei bis zum Ende lesen und Summe berechnen DO!


Read a line into memory read (10, '(A)', end=999) line do k=1,linemax,1 val(k)=-1E12 end do! Read value from the line read (line,., end=888) (val(ii), ii = 1, linemax) 888 continue do jj = 1, ii-1 if (val(jj).ne.-1E12) summe = summe + val(jj) if (val(jj).ne.-1E12) n = n + 1! Alte Werte werden nicht mitgezaehlt end do END DO 999 continue! Datei schliessen CLOSE (10)! Mittelwert berechnen mittw = summe / n! Ausgabe der Ergebnisse PRINT.
WRITE(., '('Anzahl der gelesenen Zahlen = ', i3)') n WRITE(., '(' Summe = ', f8.2)') summe WRITE(., '(' Mittelwert = ', f8.2)') mittw PRINT. END! - RE: How to read values line by line AND count them? (Programmer) 29 Oct 07 15:02.