- #1
heliosplane
- 5
- 0
Guys. I really need help. I have been working in this little problem for hours. I had a problem in array reading when I opened more than 1 files, it seems like an array with different names mixed each other. Here is my code
I have 2 arrays, A and B that I want to calculate, the A just need the file in open unit 1, and the last one need data from the file in open unit 2 and 3. When I deleted the open unit 2 and 3, my program worked just fine. But I needed those files for calculating array B. I had tried to put this last 2 opening syntax (unit 2 and 3) after the line to calculate the array A, but the program didn't work like it's supposed to be, element in array A became messy. I am really confused why this could happen, because I thought file in unit 2 and 3 don't relate with array A. Is there anything wrong with my syntax? or is it because my compiler, I am using the latest gfortran? Is there any other way that I can use?
Thanks in advance guys.
Code:
integer, parameter::size=11
real, dimension(101) :: cldata, alphadata
real, dimension(size) :: circ
integer:: i, j, nvals=0, nvals2=0, nvals3=0, status
Open (Unit=1, File='circdata.txt', status='old', Action='Read')
fileopen1: IF (status==0) then
Write (*,1000) status
1000 format (1x,'file alphadata open success--status = ',I6)
do
read(1,*,iostat=status) temp !Get value
if (status/=0) exit !Exit on end of data
nvals=nvals+1 !Bump count
circ(nvals)=temp !Save value in array
end do
else fileopen1
Write (*,1050) status
1050 format (1x,'file open failed--status = ',I6)
end if fileopen1
Open (Unit=2, File='alphadata.txt', status='old', Action='Read', Iostat=status)
fileopen2: IF (status==0) then
Write (*,2000) status
2000 format (1x,'file alphadata open success--status = ',I6)
do
read(2,*,iostat=status) temp !Get value
if (status/=0) exit !Exit on end of data
nvals2=nvals2+1 !Bump count
alphadata(nvals2)=temp !Save value in array
end do
else fileopen2
Write (*,1060) status
1060 format (1x,'file open failed--status = ',I6)
end if fileopen2
Open (Unit=3, File='cldata.txt', status='old', Action='Read', Iostat=status)
fileopen3: IF (status==0) then
Write (*,3000) status
3000 format (1x,'file cldata open success--status = ',I6)
do
read(3,*,iostat=status) temp !Get value
if (status/=0) exit !Exit on end of data
nvals3=nvals3+1 !Bump count
cldata(nvals3)=temp !Save value in array
end do
else fileopen3
Write (*,1070) status
1070 format (1x,'file open failed--status = ',I6)
end if fileopen3
I have 2 arrays, A and B that I want to calculate, the A just need the file in open unit 1, and the last one need data from the file in open unit 2 and 3. When I deleted the open unit 2 and 3, my program worked just fine. But I needed those files for calculating array B. I had tried to put this last 2 opening syntax (unit 2 and 3) after the line to calculate the array A, but the program didn't work like it's supposed to be, element in array A became messy. I am really confused why this could happen, because I thought file in unit 2 and 3 don't relate with array A. Is there anything wrong with my syntax? or is it because my compiler, I am using the latest gfortran? Is there any other way that I can use?
Thanks in advance guys.