Reputation: 11
I want to read a file 20*4 dimention contains character and digital, and resort it out to another file, but I always have forrtl server(64): Input conversion error in fortran I will aprreciate if anyone can help me.
I have an input file a.txt (20*4) like this:
index Ti Te Ne
1 2.3 2.5 0.6
2 2.9 3.2 0.8
3 3.4 3.6 1.1
.
.
.
20 7.3 8.9 3.5
My program is test.f90 like below:
program test
implicit none
real*8,allocatable :: prof_Ne(:),prof_Te(:),prof_Ti(:)
integer :: i, j, n_skip, n_prof
character :: index*22
n_prof = 20
allocate(prof_Ne(n_prof), prof_Te(n_prof), prof_Ti(n_prof))
open(21,file='a.txt')
read(21,'(A25)') index
write(*,*) index
n_skip = 4
do i=1,n_skip
read(21,*)
enddo
do i=1,n_prof
read(21,'(i2,3e9.5)') j,prof_Ne(i),prof_Te(i),prof_Ti(i)
enddo
close(21)
write(*,*) prof_Ne
end program
Upvotes: 1
Views: 6842
Reputation: 18098
read(*,*)
followed by four strings to let Fortran decided where to break those strings apart. My guess at what you are trying to achieve is below:
program test
implicit none
real*8,allocatable :: prof_Ne(:),prof_Te(:),prof_Ti(:)
integer :: i, j, n_prof
character(len=22) :: index, dummy1, dummy2, dummy3
n_prof = 20
allocate(prof_Ne(n_prof), prof_Te(n_prof), prof_Ti(n_prof))
open(21,file='a.txt')
read(21,*) index, dummy1, dummy2, dummy3
write(*,*) index, dummy1, dummy2, dummy3
do i=1,n_prof
read(21,*) j,prof_Ne(i),prof_Te(i),prof_Ti(i)
enddo
close(21)
write(*,*) prof_Ne
end program
Upvotes: 1