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.

List-Directed Read gives no error.

Rol_fae
Beginner
784 Views

I migrated from CVF to Intel Fortran. Everything is working but the following:

I read two columns of real numbers and would like to stop the reading (that means to branch to the error specifier) when there is a character string instead of a number on the input file.

The code line is as follows

.

read(nin,*,err=20,end=21)x(nd),y(nd)

.

On CVF this is working but the Intel Compiler does not detect an error and translates the character string to the number 0.0.

The input file looks like this:

.

1200. 0.
1500. 0.
north 10 to 15

.

Are there any compiler options to be changed?

Many thanks for any suggestions.

Roland

0 Kudos
6 Replies
Steven_L_Intel1
Employee
784 Views

I'll start with my usual advice to never depend on list-directed input to give an error for what YOU think is an error, since it is very forgiving.

That said, I can't reproduce the problem you describe exactly, but I wonder if the "north 10 to 15" line is actually the one causing the problem. If, for example, the first word was "flew", or anything beginning with the letter F, then I would expect a zero to be read, in both CVF and IVF. This is because the compiler provides free conversion between LOGICAL and numeric types in list-directed (and NAMELIST) input. I hate this behavior and have finally convinced the developers to turn it off by default, but that is still a work in progress.

When I try a test program based on what you wrote, "north" gives me a list-directed syntax error, though the word "to" would read happily as -1 (since it is treated as .true.)

Can you show a short but complete program that demonstrates the problem and show what input you give?

0 Kudos
Rol_fae
Beginner
784 Views

I'll start with my usual advice to never depend on list-directed input to give an error for what YOU think is an error, since it is very forgiving.

That said, I can't reproduce the problem you describe exactly, but I wonder if the "north 10 to 15" line is actually the one causing the problem. If, for example, the first word was "flew", or anything beginning with the letter F, then I would expect a zero to be read, in both CVF and IVF. This is because the compiler provides free conversion between LOGICAL and numeric types in list-directed (and NAMELIST) input. I hate this behavior and have finally convinced the developers to turn it off by default, but that is still a work in progress.

When I try a test program based on what you wrote, "north" gives me a list-directed syntax error, though the word "to" would read happily as -1 (since it is treated as .true.)

Can you show a short but complete program that demonstrates the problem and show what input you give?

Hi Steve,

many thanks fr your endeavors. Please find a copy of a test code and the corresponding input file in the following:

Test code:

program Console1

real x(10), y(10)

nin=5
nout=6
open (unit=nin,file='input.txt',status='unknown')
open (unit=nout,file='output.txt',status='unknown')
nd=10

do i=1,nd
read(nin,*,err=20,end=21)x(nd),y(nd)
write(nout,'(2f15.4)')x(nd),y(nd)
enddo
20 continue
write(nout,*)' Error detected at line:',i
stop

21 continue
write(nout,91)i-1
stop
91 format(/,' ** End of File **',/,' data number found:',i5)
end program

Input file:

0. 3.
1000. 12000.
north 10 to 15

With CVF the "error" is detected. That means the following output is produced:

0.0000 3.0000
1000.0000 12000.0000
Error detected at line: 3

With IVF the error-branching does not work and the following output ist produced:

0.0000 3.0000
1000.0000 12000.0000
0.0000 10.0000

** End of File **
data number found: 3

Thank you

Roland

0 Kudos
Steven_L_Intel1
Employee
784 Views

Sure enough - I can reproduce this. I'll report it to the developers. Nevertheless, you should not depend on an error indication from list-directed input.

0 Kudos
Rol_fae
Beginner
784 Views

Sure enough - I can reproduce this. I'll report it to the developers. Nevertheless, you should not depend on an error indication from list-directed input.

Ok, I try to change it.

Thanks.

0 Kudos
Steven_L_Intel1
Employee
784 Views

This one is very strange. It requires the following:

1. The "word" at the beginning of the line has to start with the letter I or N.

2. There needs to be at least a second variable in the I/O list!

My guess is that this involves the need to recognize the strings NaN and Infinity. I have escalated it to the developers.

0 Kudos
Steven_L_Intel1
Employee
784 Views
We have fixed this error and the fix ought to appear in the next update.
0 Kudos
Reply