- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
As can be seen in the attached program, when I am trying to open, read and write data into an array, I am getting an error which says as follows:
"forrtl: severe (59): list-directed I/O syntax error".
Any suggestions or insight into this would be greatly helpful.
Thank you.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your file has column headers which you need to skip. The line:
read (9,*)
will do it. But your program reads only one set of numbers - is that intentional?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve, Yes the line: read (9,*) skipped the line and this fixed the error. Thank you very much for pointing this out for me. My intention was to read all the sets of numbers corresponding to the 11 years, I understand that I could do this by keeping this read statement with in a do-loop, and also do the same for the write statement.
I had two questions in accomplishing this:
(i) Since the years are contiguous, I am trying to store just the start year and the number of years, what would be syntax for accomplishing this, for the integer array for year "yr"
(ii) If I place the iteration statement for the 11 years (as it may be suggested in (i) above), elsewhere other than within the read or write statements would it still read and write all the 11 values (assuming that both the read and write statements are both enclosed by just "do", and "endo").
As always thank you very much for your valuable suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You've still got a couple of fundamental Fortran concepts to understand.
You've declared your real array as having the indices (11,3), which means the first index ranges from 1->11, the second from 1->3.
Unfortunately, inside the DO loop, you're using the year as an index, which is accessing quite outside of the range of the array. It's like saying that you want to read page 1964 of a book that only has 11 pages.
Second, you've declared the year variable as an array, and so the list-directed I/O is trying to fill that array before it goes on to find the values for the real array.
To answer your other questions, if you just want the START and END (or number of) years, there are many ways to do that. Probably the least clever way is to have a variable named START that's initialized to an invalid number (negative? zero?) and then give it the first value of YR.
I'm sure you can figure a way to count iterations.
I don't understand the second question.
Here's a modified version of your first program, with a 'print' statement to help illustrate it.
PROGRAM rctbl
IMPLICIT NONE
! Declarations
INTEGER :: yr
INTEGER :: i,j
REAL :: param(11,3)
character*80 header
! Opening input file
OPEN (9,file='rc_tbl.txt',status='old')
read (9, *) header
DO i=1,11
READ(9,*,END=101)yr, (param(i,j), j=1,3)
print *, "year is", yr, "params are ", param(i,1), param(i,2), param(i,3)
END DO
101 CLOSE (9)
WRITE (*,*) param(4,2)
END PROGRAM rctbl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much Lorri,
Your detailed response helped me thoroughly understand
to read my table into an array and then and then write the appropriate values from this
table.
As regards my other questions:
(i) I am trying to use this program as a lookup table in order to retrieve a
table value based on the year value as an index, that corresponds to a
specified header, in order to use it in an equation. Any suggestions as regards
an efficient way to do this would be greatly helpful.
(ii) My second question in my previous post was about the instances where we can use
the "Do" and "END DO" without the indices and still achieve the objective of going through the iterations, if the indices are mentioned elsewhere in the program.
Thank very much once again for your valuable responses.

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