16 fprintf(stderr,
" run_time error......\n");
17 fprintf(stderr,
"%s\n", error_text);
18 fprintf(stderr,
".....now exiting to system.....\n");
27 v = (
float *)malloc((
size_t)((nh - nl + 1 +
NR_END) *
sizeof(
float)));
28 if (!v)
nrerror(
"allocation failure in vector()");
37 v = (
int *)malloc((
size_t)((nh - nl + 1 +
NR_END) *
sizeof(
int)));
38 if (!v)
nrerror(
"allocation failure in ivector()");
47 v = (
unsigned char *)malloc(
48 (
size_t)((nh - nl + 1 +
NR_END) *
sizeof(
unsigned char)));
49 if (!v)
nrerror(
"allocation failure in cvector()");
58 v = (
unsigned long *)malloc((
size_t)((nh - nl + 1 +
NR_END) *
sizeof(
long)));
59 if (!v)
nrerror(
"allocation failure in lvector()");
68 v = (
double *)malloc((
size_t)((nh - nl + 1 +
NR_END) *
sizeof(
double)));
69 if (!v)
nrerror(
"allocation failure in dvector()");
73float **
fmatrix(
long nrl,
long nrh,
long ncl,
long nch)
76 long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
80 m = (
float **)malloc((
size_t)((nrow +
NR_END) *
sizeof(
float *)));
81 if (!m)
nrerror(
"allocation failure 1 in matrix()");
86 m[nrl] = (
float *)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
float)));
87 if (!m[nrl])
nrerror(
"allocation failure 2 in matrix()");
91 for (i = nrl + 1; i <= nrh; i++) m[i] = m[i - 1] + ncol;
97double **
dmatrix(
long nrl,
long nrh,
long ncl,
long nch)
100 long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
104 m = (
double **)malloc((
size_t)((nrow +
NR_END) *
sizeof(
double *)));
105 if (!m)
nrerror(
"allocation faliore 1 in matrix()");
110 m[nrl] = (
double *)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
double)));
111 if (!m[nrl])
nrerror(
"allocation faliore 2 in matrix()");
115 for (i = nrl + 1; i <= nrh; i++) m[i] = m[i - 1] + ncol;
121int **
imatrix(
long nrl,
long nrh,
long ncl,
long nch)
124 long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
128 m = (
int **)malloc((
size_t)((nrow +
NR_END) *
sizeof(
int *)));
129 if (!m)
nrerror(
"allocation faliore 1 in matrix()");
134 m[nrl] = (
int *)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
int)));
135 if (!m[nrl])
nrerror(
"allocation falior 2 in matrix()");
139 for (i = nrl + 1; i <= nrh; i++) m[i] = m[i - 1] + ncol;
145float **
submatrix(
float **a,
long oldrl,
long oldrh,
long oldcl,
long ,
146 long newrl,
long newcl)
149 long i, j, nrow = oldrh - oldrl + 1, ncol = oldcl - newcl;
153 m = (
float **)malloc((
size_t)((nrow +
NR_END) *
sizeof(
float *)));
154 if (!m)
nrerror(
" allocation failure in submatrix()");
159 for (i = oldrl, j = newrl; i <= oldrh; i++, j++) m[j] = a[i] + ncol;
171 long i, j, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
175 m = (
float **)malloc((
size_t)((nrow +
NR_END) *
sizeof(
float *)));
176 if (!m)
nrerror(
" allocation failure in convert_matrix()");
182 for (i = 1, j = nrl + 1; i < nrow; i++, j++) m[j] = m[j - 1] + ncol;
187float ***
f3tensor(
long nrl,
long nrh,
long ncl,
long nch,
long ndl,
long ndh)
190 long i, j, nrow = nrh - nrl + 1, ncol = nch - ncl + 1, ndep = ndh - ndl + 1;
194 t = (
float ***)malloc((
size_t)((nrow +
NR_END) *
sizeof(
float **)));
195 if (!t)
nrerror(
"allocation failure 1 in f3tensor()");
200 t[nrl] = (
float **)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
float *)));
201 if (!t[nrl])
nrerror(
"allocation failure 2 in f3tensor()");
207 (
float *)malloc((
size_t)((nrow * ncol * ndep +
NR_END) *
sizeof(
float)));
208 if (!t[nrl][ncl])
nrerror(
"allocation failure 3 in f3tensor()");
212 for (j = ncl + 1; j <= nch; j++) t[nrl][j] = t[nrl][j - 1] + ndep;
213 for (i = nrl + 1; i <= nrh; i++) {
214 t[i] = t[i - 1] + ncol;
215 t[i][ncl] = t[i - 1][ncl] + ncol * ndep;
216 for (j = ncl + 1; j <= nch; j++) t[i][j] = t[i][j - 1] + ndep;
222double ***
d3tensor(
long nrl,
long nrh,
long ncl,
long nch,
long ndl,
long ndh)
226 long i, j, nrow = nrh - nrl + 1, ncol = nch - ncl + 1, ndep = ndh - ndl + 1;
230 t = (
double ***)malloc((
size_t)((nrow +
NR_END) *
sizeof(
double **)));
231 if (!t)
nrerror(
"allocation failure 1 in d3tensor()");
237 (
double **)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
double *)));
238 if (!t[nrl])
nrerror(
"allocation failure 2 in d3tensor()");
243 t[nrl][ncl] = (
double *)malloc(
244 (
size_t)((nrow * ncol * ndep +
NR_END) *
sizeof(
double)));
245 if (!t[nrl][ncl])
nrerror(
"allocation failure 3 in d3tensor()");
249 for (j = ncl + 1; j <= nch; j++) t[nrl][j] = t[nrl][j - 1] + ndep;
250 for (i = nrl + 1; i <= nrh; i++) {
251 t[i] = t[i - 1] + ncol;
252 t[i][ncl] = t[i - 1][ncl] + ncol * ndep;
253 for (j = ncl + 1; j <= nch; j++) t[i][j] = t[i][j - 1] + ndep;
260double ****
d4tensor(
long nrl,
long nrh,
long ncl,
long nch,
long ndl,
long ndh,
265 long i, j, k, nrow = nrh - nrl + 1, ncol = nch - ncl + 1,
266 ndep = ndh - ndl + 1, nwid = nwh - nwl + 1;
270 t = (
double ****)malloc((
size_t)((nrow +
NR_END) *
sizeof(
double ***)));
271 if (!t)
nrerror(
"allocation failure 1 in d4tensor()");
277 (
double ***)malloc((
size_t)((nrow * ncol +
NR_END) *
sizeof(
double **)));
278 if (!t[nrl])
nrerror(
"allocation failure 2 in d4tensor()");
283 t[nrl][ncl] = (
double **)malloc(
284 (
size_t)((nrow * ncol * ndep +
NR_END) *
sizeof(
double *)));
285 if (!t[nrl][ncl])
nrerror(
"allocation failure 3 in d4tensor()");
290 t[nrl][ncl][ndl] = (
double *)malloc(
291 (
size_t)((nrow * ncol * ndep * nwid +
NR_END) *
sizeof(
double)));
292 if (!t[nrl][ncl][ndl])
nrerror(
"allocation failure 4 in d4tensor()");
293 t[nrl][ncl][ndl] +=
NR_END;
294 t[nrl][ncl][ndl] -= nwl;
296 for (i = nrl; i <= nrh; i++) {
298 t[i] = t[i - 1] + ncol;
299 t[i][ncl] = t[i - 1][ncl] + ncol * ndep;
300 t[i][ncl][ndl] = t[i - 1][ncl][ndl] + ncol * ndep * nwid;
302 for (j = ncl; j <= nch; j++) {
304 t[i][j] = t[i][j - 1] + ndep;
305 t[i][j][ndl] = t[i][j - 1][ndl] + ndep * nwid;
308 for (k = ndl; k <= ndh; k++) {
309 if (k > ndl) t[i][j][k] = t[i][j][k - 1] + nwid;
350 for(j=ncl+1;j<=nch;j++) tt[nrl][j]=tt[nrl][j-1]+ndep;
351 for(i=nrl+1;i<=nrh;i++)
353 tt[i][ncl]=tt[i-1][ncl]+ncol*ndep;
354 for(j=ncl+1;j<=nch;j++)
355 tt[i][j]=tt[i][j-1]+ndep;
358 for(k=ndl+1;k<=ndh;k++) tt[nrl][ncl][k]=tt[nrl][ncl][k-1]+nsext; //
361 for(i=nrl+1;i<=nrh;i++) // (1~nrh;0;0~ndh).
363 tt[i][ncl][ndl]=tt[i-1][ncl][ndl]+ncol*ndep*nsext;
364 for(k=ndl+1;k<=ndh;k++)
365 tt[i][ncl][k]=tt[i][ncl][k-1]+nsext;
367 for(j=ncl+1;j<=nch;j++) // (0;1~nch;0~ndh).
369 tt[nrl][j][ndl]=tt[nrl][j-1][ndl]+ndep*nsext;
370 for(k=ndl+1;k<=ndh;k++)
371 tt[nrl][j][k]=tt[nrl][j][k-1]+nsext;
374 for(i=nrl+1;i<=nrh;i++) //
377 tt[i][ncl][ndl]=tt[i-1][ncl][ndl]+ncol*ndep*nsext;
378 for(j=ncl+1;j<=nch;j++)
380 tt[i][j][ndl]=tt[i][j-1][ndl]+ndep*nsext;
381 for(k=ndl+1;k<=ndh;k++)
382 tt[i][j][k]=tt[i][j][k-1]+nsext;
385 // return pointer to array of pointers to rows
391double ****d4tensor(long nrl, long nrh, long ncl, long nch, long ndl, long
392ndh,long nd4l,long nd4h)
394// allocate a double d4tensor with range
395t[nrl..nrh][ncl..nch][ndl..ndh][nd4l..nd4h]
397 long i, j, k, nrow=nrh-nrl+1, ncol=nch-ncl+1,
398ndep=ndh-ndl+1,nd4th=nd4h-nd4l+1; double ****t;
400 // allocate pointers to pointers to pointers to rows
401 t=(double ****) malloc((size_t)((nrow+NR_END)*sizeof(double***)));
402 if(!t) nrerror("allocation failure 1 in d4tensor()");
406 // allocate pointers to pointers to rows and set pointers to them
407 t[nrl]=(double ***) malloc((size_t)((nrow*ncol+NR_END)*sizeof(double**)));
408 if(!t[nrl]) nrerror("allocation failure 2 in d4tensor()");
412 // allocate pointers to rows and set pointers to them
413 t[nrl][ncl]=(double **)
414malloc((size_t)((nrow*ncol*ndep+NR_END)*sizeof(double*))); if(!t[nrl][ncl])
415nrerror("allocation failure 3 in d4tensor()"); t[nrl][ncl] += NR_END;
418 // allocate rows and set pointers to them
419 t[nrl][ncl][ndl]=(double *)
420malloc((size_t)((nrow*ncol*ndep*nd4th+NR_END)*sizeof(double)));
421 if(!t[nrl][ncl][ndl]) nrerror("allocation failure 4 in d4tensor()");
422 t[nrl][ncl][ndl] += NR_END;
423 t[nrl][ncl][ndl] -= nd4l;
425 for(k=ndl+1; k<=ndh; k++) t[nrl][ncl][k]=t[nrl][ncl][k-1]+nd4th;
426 for(j=ncl+1; j<=nch; j++)
428 t[nrl][j]=t[nrl][j-1]+ndep;
429 t[nrl][j][ndl]=t[nrl][j-1][ndl]+ndep*nd4th;
430 for(k=ndl+1; k<=ndh; k++)t[nrl][j][k]=t[nrl][j][k-1]+nd4th;
432 for(i=nrl+1; i<=nrh; i++)
435 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
436 for(j=ncl+1; j<=nch; j++)
438 t[i][j]=t[i][j-1]+ndep;
439 t[i][j][ndl]=t[i][j-1][ndl]+ndep*nd4th;
440 for(k=ndl+1; k<=ndh; k++)t[i][j][k]=t[i][j][k-1]+nd4th;
444 // return pointer to array of pointers to rows
523 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)