FW: [R] Advice for calling a C function

From: Tuszynski, Jaroslaw W. <JAROSLAW.W.TUSZYNSKI_at_saic.com>
Date: Wed 27 Apr 2005 - 03:19:54 EST

I think it is a problem with matrices in R and C being stored in different row/column order

> void gowsim ( double *mat, int *OBJ, int *MATDESC) {
> double x [*MATDESC][*OBJ];
> int i, j, nrow, ncol;
> nrow = *OBJ;
> ncol = *MATDESC;
>
> /* Rebuild Matrix */
> for (j=0; j < ncol; j++) {
> for (i=0; i < nrow; i++) {
> x[i][j] = *mat;

Swapping x[i][j] to x[j][i] should fix the problem. Sorry, I did not test it.

> Rprintf("row %d col %d value %f\n", i, j, x[i][j]);
> mat++;
> }
> }
> for (i=0; i< nrow; i++) {
> Rprintf("%f %f %f %f\n", x[i][0], x[i][1], x[i][2], x[i][3]);
> }
>}

Jarek

====================================================\=======

 Jarek Tuszynski, PhD.                           o / \ 
 Science Applications International Corporation  <\__,|  
 (703) 676-4192                                   ">   \
 Jaroslaw.W.Tuszynski@saic.com                     `    \

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Apr 27 03:26:12 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:26 EST