njd7
02-09-2005, 06:06 PM
Hi,
Perhaps reflecting my naivete, I am having trouble with one of the most basic functions in NR, imatrix. I am calling the function as part of a simple sorting algorithm:
int bubble3(int *data,int start,int finish,int place)
{ int i,j,k,temp[2],switched=1,**data2;
data2=imatrix(start,finish,0,1);
....
This call to imatrix results in a segmentation fault at the end of the following code segment:
int **imatrix(long nrl, long nrh, long ncl, long nch)
/* allocate a int matrix with subscript range m[nrl..nrh][ncl..nch] */
{
long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
int **m;
/* allocate pointers to rows */
m=(int **) malloc((size_t)((nrow+NR_END)*sizeof(int*)));
....
I am quite perplexed why this causes problems. The integers start and finish take values 0 and 1, respectively, for this call. NR_END is set to the default 1. Also, imatrix has been successfully called at earlier points in my code.
Does anyone have any ideas about what could be causing the problem here? I would be very grateful.
Cheers,
Nick
Perhaps reflecting my naivete, I am having trouble with one of the most basic functions in NR, imatrix. I am calling the function as part of a simple sorting algorithm:
int bubble3(int *data,int start,int finish,int place)
{ int i,j,k,temp[2],switched=1,**data2;
data2=imatrix(start,finish,0,1);
....
This call to imatrix results in a segmentation fault at the end of the following code segment:
int **imatrix(long nrl, long nrh, long ncl, long nch)
/* allocate a int matrix with subscript range m[nrl..nrh][ncl..nch] */
{
long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
int **m;
/* allocate pointers to rows */
m=(int **) malloc((size_t)((nrow+NR_END)*sizeof(int*)));
....
I am quite perplexed why this causes problems. The integers start and finish take values 0 and 1, respectively, for this call. NR_END is set to the default 1. Also, imatrix has been successfully called at earlier points in my code.
Does anyone have any ideas about what could be causing the problem here? I would be very grateful.
Cheers,
Nick