[R] again question about nmath/standalone

xt_wang@cs.concordia.ca xt_wang at cs.concordia.ca
Thu Apr 15 00:03:10 CEST 2004


Hello,

I forgot to tell you that I am using Linux OS. And I can’t find 
directory "src/nmath/standalone". I will send you the test code I am using and 
the whole operation process. 

[credsim at confsys ~/src]$ gcc test1.c -o test1 -lRmath
test1.c: In function `main':
test1.c:18: warning: assignment makes pointer from integer without a cast
test1.c:19: warning: assignment makes pointer from integer without a cast
test1.c:41: warning: assignment makes pointer from integer without a cast
test1.c: At top level:
test1.c:55: warning: type mismatch with previous implicit declaration
test1.c:18: warning: previous implicit declaration of `Allocate_Memory_2D'
test1.c:55: warning: `Allocate_Memory_2D' was previously implicitly declared to 
return `int'
/usr/bin/ld: cannot find -lRmath
collect2: ld returned 1 exit status

"test1.c" code is as follow:

#define MATHLIB_STANDALONE
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include </usr/local/lib/R/include/Rmath.h>

 main()
{

  double **x, **y, **x1, **y1, valin;
  int i,j,I,J;
  

  I=3;
  J=3;

  x=Allocate_Memory_2D( I, J, x1);
  y=Allocate_Memory_2D( I, J, y1);


  FILE *in_file; 


    /* input x value from file data_2Dx.txt */ 
    in_file=fopen("data_2Dx.txt","r");
	if (in_file==NULL)
	{/*Test for error*/
		fprintf(stderr,"Error:Unable to input file 
from 'data_2Dx.txt'\n");
		exit(8);
	}
	for( i=0;i<I; i++)
	  for (j=0;j<J;j++)
	  { fscanf(in_file, "%lf\n", &valin, stdin);/* read a single double 
value in */
	       x[i][j]=valin;
		   valin=0.0;
	  }
	fclose(in_file);


   y=solve(x);

   for (i=0;i<I;i++)
     for (j=0;j<J;j++)
     {
       printf ("y[%d][%d]=%lf\n", i, j, y[i][j]);
     }



}


double **Allocate_Memory_2D( int I, int J, double **W)
{ 
	int i;

	W=(double **)malloc(I*sizeof (double *));
    if(!W)
      printf("It is out of memory. Allocation failed.");
	for (i=0;i<I;i++)
	{
        W[i]=(double *)malloc(J*sizeof(double));
        if(!W[i])
          printf("It is out of memory. Allocation failed.");
	}
	return (W);
}

Looking forward to your early reply! 

Thanks!

Maggie Wang




More information about the R-help mailing list