- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is an example of what most of my statements look like:
open(unit=10, file='res3', status='old')
read(10,*) R1, R2, R3
res3 is a text file that looks like this:
1000.0
1100.0
2000.0
Any suggestions would be appreciated.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
program resis1
real R1, R2, R3, RC
open(unit=10, file='res3')
read(10,*) R1, R2, R3
print *, R1, R2, R3
RC = 1.0/(1.0/R1 + 1.0/R2 + 1.0/R3)
print *, RC
pause
end
The file with the numbers is a .txt file
When I try to run it, it says it breaks at the read line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It would help if you attached files as they are instead of pasting text in-line in your posts, because small differences in text file format can sometimes cause errors on your side that cannot be reproduced at this end.
Do note that when you use list-directed input, sufficient lines will be consumed to fill the input list. In your example, since the input file contains only one real number per line, the read statement consumes three lines. Different rules apply when you use formatted input.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
After the program and text file are written (the text file is now attached to my other reply) I click debug and a message comes up that says "resis1.exe has triggered a break point". I click break and the message leaves and there is a green arrow pointing to the read line. So far that's all I know. It doesn't say anything in the error list.
Like I said, since I'm so new to this, I'm guess I'm not sure what else I should do to find errors and make sure the program is running right.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One of the problems I see is that the text file has the numbers on three lines and you are using a read statement that in a normal setting would expect the numbers on one line only.
Try putting in three read statements or a loop or put all the numbers on one line of the text file.
I would also not use print, but write with a format statement so you can control the output.
There are several excellent and cheap Fortran books that teach this sort of stuff.
Good luck
JMN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you tell us :
(1) What OS you are running?
(2)What compiler and version?
(3) When you do a build would it be possible for you to attach the build log file here?
(4) Is it possible your copy of the input text file is in Unicode format instead of ASCII?
(or not in the correct directory?)
You could add "end=", "err=" and "iostat="to theread statement
and an "err=" and "iostat=" to the open statement.
That would hopefully give you more informationwhen the error occurs.
Better still :
Since this appears to be a sample program and not proprietary, it would help if you could zip up the whole directory and attach the zip file here (like you did for the text file) then we will be able to test it for ourselves.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You opened a file called 'res3', but the file is apparently really called res3.txt. Since 'res3' did not exist, Fortran created a new one (it does this unless you add STATUS='OLD' to your OPEN). The new file was empty and the read failed because it hit the end.
I do need to correct John Nichols' comment - you are using list-directed input (the * format) and this will happily read the values from three lines if that's what is needed.
If my understanding of the error is correct, you need to change the filename in the OPEN to 'res3.txt'. If not, please show us the text of the error message from the console window.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page