Using values of one array as pointer counters to access data in another ( long )
Author Message Using values of one array as pointer counters to access data in another ( long )

I wish to compute slopes for every x,y,z pair stored in array in memory
by using the values of another node array as the index value access key.
I want to group the slope values that touch each node. This means
keeping track of all pairs which contain a "0", then each that contain
a "1", etc. etc.

NODES:

0 9     ( edge 1 or NODES: from Node = XYZ to_Node = XYZ )
0 8
0 1
1 5
2 1
2 5
3 3
3 1
3 6
4 2
4 7     ( edge 11 or NODES: from Node = XYZ to_Node = XYZ )

XYZ

6294937.441867 1978476.663700   34.3    /* index  */
6294927.074852 1978476.663700   43.2
6294840.346767 1978476.663700   31.0
6294771.949283 1978476.663700   11.5
6294717.597635 1978476.663700   34.3
6294632.545078 1978476.663700   31.7
6294603.207931 1978476.663700   45.9
6294568.537736 1978476.663700   23.3
6294545.412359 1978476.663700   22.1
6294497.767143 1978476.663700   19.2    /* index  */

I have a program that uses pointers to structures and then reads the
arrays above ( these arrays are written to memory by a previous function
call)

My program seeks to do the following:

1) read the first number from the NODES array ( in this case "0" )
2) use this value as a counter (pointer incrementation) for how many
rows down the XYZ array to go to reteive the first x,y,z value pair. (
for loop )
3) reset the XYZ pointer to the beginning of that array.
4) read the second number from the NODES array ( in this case "9")
5) use this value in the same manner as in step 2. ( for loop )
6) compute slopes for every coordinate pair who's index #'sinclude  "0".
7) repeat steps 1-6 for every coordinate pair who's index#'s include
"1".
8)  "       "     "   "   "        "       "          "           "
"2".
etc....etc...etc...

9) continue until all values of NODES array have been read and all XYZ
pairs are fetched.

The problem is that I need to process only a subset at a time. I only
want to consider those NODES values which contain a 0, do calculations
on those, then fetch those pairs who's NODES values contain a 1, etc.
I have a variable passed to my function called n_Edges which makes sure
I don't read past the last member of the NODES array. The number of
elements in the XYZ array is equal to the maximum value in the NODES
array ( in this case 9 ).

right now I have the following implementation ( pseudo-code ).
It compiles, but it doesn't behave the way I want it to....

calc_Slopes(double* XYZ, long* NODES, long n_Points,long n_Edges)
{
for loop ( counter = 1st value of NODES
check if number of NODES values read <= n_Edges
increment counter

if( 1st value of NODES or 2nd value of NODES) == counter
/* fails when 1st value of Nodes increases from 0 to 1. */

for loop#1 ( counter = 0
check that counter <= 1st value read from NODES
increment counter
increment pointer to XYZ by value of counter
x1 = XYZ.X
y1 = XYZ.Y
Z1 = XYZ.Z

for loop#2 ( counter = 0
check that counter <= 2nd value read from NODES
increment counter
increment pointer to XYZ by value of counter

x2 = XYZ.X
y2 = XYZ.Y
z2 = XYZ.Z

calculate slopes using x1,x2,y1,y2,z1,z2;
check slopes against threshold value.
save slopes above this value in another array.
reset pointer to XYZ to point to its beginning.

the program works only for each pair of numbers in NODES that have a
"0".
when the 4th record ( 1 5 ) is encountered.. the processing terminates.
Does anyone know of a construct I can use to get around this ?

feedback much appreciated....

Sent via Deja.com http://www.*-*-*.com/
Share what you know. Learn what you don't.

Sat, 15 Dec 2001 03:00:00 GMT  Using values of one array as pointer counters to access data in another ( long )

Quote:

> I wish to compute slopes for every x,y,z pair stored in array in memory
> by using the values of another node array as the index value access key.
> I want to group the slope values that touch each node. This means
> keeping track of all pairs which contain a "0", then each that contain
> a "1", etc. etc.

> NODES:

> 0 9     ( edge 1 or NODES: from Node = XYZ to_Node = XYZ )
> 0 8
> 0 1
> 1 5
> 2 1
> 2 5
> 3 3
> 3 1
> 3 6
> 4 2
> 4 7        ( edge 11 or NODES: from Node = XYZ to_Node = XYZ )

From your numbering, an element of the array NODES must be able
to store two indices into XYZ.  Later you declare NODES as an
array of longs; so is edge 11 actually stored in NODES and
NODES?

- Show quoted text -

Quote:
> I have a program that uses pointers to structures and then reads the
> arrays above ( these arrays are written to memory by a previous function
> call)

> My program seeks to do the following:

> 1) read the first number from the NODES array ( in this case "0" )
> 2) use this value as a counter (pointer incrementation) for how many
> rows down the XYZ array to go to reteive the first x,y,z value pair. (
> for loop )
> 3) reset the XYZ pointer to the beginning of that array.
> 4) read the second number from the NODES array ( in this case "9")
> 5) use this value in the same manner as in step 2. ( for loop )
> 6) compute slopes for every coordinate pair who's index #'sinclude  "0".
> 7) repeat steps 1-6 for every coordinate pair who's index#'s include
> "1".
> 8)  "       "     "   "   "        "       "          "           "
> "2".
> etc....etc...etc...

> 9) continue until all values of NODES array have been read and all XYZ
>    pairs are fetched.

A top down description of what you need to do would be more
helpful: e.g., at the top level, indicate how you decide which node
to concentrate on, and then at the next refinement, indicate
what processing on the selected node is performed.

Quote:
> The problem is that I need to process only a subset at a time. I only
> want to consider those NODES values which contain a 0, do calculations
> on those, then fetch those pairs who's NODES values contain a 1, etc.

Have you written a program that works correctly for all nodes?

Quote:
> I have a variable passed to my function called n_Edges which makes sure
> I don't read past the last member of the NODES array. The number of
> elements in the XYZ array is equal to the maximum value in the NODES
> array ( in this case 9 ).

Is that 9 or 10?

Quote:
> right now I have the following implementation ( pseudo-code ).
> It compiles, but it doesn't behave the way I want it to....

I'm surprised you haven't gotten any responses pointing out that
pseudo-code is not intended to compile, and the code you give
is obviously not the code that's compiling.

Quote:
> calc_Slopes(double* XYZ, long* NODES, long n_Points,long n_Edges)
[snip]
>                    x1 = XYZ.X
>                    y1 = XYZ.Y
>                    Z1 = XYZ.Z

If XYZ is an array of doubles, how can it have X, Y and Z
components, even if you meant XYZ[i].X, XYZ[i].Y, etc?  There
seems to be a similar problem with NODES, but your pseudo-code
is too vague to be sure.

You are either handling your arrays in too loose a manner, or else
just describing the handling in too loose a manner.

--
MJSR

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Sat, 15 Dec 2001 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages