haris3384
09-12-2012, 08:32 AM
hi
i have two file with following data
file-1 (named: xyxp.dat)
6
1 1 0 10
3 2 1 5
3 5 4 8
0 0 0 11
1 2 5 4
5 6 4 12
file-2 (named: xyzn.dat)
6
1 0 0 0
2 1 1 0
3 3 2 1
4 1 2 5
5 3 5 4
6 5 6 4
now i want to match each value of the first three columns of file -1 with the corresponding values in the last three columns of file-2. for example first three values form file-1 are
1 1 0 now the program should search 1 1 0 in last three columns of file 2, and then write 2 10 as output
the result similar to this is required as output
1 11
2 10
3 5
4 4
5 8
6 12
till now i have written the following program, but really got confused with matching data
program main
implicit none
integer :: pn,nn
integer :: i
real ,allocatable, dimension (:,:) :: x , ix
open (11,file='xyxp.dat')
read (11,*) pn
allocate (x(pn,4))
do i=1,pn
read (11,*) x(i,:)
end do
close (11)
c write(*,*) x
open (12,file='xyzn.dat')
read (12,*) nn
allocate (ix(nn,4))
do i=1,nn
read (12,*) ix(i,:)
end do
close (12)
c write(*,*) ix
do i=1,nn
if (x(:,1)==ix(:,2).and.x(:,2)==ix(:,3).and.x(:,3)==i x(:,4)) then
ix(i,1)=x(i,4)
write(*,*) ix(i,1)
end if
end do
end program
kindly help me in this matter
i have two file with following data
file-1 (named: xyxp.dat)
6
1 1 0 10
3 2 1 5
3 5 4 8
0 0 0 11
1 2 5 4
5 6 4 12
file-2 (named: xyzn.dat)
6
1 0 0 0
2 1 1 0
3 3 2 1
4 1 2 5
5 3 5 4
6 5 6 4
now i want to match each value of the first three columns of file -1 with the corresponding values in the last three columns of file-2. for example first three values form file-1 are
1 1 0 now the program should search 1 1 0 in last three columns of file 2, and then write 2 10 as output
the result similar to this is required as output
1 11
2 10
3 5
4 4
5 8
6 12
till now i have written the following program, but really got confused with matching data
program main
implicit none
integer :: pn,nn
integer :: i
real ,allocatable, dimension (:,:) :: x , ix
open (11,file='xyxp.dat')
read (11,*) pn
allocate (x(pn,4))
do i=1,pn
read (11,*) x(i,:)
end do
close (11)
c write(*,*) x
open (12,file='xyzn.dat')
read (12,*) nn
allocate (ix(nn,4))
do i=1,nn
read (12,*) ix(i,:)
end do
close (12)
c write(*,*) ix
do i=1,nn
if (x(:,1)==ix(:,2).and.x(:,2)==ix(:,3).and.x(:,3)==i x(:,4)) then
ix(i,1)=x(i,4)
write(*,*) ix(i,1)
end if
end do
end program
kindly help me in this matter