Evanovich has asked for the wisdom of the Perl Monks concerning the following question:
Any help would be most most appreciated. Thanks! EvanMODULE = f PACKAGE = f #include "math.h" #define PI 3.1459 char * f(rows, cols, packedmatrix) int rows int cols char * packedmatrix CODE: float **M; float len1, len2, dotproduct; int k1; int k2; int k3; float theta; float product; char * packedangles; float angles[cols][cols]; M = (float**)packedmatrix; for (k1 = 0; k1<(cols-1); ++k1) { for (k2 = (k1+1); k2<(cols); ++k2) { dotproduct = 0; len1 = 0; len2 = 0; for (k3 = 0; k3 < rows; ++k3) { if ((M[k3][k1] != 999) && (M[k3][k2] != 999)) { dotproduct = dotproduct + (M[k3][k1])*(M[k3][k2]); len1 = len1 + pow((M[k3][k1]), 2); len2 = len2 + pow((M[k3][k2]), 2); } } theta = 180*(acos(dotproduct/sqrt(len1*len2)))/PI; angles[k1][k2]=theta; printf("The angle between columns %d and columns %d is %f\n\n", k +1, k2, theta); } packedangles = (char*)angles; printf("Packed angles: %s", packedangles); RETVAL = packedangles; } OUTPUT: RETVAL
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: Sending packed data from C to Perl
by tye (Sage) on Aug 07, 2001 at 00:14 UTC |