Welcome to Intel® Software Network Quick Login | Join | Help |
Search in Intel® Software Network Forums
in Go

Array's Loosing their values outside of the loop that assigned them.

Last post 05-15-2008, 7:46 AM by Steve Lionel. 1 replies.
Sort Posts: Previous Next
 05-15-2008, 6:14 AM 30254887  

Array's Loosing their values outside of the loop that assigned them.


I've been programming for 30+ years and this one has me stumped.


Here's the code: (The code in lower case is my debugging code.)
<...snip...>
REAL SLOPE(100),CAREA(100)

real slope2(100), carea2(100)
<...snip...>
C FIND THE AVERAGE SLOPE IN EACH CONTOUR INTERVAL
C FIND INDEX OF THE RIDGE LINE AND STORE IN KRIDGE
KRIDGE=0
write(6,9997)
9997 FORMAT(' I II Area CArea(II) Slope(II) PerD
+is Elev(I) Elev(II)')
DO 100 I=2,NCTRS
IF(ELEV(I-1).EQ.0.) KRIDGE=I-1
IF(ELEV(I).EQ.0.) KRIDGE=I
CALL INTRVL(NPTS,XCTR,YCTR,I,PERDIS,AREA,NCMAX,NPMAX,S1,S2,S3,
$ 1,NPTS(I-1),1,NPTS(I))
II=I-1
CAREA(II)=AREA
SLOPE(II)=ABS(ELEV(I)-ELEV(II))/PERDIS
carea2(ii)=area
slope2(ii)=slope(ii)
write(6,9999) i,ii,area,carea(ii),slope(ii),perdis,elev(i),
+elev(ii)
100 CONTINUE
if (debug_flag) then
write(6,9998)
9998 format('carea and slope output',/
+' i ii carea(i) carea2(i) slope(i) slope2(i)')
do 5001 i=1,nctrs-1
write(6,9999) i,i,carea(i),carea2(i),slope(i),slope2(i)
9999 format(2i4,6f13.4)
5001 continue
endif
<...snip...>

The process is simple enough, work through a series of contours (XCTR, YCTR) and CALL INTRVL to return the AREA between the contours. Save the AREA in the CAREA() array and calculate the slope into the SLOPE() array.  When I assign a value inside a loop and immediately print it back out I expect the get the same values back as were assigned.  That's not what I'm getting.  Here's my output:
 I    II  Area           CArea(II)      Slope(II)     PerDis       Elev(I)     Elev(II)
   2   1   25276.6875   25276.6875      37.8375      21.2488     804.0000       0.0000
   3   2  265195.9375  265195.9375       0.0103     193.8802     802.0000     804.0000
   4   3  255536.3594  255536.3594       0.0172     116.5833     800.0000     802.0000
   5   4  910855.3125  910855.3125       0.0056     357.2104     798.0000     800.0000
   6   5 1059779.5000 1059779.5000       0.0050     399.8702     796.0000     798.0000
   7   6 1794443.0000 1794443.0000       0.0030     673.8806     794.0000     796.0000
   8   7 1186198.2500 1186198.2500       0.0043     461.6170     792.0000     794.0000
   9   8 1128319.8750 1128319.8750       0.0044     455.9271     790.0000     792.0000
  10   9  682406.4375  682406.4375       0.0069     291.9580     788.0000     790.0000
  11  10  169926.9375  169926.9375       0.0253      79.0579     786.0000     788.0000
  12  11   33344.5469   33344.5469       0.1160      17.2381     784.0000     786.0000
  13  12   67756.9375   67756.9375       0.0513      39.0164     782.0000     784.0000
  14  13   78870.6172   78870.6172       0.0404      49.5028     780.0000     782.0000
  15  14   73929.4531   73929.4531       0.0363      55.1556     778.0000     780.0000
  16  15   65075.1406   65075.1406       0.0311      64.2501     776.0000     778.0000
  17  16   46608.5625   46608.5625       0.0283      70.7828     774.0000     776.0000
  18  17  364544.0000  364544.0000       4.1337     186.0298       5.0000     774.0000
carea and slope output
 i    ii  carea(i)       carea2(i)      slope(i)      slope2(i)
   1   1    1273.5800    1772.1899    1568.2200      37.8375
   2   2    1277.0200    1773.1300    1568.3101       0.0103
   3   3    1279.9900    1773.4301    1567.9800       0.0172
   4   4    1282.4301    1773.1500    1567.2100       0.0056
   5   5    1284.3101    1772.3199    1566.1500       0.0050
   6   6    1285.6801    1771.0400    1564.6600       0.0030
   7   7    1286.5800    1769.3500    1562.7200       0.0043
   8   8    1287.0699 1128319.8750    1560.3700       0.0044
   9   9    1287.5100  682406.4375    1557.6100       0.0069
  10  10    1288.3700  169926.9375       0.0253       0.0253
  11  11    1290.2100   33344.5469       0.1160       0.1160
  12  12    1291.4301   67756.9375       0.0513       0.0513
  13  13   78870.6172   78870.6172       0.0404       0.0404
  14  14   73929.4531   73929.4531       0.0363       0.0363
  15  15   65075.1406   65075.1406       0.0311       0.0311
  16  16   46608.5625   46608.5625       0.0283       0.0283
  17  17  364544.0000  364544.0000       4.1337       4.1337
As you can see, the values of CAREA are being overwritten by something somewhere somehow.  The copy of the CAREA (CAREA2) is less damaged by the mysterious process and SLOPE2 ends up just fine.  But I really need to know what's up with the data corruption in the CAREA and SLOPE arrays.

I hope this the result of a simple and boneheaded mistake on my part as those are easily fixed.

Thanks for your assistance.
 
 05-15-2008, 7:46 AM 30254893 in reply to 30254887  

Re: Array's Loosing their values outside of the loop that assigned them.

First, when you write out the values immediately after setting them, you ARE getting the same values.  It's only at the end of the loop when you look again that the values change.  My guess is that the call to INTRVL is corrupting the data due to mismatched argument declarations or out-of-bounds array references.

This is pretty easy to diagnose.  Step through the loop in the debugger until one element of CAREA is set.  Add a QuickWatch of that element in the debugger.  Now step through the next iteration of the loop and into the call to INTRVL.  Step line by line and watch the displayed value of the CAREA element to see when it changes.

You may also want to make sure that array bounds checking and interface checking are enabled.

Steve

Doctor Fortran: intel.com/software/drfortran
 
View as RSS news feed in XML

Shortcuts


Tags For This Post

...

Community Tags

...