- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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.
링크가 복사됨
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Are these exercises as you learn Fortran? Are you taking a class?
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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.
