clergy1122
Technical User
I'm really a novice. I wrote a small utility to calculate averages of numbers which it reads from a file. After reading I discover that it does not send the same values to the next loop. Unfortunately it works for a simple data set but not for my problem which has large data.
Here is the program;
Program Average
implicit none
integer::max
parameter(max=50)
integer::i,i1,j,N,tmp,N1,Num
real::K1,K2,K3,K4
integer,dimension(max)::Tag
real,dimension(max)::Asv,k,ar3,vol,ln,Asl,Avol,Aln
open(unit=1,file="ave2")
read(1,*)N
!write(,*)N
do i=1,N
read(1,*)Tag(i),k(i),ar3(i),vol(i),ln(i)
K1=k(i);k2=ar3(i);K3=vol(i);K4=ln(i)
enddo
Num=0
do i=1,N
K1 = k(i)
K2 = ar3(i)
K3 = vol(i)
K4 = ln(i)
N1=1
print*,K1,K2,K3,K4
print*,k(i),ar3(i),vol(i),ln(i)
do j=i+1,N
if(Tag(i).EQ.Tag(j))then
N1=N1+1
K1=K1+k(j);K2=K2+ar3(j);K3=K3+vol(j)
K4=K4+ln(j)
k(j)=0
ar3(j)=0
vol(j)=0
ln(j)=0
else
K1=K1
K2=K2
K3=K3
K4=K4
endif
enddo
Asl(i)=K1/N1
Asv(i)=K2/N1
Avol(i)=K3/N1
Aln(i)=K4/N1
! print*,Tag(i),Asl(i),Asv(i),Avol(i),Aln(i)
if(Asl(i).NE.(0.0))then
Num=Num+1
! print*,Tag(i),Asl(i),Asv(i),Avol(i),Aln(i)
! Write(3,*)Tag(i),Asl(i),Asv(i),Avol(i),Aln(i)
endif
enddo
Your help will be appreciated .
Thanks in advance
Here is the program;
Program Average
implicit none
integer::max
parameter(max=50)
integer::i,i1,j,N,tmp,N1,Num
real::K1,K2,K3,K4
integer,dimension(max)::Tag
real,dimension(max)::Asv,k,ar3,vol,ln,Asl,Avol,Aln
open(unit=1,file="ave2")
read(1,*)N
!write(,*)N
do i=1,N
read(1,*)Tag(i),k(i),ar3(i),vol(i),ln(i)
K1=k(i);k2=ar3(i);K3=vol(i);K4=ln(i)
enddo
Num=0
do i=1,N
K1 = k(i)
K2 = ar3(i)
K3 = vol(i)
K4 = ln(i)
N1=1
print*,K1,K2,K3,K4
print*,k(i),ar3(i),vol(i),ln(i)
do j=i+1,N
if(Tag(i).EQ.Tag(j))then
N1=N1+1
K1=K1+k(j);K2=K2+ar3(j);K3=K3+vol(j)
K4=K4+ln(j)
k(j)=0
ar3(j)=0
vol(j)=0
ln(j)=0
else
K1=K1
K2=K2
K3=K3
K4=K4
endif
enddo
Asl(i)=K1/N1
Asv(i)=K2/N1
Avol(i)=K3/N1
Aln(i)=K4/N1
! print*,Tag(i),Asl(i),Asv(i),Avol(i),Aln(i)
if(Asl(i).NE.(0.0))then
Num=Num+1
! print*,Tag(i),Asl(i),Asv(i),Avol(i),Aln(i)
! Write(3,*)Tag(i),Asl(i),Asv(i),Avol(i),Aln(i)
endif
enddo
Your help will be appreciated .
Thanks in advance