Garfield++ 5.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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

◆ NR_END

Function Documentation

◆ convert_matrix()

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

Definition at line 166 of file nrutil.c.

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

◆ cvector()

unsigned char * cvector ( long nl,
long nh )

Definition at line 43 of file nrutil.c.

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

◆ d3tensor()

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

Definition at line 223 of file nrutil.c.

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

◆ d4tensor()

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

Definition at line 261 of file nrutil.c.

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

Referenced by neBEMPrepareWeightingField(), and neBEMSolve().

◆ dmatrix()

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

Definition at line 98 of file nrutil.c.

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

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

◆ dvector()

double * dvector ( long nl,
long nh )

Definition at line 64 of file nrutil.c.

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

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

◆ f3tensor()

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

Definition at line 188 of file nrutil.c.

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

◆ fmatrix()

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

Definition at line 74 of file nrutil.c.

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

◆ free_convert_matrix()

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

Definition at line 500 of file nrutil.c.

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

◆ free_cvector()

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

Definition at line 461 of file nrutil.c.

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

◆ free_d3tensor()

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

Definition at line 514 of file nrutil.c.

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

◆ free_d4tensor()

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

Definition at line 523 of file nrutil.c.

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

◆ free_dmatrix()

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

Definition at line 482 of file nrutil.c.

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

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

◆ free_dvector()

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

Definition at line 471 of file nrutil.c.

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

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

◆ free_f3tensor()

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

Definition at line 506 of file nrutil.c.

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

◆ free_fmatrix()

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

Definition at line 476 of file nrutil.c.

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

◆ free_fvector()

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

Definition at line 451 of file nrutil.c.

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

◆ free_imatrix()

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

Definition at line 488 of file nrutil.c.

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

◆ free_ivector()

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

Definition at line 456 of file nrutil.c.

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

Referenced by InvertMatrix().

◆ free_lvector()

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

Definition at line 466 of file nrutil.c.

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

◆ free_submatrix()

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

Definition at line 494 of file nrutil.c.

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

◆ fvector()

float * fvector ( long nl,
long nh )

Definition at line 23 of file nrutil.c.

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

◆ imatrix()

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

Definition at line 122 of file nrutil.c.

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

Referenced by neBEMReadGeometry().

◆ ivector()

int * ivector ( long nl,
long nh )

Definition at line 33 of file nrutil.c.

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

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

◆ lvector()

unsigned long * lvector ( long nl,
long nh )

Definition at line 54 of file nrutil.c.

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

◆ nrerror()

void nrerror ( const char error_text[])

Definition at line 14 of file nrutil.c.

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

◆ submatrix()

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

Definition at line 146 of file nrutil.c.

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