haris3384
09-17-2012, 03:38 AM
hi i have two data sets one(data1) containing
3
8 2 1 5 7 9
9 2 2 5 7 7
10 3 6 6 6 6
and other(data2) containing
5
1 10
5 20
7 30
6 40
9 50
now i want my program to search the values 1 5 7 9 from (data1) in data 2 column 1 and then take the average of the corresoinding values in column 2, for example for first line of data1 the avg of (1 5 7 9) will be
(10+20+30+50)/4=27.5
then write
8 2 27.5
and so on...till now i have written the following program,
program test
implicit none
integer :: pn,en
integer :: i
real ,allocatable, dimension (:,:) :: y
integer,allocatable,dimension (:,:) :: ix
REAL ,DIMENSION (:) :: avg(10000000)
open (11, file='data1.dat')
read (11,*) pn
allocate (y(pn,2))
do i=1,pn
read(11,*) y(i,:)
enddo
close(11)
c *************************
open(12,file='data2.dat')
read (12,*) en
allocate (ix(en,6))
do i=1,en
read(12,*) ix(i,:)
enddo
close(12)
c *************************
do i=1,en
avg(i)=(y(ix(i,3),2)+y(ix(i,4),2)+y(ix(i,5),2)+
& y(ix(i,6),2))/4
end do
do i=1,en
write(*,*) ix(i,1:2),avg(i)
enddo
end program
this gives me output
8 2 15
9 2 17.5
10 3 0
which is wrong. instead of searching for value it searches for line number .... so what to change in it to search for value not line number
3
8 2 1 5 7 9
9 2 2 5 7 7
10 3 6 6 6 6
and other(data2) containing
5
1 10
5 20
7 30
6 40
9 50
now i want my program to search the values 1 5 7 9 from (data1) in data 2 column 1 and then take the average of the corresoinding values in column 2, for example for first line of data1 the avg of (1 5 7 9) will be
(10+20+30+50)/4=27.5
then write
8 2 27.5
and so on...till now i have written the following program,
program test
implicit none
integer :: pn,en
integer :: i
real ,allocatable, dimension (:,:) :: y
integer,allocatable,dimension (:,:) :: ix
REAL ,DIMENSION (:) :: avg(10000000)
open (11, file='data1.dat')
read (11,*) pn
allocate (y(pn,2))
do i=1,pn
read(11,*) y(i,:)
enddo
close(11)
c *************************
open(12,file='data2.dat')
read (12,*) en
allocate (ix(en,6))
do i=1,en
read(12,*) ix(i,:)
enddo
close(12)
c *************************
do i=1,en
avg(i)=(y(ix(i,3),2)+y(ix(i,4),2)+y(ix(i,5),2)+
& y(ix(i,6),2))/4
end do
do i=1,en
write(*,*) ix(i,1:2),avg(i)
enddo
end program
this gives me output
8 2 15
9 2 17.5
10 3 0
which is wrong. instead of searching for value it searches for line number .... so what to change in it to search for value not line number