Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29236 Discussions

Read multiple numbers from console in Fortran

vahid_s_
Novice
703 Views

Hi,

How can I read array of data from console in fortran with pressing only one ENTER?  I am looking for something like this:

[fortran]

REAL*8 DISPL(N)

DO 10 I=1,N
READ (*,*) DISPL(I)
10 CONTINUE

[/fortran]

But to read each number the user must press ENTER and I do not want that. I want to read all the data with pressing only one ENTER. Is there any way to do that? Thanks!

0 Kudos
2 Replies
DavidWhite
Valued Contributor II
703 Views

Your code enforces entering the data one by one, as you have effectively N read statements.

An alternative would be

READ (*,*) DISPL

or if you only wanted a section of the array instead of the whole array,

READ(*,*) DISPL(1:N)

Each item would need to be delimited by spaces, commas or ENTER.

Regards,

David

 

0 Kudos
mecej4
Honored Contributor III
703 Views
By default, each READ reads one record. With console input, ENTER signifies end-of-record. You can use either of the following to read N numbers from a single record. Read the chapter on I/O in a Fortran book. [fortran]READ(*,*)(DISPL(I),i=1,N) [/fortran] or [fortran]READ(*,*)DISPL(:N) [/fortran]
0 Kudos
Reply