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[0]: from Node = XYZ[0] to_Node = XYZ[9] )
0 8
0 1
1 5
2 1
2 5
3 3
3 1
3 6
4 2
4 7     ( edge 11 or NODES[10]: from Node = XYZ[4] to_Node = XYZ[7] )

XYZ

6294937.441867 1978476.663700   34.3    /* index [0] */
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 [9] */

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[0]: from Node = XYZ[0] to_Node = XYZ[9] )
> 0 8
> 0 1
> 1 5
> 2 1
> 2 5
> 3 3
> 3 1
> 3 6
> 4 2
> 4 7        ( edge 11 or NODES[10]: from Node = XYZ[4] to_Node = XYZ[7] )

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[20] and
NODES[21]?

- 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  
 
 [ 2 post ] 

 Relevant Pages 

1. Proplems writing long binary data to Access using CDaoRecordset

2. Retrieve raw data (counter value) from windows register

3. addition long values to long double value ?

4. How to get the value of a counter (AutoIncrement) field using MFC DAO classes

5. How to get the value of a counter (AutoIncrement) field using MFC DAO classes

6. having two separate values in one long

7. pointer to an array OF pointers to integer data types

8. Converting LONG value to CHAR array

9. using if..else w/ string values... (LONG)

10. fprintf, using unsigned long values

11. How to insert LONG RAW values using ADO

12. How to send INT/LONG values through COM port using MSComm control

 

 
Powered by phpBB® Forum Software