baffling arrays problem

From: news (tperzo_at_wanadoo.fr)
Date: 08/26/04


Date: Thu, 26 Aug 2004 17:13:07 +0000

hello one and all,
right, I've been battling with f77 on a linux machine for 4 days now on what
seems a stupid problem, but I simply do not see what's wrong.
hope someone can help.
here is a short version of a code I am writing (hopefully error free):

definitions :
parameter (no_of_files=13)
integer kw(no_of_files,high),ukl(no_of_files,high),non_single
integer kdf(no_of_files),kfi(no_of_files,high)
char*5 kni(no_of_files,high),kl(no_of_files,high)

main prog :
30 read a file whose index within the prog is file_number
      file_number=file_number+1 ! (=<no_of_files)
      ! a loop defines non_single
      do 10,icount=1,non_single
        kdf(file_number)=kdf(file_number)+1
        kni(file_number,kdf(file_number))=kl(file_number,i)
        kfi(file_number,kdf(file_number))=1+icount
        kw (file_number,kdf(file_number))=2+icount (*)
        ukl(file_number,kdf(file_number))=5+icount (**)
10 continue

----------

        do 20, icount=1,file_number
          do 40, jcount=1,kdf(icount)
                write (*,60) icount,kni(icount,jcount),kfi(icount,jcount),
                             ukl(icount,jcount),kw(icount,jcount)
60 format (---stuff----)
40 continue
20 continue
        goto 30
#######
(the names of the vars are not the actual one : I used initials for
readability)
right, so until the dashed line I assign values (char or number) to arrays.
no problem
the problem is SEEN (I am not saying that's WHERE it is) in the write
statement after the dashed line :
basically what it does it print to the screen all contents of all arrays
from file_number=1 to whatever value it has at any given time. (cxy =
character array at index x,y; nxy = number at index x,y)

so: file_number=1 gives
1 c11 n11 n11 n11
1 c12 n12 n12 n12
1 c13 n13 n13 n13
 etc down to y=kdf(1)

file_number = 3 gives (skipping 2 to get the idea quicker)
1 c11 n11 n11 n11
1 c12 n12 n12 n12
1 c13 n13 n13 n13
 etc down to y=kdf(1)
2 c21 n21 n21 n21
2 c22 n22 n22 n22
2 c23 n23 n23 n23
 etc down to y=kdf(2)
3 c31 n31 n31 n31
3 c32 n32 n32 n32
3 c33 n33 n33 n33
 etc down to y=kdf(3)

fine so far ... except that, what's above is what is SHOULD give!
what I actually get is (going straight to file_number=3 to see clearly since
the file_number=1 case is going to be identical to the one above) :

file_number = 3
1 c11 n11 n11 538976288
1 c12 n12 n12 538976288
1 c13 n13 n13 538976288
 etc down to y=kdf(1)
2 c21 n21 n21 538976288
2 c22 n22 n22 538976288
2 c23 n23 n23 538976288
 etc down to y=kdf(2)
3 c31 n31 n31 n31
3 c32 n32 n32 n32
3 c33 n33 n33 n33
 etc down to y=kdf(2)

in other words all arrays work fine except for kw (marked *) above, which
"forgets" its contents for all cases of file_number except the current one!
I initially thought about a memory problem and so explored a number of
avenues, to no avail. eventually I added ukl array as a test, which I did
not have initially (marked (**) above, meaning of course that the fourth
column for each case was absent), and ukl work fine!
so, my question is :
1) why would this behaviour occur since the definition and use of kw is
identical to the others
2) why kw in particular ?

i am sure this indicates a particular type of error (like segmentation fault
actual means an array boundary error), but I have no idea what, and why
this 538976288 ?

that's it. hope you computer whizzes out there can figure this out. I am
fresh out of ideas and although I can use ukl instead of kw, I feel uneasy
about leaving something like this which may hide some deeper problem that
would kick me in the backside later.

thanks everyone
G.


Quantcast