tuli
Electrical
- Feb 20, 2003
- 16
Hello,
I need to read in an unknown number of array elements. i do not know how to handle the dimension of the arrays.
I start with declaring the size of each array as 101, but the file includes an unknown number of array components so I would nee to resize the array, which cannot be done in the middle of the code. the data file is attached (Here is the code for now:
program main
parameter(imax=101)
dimension th(imax),et1(imax),et2(imax),eph1(imax),eph2(imax)
open(5,file="farfields.txt")
read(unit=5, fmt='(a1)') dummy ! read dummy text
read(unit=5, fmt='(a1)') dummy ! read dummy text
read(5,*) npoints,freq,phi
m=1
! form here on i need to read 5 arrays and I do not know the size of the file.
100 read(5,*,end=101) th(m),et1(m),et2(m),eph1(m),eph2(m)
print*,m,th(m),et1(m),et2(m),eph1(m),eph2(m)
m=m+1
goto 100
101 continue
mmax=m-1
print*,'mmax= ',mmax
close(5)
stop
end program main
I need to read in an unknown number of array elements. i do not know how to handle the dimension of the arrays.
I start with declaring the size of each array as 101, but the file includes an unknown number of array components so I would nee to resize the array, which cannot be done in the middle of the code. the data file is attached (Here is the code for now:
program main
parameter(imax=101)
dimension th(imax),et1(imax),et2(imax),eph1(imax),eph2(imax)
open(5,file="farfields.txt")
read(unit=5, fmt='(a1)') dummy ! read dummy text
read(unit=5, fmt='(a1)') dummy ! read dummy text
read(5,*) npoints,freq,phi
m=1
! form here on i need to read 5 arrays and I do not know the size of the file.
100 read(5,*,end=101) th(m),et1(m),et2(m),eph1(m),eph2(m)
print*,m,th(m),et1(m),et2(m),eph1(m),eph2(m)
m=m+1
goto 100
101 continue
mmax=m-1
print*,'mmax= ',mmax
close(5)
stop
end program main