Garfield++ 4.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
nrutil.c File Reference
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "NR.h"

Go to the source code of this file.

Macros

#define NR_END   1
 
#define FREE_ARG   char *
 

Functions

void nrerror (const char error_text[])
 
float * fvector (long nl, long nh)
 
int * ivector (long nl, long nh)
 
unsigned char * cvector (long nl, long nh)
 
unsigned long * lvector (long nl, long nh)
 
double * dvector (long nl, long nh)
 
float ** fmatrix (long nrl, long nrh, long ncl, long nch)
 
double ** dmatrix (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, long newrl, long newcl)
 
float ** convert_matrix (float *a, long nrl, long nrh, long ncl, long nch)
 
float *** f3tensor (long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
 
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)
 
void free_fvector (float *v, long nl, long)
 
void free_ivector (int *v, long nl, long)
 
void free_cvector (unsigned char *v, long nl, long)
 
void free_lvector (unsigned long *v, long nl, long)
 
void free_dvector (double *v, long nl, long)
 
void free_fmatrix (float **m, long nrl, long, long ncl, long)
 
void free_dmatrix (double **m, long nrl, long, long ncl, long)
 
void free_imatrix (int **m, long nrl, long, long ncl, long)
 
void free_submatrix (float **b, long nrl, long, long, 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)
 
void free_d3tensor (double ***t, long nrl, long, long ncl, long, long ndl, long)
 
void free_d4tensor (double ****t, long nrl, long, long ncl, long, long ndl, long, long nwl, long)
 

Macro Definition Documentation

◆ FREE_ARG

#define FREE_ARG   char *

Definition at line 7 of file nrutil.c.

◆ NR_END

#define NR_END   1

Definition at line 6 of file nrutil.c.

Function Documentation

◆ convert_matrix()

float ** convert_matrix ( float *  a,
long  nrl,
long  nrh,
long  ncl,
long  nch 
)

Definition at line 165 of file nrutil.c.

170{
171 long i, j, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
172 float **m;
173
174 /* allocate pointers to rows */
175 m = (float **)malloc((size_t)((nrow + NR_END) * sizeof(float *)));
176 if (!m) nrerror(" allocation failure in convert_matrix()");
177 m += NR_END;
178 m -= nrl;
179
180 /*set pointers to rows */
181 m[nrl] = a - ncl;
182 for (i = 1, j = nrl + 1; i < nrow; i++, j++) m[j] = m[j - 1] + ncol;
183 /* return pointer to array of pointers to rows */
184 return m;
185}
NRGLOBAL void nrerror()
#define NR_END
Definition: nrutil.c:6

◆ cvector()

unsigned char * cvector ( long  nl,
long  nh 
)

Definition at line 42 of file nrutil.c.

44{
45 unsigned char *v;
46
47 v = (unsigned char *)malloc(
48 (size_t)((nh - nl + 1 + NR_END) * sizeof(unsigned char)));
49 if (!v) nrerror("allocation failure in cvector()");
50 return v - nl + NR_END;
51}

◆ d3tensor()

double *** d3tensor ( long  nrl,
long  nrh,
long  ncl,
long  nch,
long  ndl,
long  ndh 
)

Definition at line 222 of file nrutil.c.

225{
226 long i, j, nrow = nrh - nrl + 1, ncol = nch - ncl + 1, ndep = ndh - ndl + 1;
227 double ***t;
228
229 /* allocate pointers to pointers to rows */
230 t = (double ***)malloc((size_t)((nrow + NR_END) * sizeof(double **)));
231 if (!t) nrerror("allocation failure 1 in d3tensor()");
232 t += NR_END;
233 t -= nrl;
234
235 /* allocate pointers to rows and set pointers to them */
236 t[nrl] =
237 (double **)malloc((size_t)((nrow * ncol + NR_END) * sizeof(double *)));
238 if (!t[nrl]) nrerror("allocation failure 2 in d3tensor()");
239 t[nrl] += NR_END;
240 t[nrl] -= ncl;
241
242 /* allocate rows and set pointers to them */
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()");
246 t[nrl][ncl] += NR_END;
247 t[nrl][ncl] -= ndl;
248
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;
254 }
255 /* return pointer to array of pointers to rows */
256 return t;
257}

◆ d4tensor()

double **** d4tensor ( long  nrl,
long  nrh,
long  ncl,
long  nch,
long  ndl,
long  ndh,
long  nwl,
long  nwh 
)

Definition at line 260 of file nrutil.c.

264{
265 long i, j, k, nrow = nrh - nrl + 1, ncol = nch - ncl + 1,
266 ndep = ndh - ndl + 1, nwid = nwh - nwl + 1;
267 double ****t;
268
269 // allocate pointers to pointers to pointers to rows
270 t = (double ****)malloc((size_t)((nrow + NR_END) * sizeof(double ***)));
271 if (!t) nrerror("allocation failure 1 in d4tensor()");
272 t += NR_END;
273 t -= nrl;
274
275 // allocate pointers to pointers to rows and set pointers to them
276 t[nrl] =
277 (double ***)malloc((size_t)((nrow * ncol + NR_END) * sizeof(double **)));
278 if (!t[nrl]) nrerror("allocation failure 2 in d4tensor()");
279 t[nrl] += NR_END;
280 t[nrl] -= ncl;
281
282 // allocate pointers to rows and set pointers to them
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()");
286 t[nrl][ncl] += NR_END;
287 t[nrl][ncl] -= ndl;
288
289 // allocate rows and set pointers to them
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;
295
296 for (i = nrl; i <= nrh; i++) {
297 if (i > nrl) {
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;
301 }
302 for (j = ncl; j <= nch; j++) {
303 if (j > ncl) {
304 t[i][j] = t[i][j - 1] + ndep;
305 t[i][j][ndl] = t[i][j - 1][ndl] + ndep * nwid;
306 }
307
308 for (k = ndl; k <= ndh; k++) {
309 if (k > ndl) t[i][j][k] = t[i][j][k - 1] + nwid;
310 }
311 }
312 }
313
314 // return pointer to pointer to array of pointers to rows
315 return t;
316}

Referenced by neBEMSolve().

◆ dmatrix()

double ** dmatrix ( long  nrl,
long  nrh,
long  ncl,
long  nch 
)

Definition at line 97 of file nrutil.c.

99{
100 long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
101 double **m;
102
103 /* allocate pointer to row */
104 m = (double **)malloc((size_t)((nrow + NR_END) * sizeof(double *)));
105 if (!m) nrerror("allocation faliore 1 in matrix()");
106 m += NR_END;
107 m -= nrl;
108
109 /* allocate row and set pointer to them */
110 m[nrl] = (double *)malloc((size_t)((nrow * ncol + NR_END) * sizeof(double)));
111 if (!m[nrl]) nrerror("allocation faliore 2 in matrix()");
112 m[nrl] += NR_END;
113 m[nrl] -= ncl;
114
115 for (i = nrl + 1; i <= nrh; i++) m[i] = m[i - 1] + ncol;
116
117 /* return pointer to array of pointer to rows */
118 return m;
119}

Referenced by InvertMatrix(), LHMatrix(), neBEMReadGeometry(), ReadInvertedMatrix(), ReadPrimitives(), Solve(), and ValueChUp().

◆ dvector()

double * dvector ( long  nl,
long  nh 
)

Definition at line 63 of file nrutil.c.

65{
66 double *v;
67
68 v = (double *)malloc((size_t)((nh - nl + 1 + NR_END) * sizeof(double)));
69 if (!v) nrerror("allocation failure in dvector()");
70 return v - nl + NR_END;
71}

Referenced by ElePFAtPoint(), InvertMatrix(), ludcmp(), MapFPR(), neBEMInitialize(), neBEMReadGeometry(), ReadPrimitives(), RHVector(), Solve(), svdcmp(), VoxelFPR(), and WtPFAtPoint().

◆ f3tensor()

float *** f3tensor ( long  nrl,
long  nrh,
long  ncl,
long  nch,
long  ndl,
long  ndh 
)

Definition at line 187 of file nrutil.c.

189{
190 long i, j, nrow = nrh - nrl + 1, ncol = nch - ncl + 1, ndep = ndh - ndl + 1;
191 float ***t;
192
193 /* allocate pointers to pointers to rows */
194 t = (float ***)malloc((size_t)((nrow + NR_END) * sizeof(float **)));
195 if (!t) nrerror("allocation failure 1 in f3tensor()");
196 t += NR_END;
197 t -= nrl;
198
199 /* allocate pointers to rows and set pointers to them */
200 t[nrl] = (float **)malloc((size_t)((nrow * ncol + NR_END) * sizeof(float *)));
201 if (!t[nrl]) nrerror("allocation failure 2 in f3tensor()");
202 t[nrl] += NR_END;
203 t[nrl] -= ncl;
204
205 /* allocate rows and set pointers to them */
206 t[nrl][ncl] =
207 (float *)malloc((size_t)((nrow * ncol * ndep + NR_END) * sizeof(float)));
208 if (!t[nrl][ncl]) nrerror("allocation failure 3 in f3tensor()");
209 t[nrl][ncl] += NR_END;
210 t[nrl][ncl] -= ndl;
211
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;
217 }
218 /* return pointer to array of pointers to rows */
219 return t;
220}

◆ fmatrix()

float ** fmatrix ( long  nrl,
long  nrh,
long  ncl,
long  nch 
)

Definition at line 73 of file nrutil.c.

75{
76 long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
77 float **m;
78
79 /* allocate pointers to rows */
80 m = (float **)malloc((size_t)((nrow + NR_END) * sizeof(float *)));
81 if (!m) nrerror("allocation failure 1 in matrix()");
82 m += NR_END;
83 m -= nrl;
84
85 /* allocate rows and set pointers to them */
86 m[nrl] = (float *)malloc((size_t)((nrow * ncol + NR_END) * sizeof(float)));
87 if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
88 m[nrl] += NR_END;
89 m[nrl] -= ncl;
90
91 for (i = nrl + 1; i <= nrh; i++) m[i] = m[i - 1] + ncol;
92
93 /* return pointer to array of pointer to rows */
94 return m;
95}

◆ free_convert_matrix()

void free_convert_matrix ( float **  b,
long  nrl,
long  ,
long  ,
long   
)

Definition at line 499 of file nrutil.c.

500 {
501 free((FREE_ARG)(b + nrl - NR_END));
502}
#define FREE_ARG
Definition: nrutil.c:7

◆ free_cvector()

void free_cvector ( unsigned char *  v,
long  nl,
long   
)

Definition at line 460 of file nrutil.c.

460 {
461 free((FREE_ARG)(v + nl - NR_END));
462}

◆ free_d3tensor()

void free_d3tensor ( double ***  t,
long  nrl,
long  ,
long  ncl,
long  ,
long  ndl,
long   
)

Definition at line 513 of file nrutil.c.

514 {
515 free((FREE_ARG)(t[nrl][ncl] + ndl - NR_END));
516 free((FREE_ARG)(t[nrl] + ncl - NR_END));
517 free((FREE_ARG)(t + nrl - NR_END));
518}

◆ free_d4tensor()

void free_d4tensor ( double ****  t,
long  nrl,
long  ,
long  ncl,
long  ,
long  ndl,
long  ,
long  nwl,
long   
)

Definition at line 522 of file nrutil.c.

523 {
524 free((FREE_ARG)(t[nrl][ncl][ndl] + nwl - NR_END));
525 free((FREE_ARG)(t[nrl][ncl] + ndl - NR_END));
526 free((FREE_ARG)(t[nrl] + ncl - NR_END));
527 free((FREE_ARG)(t + nrl - NR_END));
528}

◆ free_dmatrix()

void free_dmatrix ( double **  m,
long  nrl,
long  ,
long  ncl,
long   
)

Definition at line 481 of file nrutil.c.

481 {
482 free((FREE_ARG)(m[nrl] + ncl - NR_END));
483 free((FREE_ARG)(m + nrl - NR_END));
484}

Referenced by ComputeSolution(), InvertMatrix(), and Solve().

◆ free_dvector()

void free_dvector ( double *  v,
long  nl,
long   
)

Definition at line 470 of file nrutil.c.

470 {
471 free((FREE_ARG)(v + nl - NR_END));
472}

Referenced by InvertMatrix(), ludcmp(), MapFPR(), Solve(), svdcmp(), and VoxelFPR().

◆ free_f3tensor()

void free_f3tensor ( float ***  t,
long  nrl,
long  ,
long  ncl,
long  ,
long  ndl,
long   
)

Definition at line 505 of file nrutil.c.

506 {
507 free((FREE_ARG)(t[nrl][ncl] + ndl - NR_END));
508 free((FREE_ARG)(t[nrl] + ncl - NR_END));
509 free((FREE_ARG)(t + nrl - NR_END));
510}

◆ free_fmatrix()

void free_fmatrix ( float **  m,
long  nrl,
long  ,
long  ncl,
long   
)

Definition at line 475 of file nrutil.c.

475 {
476 free((FREE_ARG)(m[nrl] + ncl - NR_END));
477 free((FREE_ARG)(m + nrl - NR_END));
478}

◆ free_fvector()

void free_fvector ( float *  v,
long  nl,
long   
)

Definition at line 450 of file nrutil.c.

450 {
451 free((FREE_ARG)(v + nl - NR_END));
452}

◆ free_imatrix()

void free_imatrix ( int **  m,
long  nrl,
long  ,
long  ncl,
long   
)

Definition at line 487 of file nrutil.c.

487 {
488 free((FREE_ARG)(m[nrl] + ncl - NR_END));
489 free((FREE_ARG)(m + nrl - NR_END));
490}

◆ free_ivector()

void free_ivector ( int *  v,
long  nl,
long   
)

Definition at line 455 of file nrutil.c.

455 {
456 free((FREE_ARG)(v + nl - NR_END));
457}

Referenced by InvertMatrix().

◆ free_lvector()

void free_lvector ( unsigned long *  v,
long  nl,
long   
)

Definition at line 465 of file nrutil.c.

465 {
466 free((FREE_ARG)(v + nl - NR_END));
467}

◆ free_submatrix()

void free_submatrix ( float **  b,
long  nrl,
long  ,
long  ,
long   
)

Definition at line 493 of file nrutil.c.

494 {
495 free((FREE_ARG)(b + nrl - NR_END));
496}

◆ fvector()

float * fvector ( long  nl,
long  nh 
)

Definition at line 22 of file nrutil.c.

24{
25 float *v;
26
27 v = (float *)malloc((size_t)((nh - nl + 1 + NR_END) * sizeof(float)));
28 if (!v) nrerror("allocation failure in vector()");
29 return v - nl + NR_END;
30}

◆ imatrix()

int ** imatrix ( long  nrl,
long  nrh,
long  ncl,
long  nch 
)

Definition at line 121 of file nrutil.c.

123{
124 long i, nrow = nrh - nrl + 1, ncol = nch - ncl + 1;
125 int **m;
126
127 /* allocate pointer to row */
128 m = (int **)malloc((size_t)((nrow + NR_END) * sizeof(int *)));
129 if (!m) nrerror("allocation faliore 1 in matrix()");
130 m += NR_END;
131 m -= nrl;
132
133 /* allocate row and set pointer to them */
134 m[nrl] = (int *)malloc((size_t)((nrow * ncol + NR_END) * sizeof(int)));
135 if (!m[nrl]) nrerror("allocation falior 2 in matrix()");
136 m[nrl] += NR_END;
137 m[nrl] -= ncl;
138
139 for (i = nrl + 1; i <= nrh; i++) m[i] = m[i - 1] + ncol;
140
141 /* return pointer to array of pointer to rows */
142 return m;
143}

Referenced by neBEMReadGeometry().

◆ ivector()

int * ivector ( long  nl,
long  nh 
)

Definition at line 32 of file nrutil.c.

34{
35 int *v;
36
37 v = (int *)malloc((size_t)((nh - nl + 1 + NR_END) * sizeof(int)));
38 if (!v) nrerror("allocation failure in ivector()");
39 return v - nl + NR_END;
40}

Referenced by InvertMatrix(), neBEMInitialize(), neBEMReadGeometry(), and ReadPrimitives().

◆ lvector()

unsigned long * lvector ( long  nl,
long  nh 
)

Definition at line 53 of file nrutil.c.

55{
56 unsigned long *v;
57
58 v = (unsigned long *)malloc((size_t)((nh - nl + 1 + NR_END) * sizeof(long)));
59 if (!v) nrerror("allocation failure in lvector()");
60 return v - nl + NR_END;
61}

◆ nrerror()

void nrerror ( const char  error_text[])

Definition at line 13 of file nrutil.c.

15{
16 fprintf(stderr, " run_time error......\n");
17 fprintf(stderr, "%s\n", error_text);
18 fprintf(stderr, ".....now exiting to system.....\n");
19 exit(1);
20}

◆ submatrix()

float ** submatrix ( float **  a,
long  oldrl,
long  oldrh,
long  oldcl,
long  ,
long  newrl,
long  newcl 
)

Definition at line 145 of file nrutil.c.

148{
149 long i, j, nrow = oldrh - oldrl + 1, ncol = oldcl - newcl;
150 float **m;
151
152 /* allocate array of pointers to rows */
153 m = (float **)malloc((size_t)((nrow + NR_END) * sizeof(float *)));
154 if (!m) nrerror(" allocation failure in submatrix()");
155 m += NR_END;
156 m -= newrl;
157
158 /*set pointers to rows */
159 for (i = oldrl, j = newrl; i <= oldrh; i++, j++) m[j] = a[i] + ncol;
160
161 /* return pointer to array of pointers to rows */
162 return m;
163}