Deal all,
I have an extremely simple example, but I am confused if read can correctly recognize the '"." in the file.
Here is the file, call it test.csv
101,1,0,2,55,.,.,1
Note that the . cause trouble.
I was think read * can recognize . as just 0.0, but it seems behave strange. Here is the code,
program main
implicit none
integer :: fu, rc
integer :: i(10)
real :: x(10)
open(action='read', file='test.csv', iostat=rc, newunit=fu)
read (fu, '(2(i10),6(g15.7))', iostat=rc) i(1:2),x(1:6)
write(6,*) 'i = ', i(1:2)
write(6,*) 'x = ', x(1:6)
close(fu)
end program main
I expect it shows
i = 101 1
x = 0.0 2.0 55.0 0.0 0.0 1.0
but it gives me
i = 101 1
x = 0.0000000E+00 2.0000000E-07 5.5000000E-06 0.0000000E+00 0.0000000E+00
1.0000000E-07
Obviously when encounter " . ", it cannot recognize anything after it.
Initially I use
read (fu, *, iostat=rc) i(1:2),x(1:6)
But the * does not help.
Could anyone explain why the β . β cause the trouble or how to make it work?
Do I have to read the whole line as string first, then deal with those , and . symbols and do some conversion? like things below,
Then the code becomes,
program main
implicit none
integer :: fu, rc
integer :: i(10)
real :: x(10)
character(len=100) :: char(8)
open(action='read', file='test.csv', iostat=rc, newunit=fu)
read (fu, *, iostat=rc) char(1:8)
write(6,*) 'char = ', char(1:8)
close(fu)
end program main
I can convert my char array correspondingly
Thank you very much in advance!