I have problems reading a file when I compile with pgi. Compiling with ifort works. I read the file in the following way:
open ( 33, file = 'Nbody.files0' , status = 'old' )
lst = 1
do while (.true.)
read(33,*,iostat=ios) dum
if (ios .ne. 0) exit
lst=lst+1
enddo
lst = lst - 1
rewind(33)
do i = 1,lst
read(33,*) steps(i)
enddo
The file to be read has one entry in each line. However, if I change the file in such a way, that all of the data is on one line and the data is seperated by the two ascii characters \n (not the ascii newline) then it works. Then the file looks like
Can you put together some code to reproduce the problem you’re seeing? I tried but get the same behavior with the Intel and PGI compilers, where each read will advance a full line and ‘\n’ is not interrupted as the ASCII newline character.
% cat read.f90
program foo
implicit none
real :: dum, steps(100)
integer :: ios, lst, i
open ( 33, file = 'Nbody.files0' , status = 'old' )
lst = 1
do while (.true.)
read(33,*,iostat=ios) dum
if (ios .ne. 0) exit
lst=lst+1
enddo
lst = lst - 1
rewind(33)
do i = 1,lst
read(33,*) steps(i)
enddo
close (33)
print *, steps(1), steps(10)
end program foo
% cat Nbody.files0
0.000000\n67.199997\n134.399994\n201.600006\n268.799988\n336.000000\n403.200012\n470.399994\n537.599976\n604.799988\n672.000000\n739.200012\n806.400024\n873.599976\n940.799988\n1008.000000\n1075.199951\n1142.400024\n1209.599976\n1276.800049\n1344.000000\n1411.199951
% ifort read.f90 -o iread.out
% pgf90 read.f90 -o pread.out
% iread.out
0.0000000E+00 0.0000000E+00
% pread.out
0.000000 0.000000
% vi Nbody.files0
% cat Nbody.files0
0.000000
67.199997
134.399994
201.600006
268.799988
336.000000
403.200012
470.399994
537.599976
604.799988
672.000000
739.200012
806.400024
873.599976
940.799988
% iread.out
0.0000000E+00 604.8000
% pread.out
0.000000 604.8000
Thank you for your fast reply. Indeed, your test program works the same for pgi and ifort also on my computer. In the meantime I found out what the difference in my case is. I actually create the file Nbody.files0 form another file, in the following way:
call system ('cat galaxies | awk ''{printf $2"\\n"}'' > Nbody.prop')
Use the “-Mbackslash” option to have back slashes treated as just another character in a string. By default we treat back slash as the escape character.
It appears that Intel is the opposite where you need to add “-assume bscc” to have backslashes be the escape character.
gfortran has the same default as us with the ‘-fno-backslash’ flag to disable the escape character.