- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I have an input output question. I am trying to read the values as in the attached text file, until end of file, then multiply the last value (from beginning to end) by a coefficient (example 0.5) and output the table in the same format but with the modified last column. Attached herewith is a test program which I tried to write for this, which appears to go in an infinite loop.
Any pointers and suggestions so as to output the file in the same format would be greatly helpful.
Thank you.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Please disregard the request made for this forum topic. Attached herewith is the modified code and input file by which I was able to arrive at the answer.
Any enhancements or further suggestions also would be helpful.
I sincerely thank this forum, for always being with me as my mentor throughout my learning process as and when I needed help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are these exercises as you learn Fortran? Are you taking a class?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
The basic task I have is not part of any exercise of any class. I am not taking any class. I am not a programmer by profession, that's all.
The research project I am part of involves conversion of calculations that are done by using Excel macros to Fortran so as to do these calculations multiple times using a Fortran executable.
As I am working through it, I am posting the question that I have through a very simplistic example, with the idea of not overwhelming the question.
As always thank you very much for all your responses.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's fine. I looked at your program - there's one bug and I have one suggestion.
You have:
DO i=1,nd READ(20,*,END=101)iyr(i),imonth(i),iday(i),tc(i) tc_out = 0.5*tc END DO
where tc and tc_out are arrays. You should either add (i) subscripting to both of those in the assignment, or even better, simply move the assignment to tc_out to after the END DO outside the loop. Since these are arrays of the same dimension, each element will get multiplied by .5 and assigned.
The suggestion is to not compare IOSTAT to -1 but to use the predefined constant for the EOF status. Add:
USE, INTRINSIC :: ISO_FORTRAN_ENV
after PROGRAM and compare to IOSTAT_END instead. This will be more portable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much Steve, for pointing this out and for your suggestion. I have implemented the same and everything works fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh, the END=101 in that loop should probably be removed. You'd like to get an error if for some reason the count is wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you again for the suggestion and the detailed explanation, Steve.

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