Read multiple numbers from console in Fortran

Read multiple numbers from console in Fortran

Hi,

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

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

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!

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

 

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.

READ(*,*)(DISPL(I),i=1,N)

or

READ(*,*)DISPL(:N)

Leave a Comment

Please sign in to add a comment. Not a member? Join today