17 fprintf(stderr,
" run_time error......\n");
18 fprintf(stderr,
"%s\n", error_text);
19 fprintf(stderr,
".....now exiting to system.....\n");
28 v = (
float *)malloc((
size_t)((nh - nl + 1 +
NR_END) *
sizeof(
float)));
29 if (!v)
nrerror(
"allocation failure in vector()");
38 v = (
int *)malloc((
size_t)((nh - nl + 1 +
NR_END) *
sizeof(
int)));
39 if (!v)
nrerror(
"allocation failure in ivector()");
48 v = (
unsigned char *)malloc(
49 (
size_t)((nh - nl + 1 +
NR_END) *
sizeof(
unsigned char)));
50 if (!v)
nrerror(
"allocation failure in cvector()");
59 v = (
unsigned long *)malloc((
size_t)((nh - nl + 1 +
NR_END) *
sizeof(
long)));
60 if (!v)
nrerror(
"allocation failure in lvector()");
69 v = (
double *)malloc((
size_t)((nh - nl + 1 +
NR_END) *
sizeof(
double)));
70 if (!v)
nrerror(
"allocation failure in dvector()");
74float **
fmatrix(
long nrl,
long nrh,
long ncl,
long nch)
77 long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
81 m = (
float **)malloc((
size_t)((nrow +
NR_END) *
sizeof(
float *)));
82 if (!m)
nrerror(
"allocation failure 1 in matrix()");
87 m[nrl] = (
float *)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
float)));
88 if (!m[nrl])
nrerror(
"allocation failure 2 in matrix()");
92 for (i = nrl + 1; i <= nrh; i++) m[i] = m[i - 1] + ncol;
98double **
dmatrix(
long nrl,
long nrh,
long ncl,
long nch)
101 long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
105 m = (
double **)malloc((
size_t)((nrow +
NR_END) *
sizeof(
double *)));
106 if (!m)
nrerror(
"allocation faliore 1 in matrix()");
111 m[nrl] = (
double *)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
double)));
112 if (!m[nrl])
nrerror(
"allocation faliore 2 in matrix()");
116 for (i = nrl + 1; i <= nrh; i++) m[i] = m[i - 1] + ncol;
122int **
imatrix(
long nrl,
long nrh,
long ncl,
long nch)
125 long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
129 m = (
int **)malloc((
size_t)((nrow +
NR_END) *
sizeof(
int *)));
130 if (!m)
nrerror(
"allocation faliore 1 in matrix()");
135 m[nrl] = (
int *)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
int)));
136 if (!m[nrl])
nrerror(
"allocation falior 2 in matrix()");
140 for (i = nrl + 1; i <= nrh; i++) m[i] = m[i - 1] + ncol;
146float **
submatrix(
float **a,
long oldrl,
long oldrh,
long oldcl,
long ,
147 long newrl,
long newcl)
150 long i, j, nrow = oldrh - oldrl + 1, ncol = oldcl - newcl;
154 m = (
float **)malloc((
size_t)((nrow +
NR_END) *
sizeof(
float *)));
155 if (!m)
nrerror(
" allocation failure in submatrix()");
160 for (i = oldrl, j = newrl; i <= oldrh; i++, j++) m[j] = a[i] + ncol;
172 long i, j, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
176 m = (
float **)malloc((
size_t)((nrow +
NR_END) *
sizeof(
float *)));
177 if (!m)
nrerror(
" allocation failure in convert_matrix()");
183 for (i = 1, j = nrl + 1; i < nrow; i++, j++) m[j] = m[j - 1] + ncol;
188float ***
f3tensor(
long nrl,
long nrh,
long ncl,
long nch,
long ndl,
long ndh)
191 long i, j, nrow = nrh - nrl + 1, ncol = nch - ncl + 1, ndep = ndh - ndl + 1;
195 t = (
float ***)malloc((
size_t)((nrow +
NR_END) *
sizeof(
float **)));
196 if (!t)
nrerror(
"allocation failure 1 in f3tensor()");
201 t[nrl] = (
float **)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
float *)));
202 if (!t[nrl])
nrerror(
"allocation failure 2 in f3tensor()");
208 (
float *)malloc((
size_t)((nrow * ncol * ndep +
NR_END) *
sizeof(
float)));
209 if (!t[nrl][ncl])
nrerror(
"allocation failure 3 in f3tensor()");
213 for (j = ncl + 1; j <= nch; j++) t[nrl][j] = t[nrl][j - 1] + ndep;
214 for (i = nrl + 1; i <= nrh; i++) {
215 t[i] = t[i - 1] + ncol;
216 t[i][ncl] = t[i - 1][ncl] + ncol * ndep;
217 for (j = ncl + 1; j <= nch; j++) t[i][j] = t[i][j - 1] + ndep;
223double ***
d3tensor(
long nrl,
long nrh,
long ncl,
long nch,
long ndl,
long ndh)
227 long i, j, nrow = nrh - nrl + 1, ncol = nch - ncl + 1, ndep = ndh - ndl + 1;
231 t = (
double ***)malloc((
size_t)((nrow +
NR_END) *
sizeof(
double **)));
232 if (!t)
nrerror(
"allocation failure 1 in d3tensor()");
238 (
double **)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
double *)));
239 if (!t[nrl])
nrerror(
"allocation failure 2 in d3tensor()");
244 t[nrl][ncl] = (
double *)malloc(
245 (
size_t)((nrow * ncol * ndep +
NR_END) *
sizeof(
double)));
246 if (!t[nrl][ncl])
nrerror(
"allocation failure 3 in d3tensor()");
250 for (j = ncl + 1; j <= nch; j++) t[nrl][j] = t[nrl][j - 1] + ndep;
251 for (i = nrl + 1; i <= nrh; i++) {
252 t[i] = t[i - 1] + ncol;
253 t[i][ncl] = t[i - 1][ncl] + ncol * ndep;
254 for (j = ncl + 1; j <= nch; j++) t[i][j] = t[i][j - 1] + ndep;
261double ****
d4tensor(
long nrl,
long nrh,
long ncl,
long nch,
long ndl,
long ndh,
266 long i, j, k, nrow = nrh - nrl + 1, ncol = nch - ncl + 1,
267 ndep = ndh - ndl + 1, nwid = nwh - nwl + 1;
271 t = (
double ****)malloc((
size_t)((nrow +
NR_END) *
sizeof(
double ***)));
272 if (!t)
nrerror(
"allocation failure 1 in d4tensor()");
278 (
double ***)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
double **)));
279 if (!t[nrl])
nrerror(
"allocation failure 2 in d4tensor()");
284 t[nrl][ncl] = (
double **)malloc(
285 (
size_t)((nrow * ncol * ndep +
NR_END) *
sizeof(
double *)));
286 if (!t[nrl][ncl])
nrerror(
"allocation failure 3 in d4tensor()");
291 t[nrl][ncl][ndl] = (
double *)malloc(
292 (
size_t)((nrow * ncol * ndep * nwid +
NR_END) *
sizeof(
double)));
293 if (!t[nrl][ncl][ndl])
nrerror(
"allocation failure 4 in d4tensor()");
294 t[nrl][ncl][ndl] +=
NR_END;
295 t[nrl][ncl][ndl] -= nwl;
297 for (i = nrl; i <= nrh; i++) {
299 t[i] = t[i - 1] + ncol;
300 t[i][ncl] = t[i - 1][ncl] + ncol * ndep;
301 t[i][ncl][ndl] = t[i - 1][ncl][ndl] + ncol * ndep * nwid;
303 for (j = ncl; j <= nch; j++) {
305 t[i][j] = t[i][j - 1] + ndep;
306 t[i][j][ndl] = t[i][j - 1][ndl] + ndep * nwid;
309 for (k = ndl; k <= ndh; k++) {
310 if (k > ndl) t[i][j][k] = t[i][j][k - 1] + nwid;
351 for(j=ncl+1;j<=nch;j++) tt[nrl][j]=tt[nrl][j-1]+ndep;
352 for(i=nrl+1;i<=nrh;i++)
354 tt[i][ncl]=tt[i-1][ncl]+ncol*ndep;
355 for(j=ncl+1;j<=nch;j++)
356 tt[i][j]=tt[i][j-1]+ndep;
359 for(k=ndl+1;k<=ndh;k++) tt[nrl][ncl][k]=tt[nrl][ncl][k-1]+nsext; //
362 for(i=nrl+1;i<=nrh;i++) // (1~nrh;0;0~ndh).
364 tt[i][ncl][ndl]=tt[i-1][ncl][ndl]+ncol*ndep*nsext;
365 for(k=ndl+1;k<=ndh;k++)
366 tt[i][ncl][k]=tt[i][ncl][k-1]+nsext;
368 for(j=ncl+1;j<=nch;j++) // (0;1~nch;0~ndh).
370 tt[nrl][j][ndl]=tt[nrl][j-1][ndl]+ndep*nsext;
371 for(k=ndl+1;k<=ndh;k++)
372 tt[nrl][j][k]=tt[nrl][j][k-1]+nsext;
375 for(i=nrl+1;i<=nrh;i++) //
378 tt[i][ncl][ndl]=tt[i-1][ncl][ndl]+ncol*ndep*nsext;
379 for(j=ncl+1;j<=nch;j++)
381 tt[i][j][ndl]=tt[i][j-1][ndl]+ndep*nsext;
382 for(k=ndl+1;k<=ndh;k++)
383 tt[i][j][k]=tt[i][j][k-1]+nsext;
386 // return pointer to array of pointers to rows
392double ****d4tensor(long nrl, long nrh, long ncl, long nch, long ndl, long
393ndh,long nd4l,long nd4h)
395// allocate a double d4tensor with range
396t[nrl..nrh][ncl..nch][ndl..ndh][nd4l..nd4h]
398 long i, j, k, nrow=nrh-nrl+1, ncol=nch-ncl+1,
399ndep=ndh-ndl+1,nd4th=nd4h-nd4l+1; double ****t;
401 // allocate pointers to pointers to pointers to rows
402 t=(double ****) malloc((size_t)((nrow+NR_END)*sizeof(double***)));
403 if(!t) nrerror("allocation failure 1 in d4tensor()");
407 // allocate pointers to pointers to rows and set pointers to them
408 t[nrl]=(double ***) malloc((size_t)((nrow*ncol+NR_END)*sizeof(double**)));
409 if(!t[nrl]) nrerror("allocation failure 2 in d4tensor()");
413 // allocate pointers to rows and set pointers to them
414 t[nrl][ncl]=(double **)
415malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(double*))); if(!t[nrl][ncl])
416nrerror("allocation failure 3 in d4tensor()"); t[nrl][ncl] += NR_END;
419 // allocate rows and set pointers to them
420 t[nrl][ncl][ndl]=(double *)
421malloc((size_t)((nrow*ncol*ndep*nd4th+NR_END)*sizeof(double)));
422 if(!t[nrl][ncl][ndl]) nrerror("allocation failure 4 in d4tensor()");
423 t[nrl][ncl][ndl] += NR_END;
424 t[nrl][ncl][ndl] -= nd4l;
426 for(k=ndl+1; k<=ndh; k++) t[nrl][ncl][k]=t[nrl][ncl][k-1]+nd4th;
427 for(j=ncl+1; j<=nch; j++)
429 t[nrl][j]=t[nrl][j-1]+ndep;
430 t[nrl][j][ndl]=t[nrl][j-1][ndl]+ndep*nd4th;
431 for(k=ndl+1; k<=ndh; k++)t[nrl][j][k]=t[nrl][j][k-1]+nd4th;
433 for(i=nrl+1; i<=nrh; i++)
436 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
437 for(j=ncl+1; j<=nch; j++)
439 t[i][j]=t[i][j-1]+ndep;
440 t[i][j][ndl]=t[i][j-1][ndl]+ndep*nd4th;
441 for(k=ndl+1; k<=ndh; k++)t[i][j][k]=t[i][j][k-1]+nd4th;
445 // return pointer to array of pointers to rows
524 long ndl,
long ,
long nwl,
long ) {
unsigned long * lvector(long nl, long nh)
unsigned char * cvector(long nl, long nh)
void free_fmatrix(float **m, long nrl, long, long ncl, long)
float ** convert_matrix(float *a, long nrl, long nrh, long ncl, long nch)
float ** fmatrix(long nrl, long nrh, long ncl, long nch)
void free_dmatrix(double **m, long nrl, long, long ncl, long)
float * fvector(long nl, long nh)
void free_dvector(double *v, long nl, long)
void free_convert_matrix(float **b, long nrl, long, long, long)
void free_f3tensor(float ***t, long nrl, long, long ncl, long, long ndl, long)
double *** d3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
double **** d4tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh, long nwl, long nwh)
float *** f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
void free_d4tensor(double ****t, long nrl, long, long ncl, long, long ndl, long, long nwl, long)
void free_submatrix(float **b, long nrl, long, long, long)
int * ivector(long nl, long nh)
void free_lvector(unsigned long *v, long nl, long)
double ** dmatrix(long nrl, long nrh, long ncl, long nch)
int ** imatrix(long nrl, long nrh, long ncl, long nch)
void free_ivector(int *v, long nl, long)
double * dvector(long nl, long nh)
void free_cvector(unsigned char *v, long nl, long)
void free_d3tensor(double ***t, long nrl, long, long ncl, long, long ndl, long)
void free_imatrix(int **m, long nrl, long, long ncl, long)
void free_fvector(float *v, long nl, long)
float ** submatrix(float **a, long oldrl, long oldrh, long oldcl, long, long newrl, long newcl)