Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading matrix, making vector 1

Status
Not open for further replies.

galileo1972

Technical User
Feb 17, 2003
14
DE
hello,

i need really help !!!

i have implemented a filter, this reads a data file from a Mesh generator and finding of every node its neighbours (3 dimensional). This was difficult enough. But now i get a list of nodes with its neighbours, but some neigbours appears twice or more. For example following list.

Node neighbours

1 3 5 6
1 2 3 5
1 6 3 2
1 3 5 2
2 8 7 5
2 7 5 11
2 11 7 12
2 13 8 7
2 5 12 13
2 5 8 12

I need this list:

1 3 5 6 2
2 8 7 5 11 13 12

and so on.

can someone help me please !!!

thanx in advance

galileo
 
Try this

program ff2

integer i,j,k,m(3),n,ksv,a(100)

open(1,FILE='ff2.dat')

ksv = -1
do while (1)
read(1,*,end=999) k,m(1),m(2),m(3)
if (k.ne.ksv) then
if (ksv.ne.-1) then
print *,ksv,(a(j),j=1,n)
n = 0
endif
ksv = k
endif
do i=1,3
do j=1,n
if (a(j).eq.m(i)) goto 100
enddo
n = n+1
if (n.le.100) a(n) = m(i)
100 continue
enddo
enddo

999 print *,ksv,(a(j),j=1,n)
close(1)
end CaKiwi
 
Hi cakiwi,

thank you for your program. But I have a problem.

during compilation i get this message:

do while(1)
^

Type disagreement between expressions at (^) and (^)

i hope you know this problem.

best regards

galielo
 
hi i have further problems

i cant understand a aprt of your program


if (k.ne.ksv) then
if (ksv.ne.-1) then
print *,ksv,(a(j),j=1,n)
n = 0
endif
ksv = k
endif


i get problems with the a(j). if i start the program i get stupid numbers

100000000 1233424243 ^231242424 12341312
123213131 12341231212 1234123123 12312123
1232131221 23423423324 2342342332 23423324

and so on.

maybe you can help me

galileo
 
i know where is the problem:

if (ksv.ne.-1) then
print *,ksv,(a(j),j=1,n)
n = 0
endif

if i kill this part i think it can work !!

do i need this part ?
 
i think im near the solution:

if i kill the following part

if (ksv.ne.-1) then
print *,ksv,(a(j),j=1,n)
n = 0
endif

i get this outfile from the following list

1 ...numbbers
1
1
1
2 ...numbers
2
2
2


i get this outfile :

2 .....num,bers


i get only the last column from the list, How can i get also the node number 1


1 .....numbers
2 .....numbers
3 ..... numbers


i hope you know the solution
 
It looks like there is a problem reading the data from the input file. Put a

print *,k,m(1),m(2),m(3)

after the read statement to help us debug it.

If your compiler does not like the while(1), replace it with

10 continue

and change the last enddo to

goto 10 CaKiwi
 
the reading is no problem, if i put

print *,k,m(1),m(2),m(3) after the read statement. i get the wright output.

The Problem is that i only get the last row of the input list. For example i read from the following list:

1 31 3 15
1 3 34 15
1 31 3 55
1 3 34 55
23 22 25 5
23 24 25 5
23 28 22 5
23 28 24 5

After starting your program i get only the output of the nodes 23 (last node) with their neighbours:

23 22 25 5 24 28

the node number 1 wont considered. But the output file should be

1 31 3 15 34 55
23 22 25 5 24 28

I tried something: If i put the write statement after

if (n.le.100) a(n)=m(i) (program listing)

-------------------------------------------------
do i=1,3
do j=1,n
if (a(j).eq.m(i)) goto 100
enddo
n = n+1
if (n.le.100) a(n) = m(i)
-->test write(*,*) ksv,(a(j),j=1,n)
--------------------------------------------------

i get following output:

1 31
1 31 3
1 31 3 15
1 31 3 15 34
1 31 3 15 34 55
23 22
23 22 25
23 22 25 5
23 22 25 5 24
23 22 25 5 24 28


the program does it wonderful, but i have only output problems.
you see the problem ??
i only need the last of every comparisons. The last row of the nodes 1, the last row of the nodes 23 and so on, if i have 20000 nodes, i need the last of every node.

we are really near the solution, i hope so. Im really deeply grateful for your help.

galileo


 
I don't understand why the program works for me but not for you. Post the complete program you are using now and I will try it. CaKiwi
 
ok, here is the complete program:

program test

integer i,j,k,m(3),n,ksv,a(100),z

open(1,FILE='test.out')
open(3,FILE='test2.out')

ksv = -1
read(1,*) iter
do 100 z=1,iter
read(1,*) k,m(1),m(2),m(3)
if (k.ne.ksv) then
c if (ksv.ne.-1) then
n = 0
c endif
ksv = k
endif

do i=1,3
do j=1,n
if (a(j).eq.m(i)) goto 200
enddo
n = n + 1
if (n.le.100) a(n) = m(i)
write(3,*) ksv,(a(j),j=1,n)
200 continue
enddo

100 continue

c write(*,*) ksv,(a(j),j=1,n)
close(1)
close(3)

end




I have modified it, because this program version give me now the output i told you before.

If i take the last write statement, i get only the very last row of the list. Maybe this section is the problem

c if (ksv.ne.-1) then
n = 0
c endif

if i implement a write statement before endif, i get strange results !!!!!

its really strange that you get the perfect result !???

i hope you can modify the program i sent you, that it works on my PC. I use the linux version 8.1 !!!
 
Here's the program that works for me

program test

integer i,j,k,m(3),n,ksv,a(100),z

open(1,FILE='test.out')
open(3,FILE='test2.out')

ksv = -1
read(1,*) iter
do 100 z=1,iter
read(1,*) k,m(1),m(2),m(3)
if (k.ne.ksv) then
if (ksv.ne.-1) then
write(3,*) ksv,(a(j),j=1,n)
endif
ksv = k
n = 0
endif

do i=1,3
do j=1,n
if (a(j).eq.m(i)) goto 200
enddo
n = n + 1
if (n.le.100) a(n) = m(i)
200 continue
enddo

100 continue

write(3,*) ksv,(a(j),j=1,n)
close(1)
close(3)

end

This is the input data I used

8
1 31 3 15
1 3 34 15
1 31 3 55
1 3 34 55
23 22 25 5
23 24 25 5
23 28 22 5
23 28 24 5

This is the output I got

1 31 3 15 34 55
23 22 25 5 24 28 CaKiwi
 
IT WORKS !!!!!!!!!!!!

thank you for your help.

i wish you a nice week, and weekend !

galileo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top