1 #if defined(__STDC__) || defined(ANSI) || defined(NRANSI) 14 fprintf(stderr,
"Numerical Recipes run-time error...\n");
15 fprintf(stderr,
"%s\n",error_text);
16 fprintf(stderr,
"...now exiting to system...\n");
20 float *
vector(
long nl,
long nh)
25 v=(
float *)malloc((
size_t) ((nh-nl+1+
NR_END)*
sizeof(
float)));
26 if (!v)
nrerror(
"allocation failure in vector()");
35 v=(
int *)malloc((
size_t) ((nh-nl+1+
NR_END)*
sizeof(
int)));
36 if (!v)
nrerror(
"allocation failure in ivector()");
40 unsigned char *
cvector(
long nl,
long nh)
45 v=(
unsigned char *)malloc((
size_t) ((nh-nl+1+
NR_END)*
sizeof(
unsigned char)));
46 if (!v)
nrerror(
"allocation failure in cvector()");
50 unsigned long *
lvector(
long nl,
long nh)
55 v=(
unsigned long *)malloc((
size_t) ((nh-nl+1+
NR_END)*
sizeof(
long)));
56 if (!v)
nrerror(
"allocation failure in lvector()");
60 double *
dvector(
long nl,
long nh)
65 v=(
double *)malloc((
size_t) ((nh-nl+1+
NR_END)*
sizeof(
double)));
66 if (!v)
nrerror(
"allocation failure in dvector()");
70 float **
matrix(
long nrl,
long nrh,
long ncl,
long nch)
73 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
77 m=(
float **) malloc((
size_t)((nrow+
NR_END)*
sizeof(
float*)));
78 if (!m)
nrerror(
"allocation failure 1 in matrix()");
83 m[nrl]=(
float *) malloc((
size_t)((nrow*ncol+
NR_END)*
sizeof(
float)));
84 if (!m[nrl])
nrerror(
"allocation failure 2 in matrix()");
88 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
94 double **
dmatrix(
long nrl,
long nrh,
long ncl,
long nch)
97 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
101 m=(
double **) malloc((
size_t)((nrow+
NR_END)*
sizeof(
double*)));
102 if (!m)
nrerror(
"allocation failure 1 in matrix()");
107 m[nrl]=(
double *) malloc((
size_t)((nrow*ncol+
NR_END)*
sizeof(
double)));
108 if (!m[nrl])
nrerror(
"allocation failure 2 in matrix()");
112 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
118 int **
imatrix(
long nrl,
long nrh,
long ncl,
long nch)
121 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
125 m=(
int **) malloc((
size_t)((nrow+
NR_END)*
sizeof(
int*)));
126 if (!m)
nrerror(
"allocation failure 1 in matrix()");
132 m[nrl]=(
int *) malloc((
size_t)((nrow*ncol+
NR_END)*
sizeof(
int)));
133 if (!m[nrl])
nrerror(
"allocation failure 2 in matrix()");
137 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
143 float **
submatrix(
float **a,
long oldrl,
long oldrh,
long oldcl,
long oldch,
144 long newrl,
long newcl)
147 long i,j,nrow=oldrh-oldrl+1,ncol=oldcl-newcl;
151 m=(
float **) malloc((
size_t) ((nrow+
NR_END)*
sizeof(
float*)));
152 if (!m)
nrerror(
"allocation failure in submatrix()");
157 for(i=oldrl,j=newrl;i<=oldrh;i++,j++) m[j]=a[i]+ncol;
163 float **
convert_matrix(
float *a,
long nrl,
long nrh,
long ncl,
long nch)
169 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1;
173 m=(
float **) malloc((
size_t) ((nrow+
NR_END)*
sizeof(
float*)));
174 if (!m)
nrerror(
"allocation failure in convert_matrix()");
180 for(i=1,j=nrl+1;i<nrow;i++,j++) m[j]=m[j-1]+ncol;
185 float ***
f3tensor(
long nrl,
long nrh,
long ncl,
long nch,
long ndl,
long ndh)
188 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
192 t=(
float ***) malloc((
size_t)((nrow+
NR_END)*
sizeof(
float**)));
193 if (!t)
nrerror(
"allocation failure 1 in f3tensor()");
198 t[nrl]=(
float **) malloc((
size_t)((nrow*ncol+
NR_END)*
sizeof(
float*)));
199 if (!t[nrl])
nrerror(
"allocation failure 2 in f3tensor()");
204 t[nrl][ncl]=(
float *) malloc((
size_t)((nrow*ncol*ndep+
NR_END)*
sizeof(
float)));
205 if (!t[nrl][ncl])
nrerror(
"allocation failure 3 in f3tensor()");
209 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
210 for(i=nrl+1;i<=nrh;i++) {
212 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
213 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
250 void free_matrix(
float **m,
long nrl,
long nrh,
long ncl,
long nch)
257 void free_dmatrix(
double **m,
long nrl,
long nrh,
long ncl,
long nch)
264 void free_imatrix(
int **m,
long nrl,
long nrh,
long ncl,
long nch)
271 void free_submatrix(
float **b,
long nrl,
long nrh,
long ncl,
long nch)
283 void free_f3tensor(
float ***t,
long nrl,
long nrh,
long ncl,
long nch,
303 #define FREE_ARG char* 311 fprintf(stderr,
"Numerical Recipes run-time error...\n");
312 fprintf(stderr,
"%s\n",error_text);
313 fprintf(stderr,
"...now exiting to system...\n");
323 v=(
float *)malloc((
unsigned int) ((nh-nl+1+
NR_END)*
sizeof(
float)));
324 if (!v)
nrerror(
"allocation failure in vector()");
334 v=(
int *)malloc((
unsigned int) ((nh-nl+1+
NR_END)*
sizeof(
int)));
335 if (!v)
nrerror(
"allocation failure in ivector()");
345 v=(
unsigned char *)malloc((
unsigned int) ((nh-nl+1+
NR_END)*
sizeof(
unsigned char)));
346 if (!v)
nrerror(
"allocation failure in cvector()");
356 v=(
unsigned long *)malloc((
unsigned int) ((nh-nl+1+
NR_END)*
sizeof(
long)));
357 if (!v)
nrerror(
"allocation failure in lvector()");
367 v=(
double *)malloc((
unsigned int) ((nh-nl+1+
NR_END)*
sizeof(
double)));
368 if (!v)
nrerror(
"allocation failure in dvector()");
373 long nch,ncl,nrh,nrl;
376 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
380 m=(
float **) malloc((
unsigned int)((nrow+
NR_END)*
sizeof(
float*)));
381 if (!m)
nrerror(
"allocation failure 1 in matrix()");
386 m[nrl]=(
float *) malloc((
unsigned int)((nrow*ncol+
NR_END)*
sizeof(
float)));
387 if (!m[nrl])
nrerror(
"allocation failure 2 in matrix()");
391 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
398 long nch,ncl,nrh,nrl;
401 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
405 m=(
double **) malloc((
unsigned int)((nrow+
NR_END)*
sizeof(
double*)));
406 if (!m)
nrerror(
"allocation failure 1 in matrix()");
411 m[nrl]=(
double *) malloc((
unsigned int)((nrow*ncol+
NR_END)*
sizeof(
double)));
412 if (!m[nrl])
nrerror(
"allocation failure 2 in matrix()");
416 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
423 long nch,ncl,nrh,nrl;
426 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
430 m=(
int **) malloc((
unsigned int)((nrow+
NR_END)*
sizeof(
int*)));
431 if (!m)
nrerror(
"allocation failure 1 in matrix()");
437 m[nrl]=(
int *) malloc((
unsigned int)((nrow*ncol+
NR_END)*
sizeof(
int)));
438 if (!m[nrl])
nrerror(
"allocation failure 2 in matrix()");
442 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
448 float **
submatrix(a,oldrl,oldrh,oldcl,oldch,newrl,newcl)
450 long newcl,newrl,oldch,oldcl,oldrh,oldrl;
453 long i,j,nrow=oldrh-oldrl+1,ncol=oldcl-newcl;
457 m=(
float **) malloc((
unsigned int) ((nrow+
NR_END)*
sizeof(
float*)));
458 if (!m)
nrerror(
"allocation failure in submatrix()");
463 for(i=oldrl,j=newrl;i<=oldrh;i++,j++) m[j]=a[i]+ncol;
471 long nch,ncl,nrh,nrl;
477 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1;
481 m=(
float **) malloc((
unsigned int) ((nrow+
NR_END)*
sizeof(
float*)));
482 if (!m)
nrerror(
"allocation failure in convert_matrix()");
488 for(i=1,j=nrl+1;i<nrow;i++,j++) m[j]=m[j-1]+ncol;
494 long nch,ncl,ndh,ndl,nrh,nrl;
497 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
501 t=(
float ***) malloc((
unsigned int)((nrow+
NR_END)*
sizeof(
float**)));
502 if (!t)
nrerror(
"allocation failure 1 in f3tensor()");
507 t[nrl]=(
float **) malloc((
unsigned int)((nrow*ncol+
NR_END)*
sizeof(
float*)));
508 if (!t[nrl])
nrerror(
"allocation failure 2 in f3tensor()");
513 t[nrl][ncl]=(
float *) malloc((
unsigned int)((nrow*ncol*ndep+
NR_END)*
sizeof(
float)));
514 if (!t[nrl][ncl])
nrerror(
"allocation failure 3 in f3tensor()");
518 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
519 for(i=nrl+1;i<=nrh;i++) {
521 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
522 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
571 long nch,ncl,nrh,nrl;
580 long nch,ncl,nrh,nrl;
589 long nch,ncl,nrh,nrl;
598 long nch,ncl,nrh,nrl;
606 long nch,ncl,nrh,nrl;
614 long nch,ncl,ndh,ndl,nrh,nrl;
void free_submatrix(float **b, long nrl, long nrh, long ncl, long nch)
float *** f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
void free_imatrix(int **m, long nrl, long nrh, long ncl, long nch)
int ** imatrix(long nrl, long nrh, long ncl, long nch)
float ** submatrix(float **a, long oldrl, long oldrh, long oldcl, long oldch, long newrl, long newcl)
void free_lvector(unsigned long *v, long nl, long nh)
void free_ivector(int *v, long nl, long nh)
unsigned long * lvector(long nl, long nh)
double ** dmatrix(long nrl, long nrh, long ncl, long nch)
float * vector(long nl, long nh)
void free_dvector(double *v, long nl, long nh)
int * ivector(long nl, long nh)
void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
float ** matrix(long nrl, long nrh, long ncl, long nch)
void free_vector(float *v, long nl, long nh)
void free_convert_matrix(float **b, long nrl, long nrh, long ncl, long nch)
void free_dmatrix(double **m, long nrl, long nrh, long ncl, long nch)
void free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
float ** convert_matrix(float *a, long nrl, long nrh, long ncl, long nch)
double * dvector(long nl, long nh)
unsigned char * cvector(long nl, long nh)
void free_cvector(unsigned char *v, long nl, long nh)