Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

I/O Question

bhvj
Beginner
1,126 Views

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.

0 Kudos
7 Replies
bhvj
Beginner
1,126 Views

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.

0 Kudos
Steven_L_Intel1
Employee
1,126 Views

Are these exercises as you learn Fortran? Are you taking a class?

0 Kudos
bhvj
Beginner
1,126 Views

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.

0 Kudos
Steven_L_Intel1
Employee
1,126 Views

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.

0 Kudos
bhvj
Beginner
1,126 Views

Thank you very much Steve, for pointing this out and for your suggestion. I have implemented the same and everything works fine.

 

0 Kudos
Steven_L_Intel1
Employee
1,126 Views

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.

0 Kudos
bhvj
Beginner
1,126 Views

Thank you again for the suggestion and the detailed explanation, Steve.

0 Kudos
Reply