- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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]

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page