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

File is opened. But giving an error

Mahesh_K_
Beginner
489 Views

Hi,

I open a file using this.

open(100,FILE ='temp.txt',STATUS='OLD',ERR=63) 

But it goes to error line.

Then,I check the error using this(when the error is happen) .

INQUIRE (100, OPENED=I_OPENED, NAME=I_NAME, ACTION=I_ACTION)

But it says file is opened.

I_OPENED = T and other variable are fine.

Please help me.

0 Kudos
4 Replies
Lorri_M_Intel
Employee
489 Views

Change your OPEN statement to also include IOSTAT.  it will look something like this:

open(100,FILE ='temp.txt',STATUS='OLD',IOSTAT=IERR, ERR=63) 

and then look to see what the error number is.

In case it's not obvious, you should also declare "INTEGER IERR"

0 Kudos
Mahesh_K_
Beginner
489 Views

Thank you, Lorri Menard.

I tested. It gives me 0. That means no error. But unfortunately it goes to error line(to 63);

What can be the reason for that?

Thank you.

OH sorry.. I couldn't tell you one important thing.

Programme works fine when it run at the visual studio. Only it gives me the error when it run as separate programme. Because of that I couldn't understand the reason for this. Please help me.

0 Kudos
Les_Neilson
Valued Contributor II
489 Views

In which directory is your file temp.txt located?

When running as a separate program you need to be in the directory where temp.txt exists.

Les

0 Kudos
andrew_4619
Honored Contributor III
489 Views

on error it will still jump to the ERR line (63) but IERR will be set non-zero to 29 (file not found) I would expect....

Perhaps something like below would help you more....

open(100,FILE ='temp.txt',STATUS='OLD',IOSTAT=IERR)
if( ierr /= 0) then
   write(*,*) 'file error is:',ierr
   goto 63
endif  

 

0 Kudos
Reply