Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Expression in I/Olist

dboggs
New Contributor I
579 Views

If memory serves correct, I used to write data using statements like

A = something
B = something
write (6, '(fmt') A, B, A/B

i.e., I want to write the ratio of A/B without explicitly calculating it and assigning to an intermediate variable (just to save the declaration), by including the expression A/B in the I/O list. I thought this used to work consistently (I don't know how long ago or which version, perhaps F77).

When I try this now, I observe that the statement "works" in the sense of writing the correct result. But SOMETIMES it will mess up the value of one or more other variables (depending on where they are stored in memory relative to A or B?), which then results in obscure errors elsewhere in the program. This can be very difficult to track down.

Checking the documentation, I now see that expressions in an I/Olist are not allowed. If this is so, shouldn't the compiler catch an illegal statement such as the above write and at least issue a warning?

0 Kudos
3 Replies
Steven_L_Intel1
Employee
579 Views

There's no problems with expressions in an output (WRITE) list. Obviously it doesn't work for a READ. Can you come up with a real example that fails? Also, please point to the place in the documentation where you think it says this is not allowed.

0 Kudos
dboggs
New Contributor I
579 Views

In the documentation, I looked up "WRITE statement"  and find many different forms, all of which have an optional [io-list] as the last item. The table then defines [io-list] as "the names of the variables, arrays, array elements, or character substrings from which or to which data will be transferred. Optionally an implied-DO list." Hence my conclusion.

Investigating further, if I click on "I/O list" I am taken to another document area that states

"However, constants and expressions can appear in the I/O lists for output statements because the compiler can use temporary memory locations to hold these values during the execution of the I/O statement."

So I guess it is only the "WRITE" documentation that is wrong, and not the "I/O Lists" documentation.

Can I reproduce the problem and submit it? Probably not, because it is intermittant, and behaves differently on different computers. But I will try. (fyi: the problem surfaces on a 64-bit Win7 computer running IVF12.1, while the same program was OK on a 32-bit WinXP computer running IVF11.10)

0 Kudos
Steven_L_Intel1
Employee
579 Views

Ok, thanks.  I asked our writers to enhance that text a bit.

0 Kudos
Reply