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

Fail to read data file

Yaming_P_
Beginner
2,179 Views

I am now using the Parallel Studio XE 2015 Composer Edition for Fortran combined with Xcode 6.3 to run a program.

The program was made in order to read data from file first and then go for some further computation.

I had all my f90 files (including the main program and the modules) in the Project folder and it did compile and run.

But when I tried to input the file name and load the file, it seemed that it failed to read the file.

I have my code like this

 

.......

CHARACTER(LEN = 20) :: fileName

INTEGER :: iNode

REAL(KIND = dp) :: xBox, yBox, zBox

WRITE(*,'(A)', ADVANCE = "NO") "Input file name: "

READ(*,*) fileName

OPEN(1, FILE = TRIM(fileName)//'.in' , STATUS = 'UNKNOWN')

READ(1,*) iNode, xBox, yBox, zBox

........

 

When I ran the program and input the file name it simply returned forrtl: severe (24): end-of-file during read, unit 1...

I though it might be due to failure to find the file though I had put the data file (output.in) in the same folder as other .f90 files, as well as add it to the project. 

I am just wondering how to deal with this issue (I thought it might be a reference/file location issue of Xcode, since this program is running well on other fortran compiler.)

 

Thanks.

-Abright

0 Kudos
1 Solution
Kevin_D_Intel
Employee
2,179 Views

The severe(24) is an end-of-file error indicating the amount of data in the file found/opened was less than what was attempted by the READ. (See here for list of run-time error messages).

With the STATUS=’UNKNOWN’, when a pre-existing file by the name you constructed for FILE= is not found, a new (empty) file by that name is created/opened which could lead to the severe (24) when the READ statement executes. Since you seem to indicate knowing the file name created (i.e. output.in) does exists, then the severe(24) likely indicates the program not finding the file where you expected it might.

You likely need to just set the working directory accordingly under Xcode or place a copy of the input file into the pre-set working directory (where the executable resides), which ever you prefer.
 
I do not have a working example readily available under Xcode 6.x to play with so see if the details in this older post helps with setting the working directory.

View solution in original post

0 Kudos
4 Replies
Steven_L_Intel1
Employee
2,179 Views

Doesn't the error message give the full path to the data file? Adding the file to the project has no effect. Are you using these other compilers in Xcode? I am not sure how it works in Xcode, but most likely the default for files is not where you think it is. You could use INQUIRE to get the full path if it isn't in the error message. Note that the default is STATUS='UNKNOWN' so it will create an empty file if it doesn't exist, and then get an EOF on the first read. You could also try using STATUS='OLD' to force an error if the file is not found. (But make sure you delete any empty copies of the file first.)

0 Kudos
Kevin_D_Intel
Employee
2,180 Views

The severe(24) is an end-of-file error indicating the amount of data in the file found/opened was less than what was attempted by the READ. (See here for list of run-time error messages).

With the STATUS=’UNKNOWN’, when a pre-existing file by the name you constructed for FILE= is not found, a new (empty) file by that name is created/opened which could lead to the severe (24) when the READ statement executes. Since you seem to indicate knowing the file name created (i.e. output.in) does exists, then the severe(24) likely indicates the program not finding the file where you expected it might.

You likely need to just set the working directory accordingly under Xcode or place a copy of the input file into the pre-set working directory (where the executable resides), which ever you prefer.
 
I do not have a working example readily available under Xcode 6.x to play with so see if the details in this older post helps with setting the working directory.

0 Kudos
Yaming_P_
Beginner
2,179 Views

Steve and Kevin,

Thanks for you help!

Case closed.

0 Kudos
Kevin_D_Intel
Employee
2,179 Views

Glad to hear that!

0 Kudos
Reply