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'm lost!

Massimo
Beginner
1,309 Views

Greetings,

I am getting crazy with a trivial routine that systematically hungs my computer. It is a really trivial mnimal set of I/O instructions that I had written for a small computation program and I have then extracted in a stand-alone "project" (of just a few lines). Here is the code

OPEN (UNIT=5,FILE='INPUT.IN',STATUS='OLD',FORM='UNFORMATTED')
OPEN (UNIT=6,FILE='OUTPUT.OUT',STATUS='REPLACE')
WRITE(6,*) 1111
READ(5) A0
WRITE(6,*) 2222
WRITE(6,*) A0
CLOSE(6)
CLOSE(5)
END

Nothing could be simpler than this! Well, build is OK, but when I run this stupid program, it writes the "1111" in the output file and than it hangs. I have to terminate the dos-like window, but actually the .exe remains active - I can see it in the task manager and there is no way to terminate it. At the same time, it saturates my pagefile and I have to reboot.

With CVF I never had such a problem, with IVF this hyper-trivial task seems to be un-doable! I wonder what the hell I'm doing wrong?

Many thanks in advance.

0 Kudos
10 Replies
Steven_L_Intel1
Employee
1,309 Views
What is INPUT.IN? What wrote this file? My guess is that the file is not a Fortran unformatted file and data is being misinterpreted as a record length. CVF would have behaved identically.
0 Kudos
Massimo
Beginner
1,309 Views
What is INPUT.IN? What wrote this file? My guess is that the file is not a Fortran unformatted file and data is being misinterpreted as a record length. CVF would have behaved identically.
Oh, I see. OK, let me do a step back. I originally wrote, as I always did so far

OPEN (UNIT=5,FILE='INPUT.IN',MODE='READ')
OPEN (UNIT=6,FILE='OUTPUT.OUT',MODE='WRITE')
WRITE(6,*) 1111
READ(5,*) A0
WRITE(6,*) 2222
WRITE(6,*) A0
CLOSE(6)
CLOSE(5)
END

In this way it normally works with CVF, but IVF gives error 59 at the READ instruction. I read the help and somewhat guessed that the input way has changed. I looked for "unformatted" and found the above solution. I thought that unformatted meant what the "*" is in Fortran77 but your answer suggests it is not the case. OK, so I have misunderstood how it works. But then, why the above old-style code no longer works?

Thank you for your help!
0 Kudos
Steven_L_Intel1
Employee
1,309 Views
No, unformatted is a binary representation. The * format means "list-directed".

It could be that there's an error in the input that's not detected by CVF, or there's a bug in IVF. Can you create a ZIP of the input file and attach it to a reply here? Don't attach the file itself as that might change some bits. Also, please show the declaration of variable A0.
0 Kudos
Massimo
Beginner
1,309 Views
Thank you for your answer. OK, I have modified my trivial routine, that now is as follows

OPEN (UNIT=5,FILE='INPUT.IN',MODE='READ')
OPEN (UNIT=6,FILE='OUTPUT.OUT',MODE='WRITE')
WRITE(6,*) 1111
READ(5) A0
WRITE(6,*) 2222
WRITE(6,*) A0
CLOSE(6)
CLOSE(5)
END

The input file contains only a number, 5.3312. No declaration for the variable A0, it start with "A" so it should be implicitely interpeted as floating-point, shouldn't it? Anyway, I also tried adding a declaration: REAL A0, then REAL*4 A0, then REAL*8 A0, no change, I always get the following error message

forrtl: severe(256): unformatted I/O to unit open for formatted transfers, unit 5, file %directory%INPUT.IN

I attach the zipped input file.


0 Kudos
Steven_L_Intel1
Employee
1,309 Views
When you say READ(5), that is an unformatted READ which is not allowed when the unit is open for formatted input.

The input file begins with three non-ASCII characters, hex EF BB BF. What wrote this file?

If you want to read it, use this:

READ (5,'(3X,G6.0)') A0

That will skip over the three "garbage" characters and read just the number. You can't use list-directed input for this.

CVF would behave identically for this input file.
0 Kudos
Massimo
Beginner
1,309 Views

Sorry, sorry, I forgot to add the "*"!

READ(5,*)

Now I get the 59 error

forrtl: severe(59): list-directed I/O syntax error, unit 5, file etc.

The file has been written with a normal text editor (Window's notepad). I cannot give a formatted input because the file will be edited by hand by different users: some can put a blank before, others may not... I want to stress that this is a trivial operation I did thousand of times: open, read(5,*) a file containing a list of numbers, close, process data.

0 Kudos
Steven_L_Intel1
Employee
1,309 Views
The file has been corrupted, then. It is not a normal text file - it has what appears to be garbage in the first three characters.
0 Kudos
Les_Neilson
Valued Contributor II
1,308 Views

The file has been saved with UTF-8encoding.
I just used notepad to create a file test.txt and entered "5.312"
When Iedit the file and look at the hex data I see the following :

efbb bf35 2e33 3132 0d0a ...5.312..


Les
0 Kudos
Steven_L_Intel1
Employee
1,309 Views
Aha! I did not recognize that. Neither IVF nor CVF recognize UTF-8 encoding in formatted input.
0 Kudos
Massimo
Beginner
1,309 Views
Gosh, I would never had thought about such a problem! Thank you very much indeed for solving this!
0 Kudos
Reply