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

read data in Debug and Release mode

Zhanghong_T_
Novice
298 Views

Hi all,

I need to read a line of data (the number is unknow), I have the following code, which runs OK in Debug mode, however, in Release mode, it displays 'error in reading file':

character*512::line
integer::readtype
integer::length
integer::n,inum,i
integer::data(n)
open(1,file='data.txt')
read(1,'(a)')line
line=adjustl(adjustr(line))
length=len_trim(line)
read(line(1:length),*,end=1,err=10)(data(i),i=1,n)
10 &
stop 'error in reading data'
1 &
inum=i-1 ! data is saved in data(1:inum)
end

The data file can be as follows:

1 2 3 4 5

or

1,2,3,4,5

or

1, 2, 3, 4, 5,

and so on.

Can anyone give me some suggestion?

Thanks,

Zhanghong Tang

0 Kudos
1 Reply
anthonyrichards
New Contributor III
298 Views
For a start, in the code you posted you have not defined a value for n. There should normally be a warning from the compiler if you are ..'using a variable that has not yet been defined'.
0 Kudos
Reply