Garfield++ 3.0
A toolkit for the detailed simulation of particle detectors based on ionisation measurement in gases and semiconductors
Loading...
Searching...
No Matches
AbsArr.cpp
Go to the documentation of this file.
1/*
2Copyright (c) 1999-2004 I. B. Smirnov
3
4The file can be used, copied, modified, and distributed
5according to the terms of GNU Lesser General Public License version 2.1
6as published by the Free Software Foundation,
7and provided that the above copyright notice, this permission notice,
8and notices about any modifications of the original text
9appear in all copies and in supporting documentation.
10The file is provided "as is" without express or implied warranty.
11*/
12#include <iomanip>
14
15namespace Heed {
16
17long max_qel_DynLinArr = 100000000;
18
19void print_DynLinArr_int(std::ostream& file, const DynLinArr<int>& f) {
20 Ifile << "DynLinArr<int>:";
21 long q = f.get_qel();
22 file << " q=" << q << '\n';
23 f.check();
24 if (q <= 0) return;
25 indn.n += 2;
26 if (q <= pq_arrelem_in_line) file << indn;
27 for (long i = 0; i < q; i++) {
28 if (q <= pq_arrelem_in_line)
29 file << f[i] << ' '; // all in one line
30 else
31 Ifile << std::setw(4) << i << ' ' << f[i] << '\n'; // column
32 }
33 if (q <= pq_arrelem_in_line) file << '\n';
34 indn.n -= 2;
35 file << std::flush;
36}
37void print_DynLinArr_long(std::ostream& file, const DynLinArr<long>& f) {
38 Ifile << "DynLinArr<long>:";
39 long q = f.get_qel();
40 file << " q=" << q << '\n';
41 f.check();
42 if (q <= 0) return;
43 indn.n += 2;
44 if (q <= pq_arrelem_in_line) file << indn;
45 long i;
46 for (i = 0; i < q; i++) {
47 if (q <= pq_arrelem_in_line)
48 file << f[i] << ' '; // all in one line
49 else
50 Ifile << std::setw(4) << i << ' ' << f[i] << '\n'; // column
51 }
52 if (q <= pq_arrelem_in_line) file << '\n';
53 indn.n -= 2;
54 file << std::flush;
55}
56
57void print_DynLinArr_float(std::ostream& file, const DynLinArr<float>& f) {
58 Ifile << "DynLinArr<float>:";
59 long q = f.get_qel();
60 file << " q=" << q << '\n';
61 f.check();
62 if (q <= 0) return;
63 indn.n += 2;
64 if (q <= pq_arrelem_in_line) file << indn;
65 long i;
66 for (i = 0; i < q; i++) {
67 if (q <= pq_arrelem_in_line)
68 file << f[i] << ' '; // all in one line
69 else
70 Ifile << std::setw(4) << i << ' ' << f[i] << '\n'; // column
71 }
72 if (q <= pq_arrelem_in_line) file << '\n';
73 indn.n -= 2;
74 file << std::flush;
75}
76
77void print_DynLinArr_double(std::ostream& file, const DynLinArr<double>& f) {
78 Ifile << "DynLinArr<double>:";
79 long q = f.get_qel();
80 file << " q=" << q << '\n';
81 f.check();
82 if (q <= 0) return;
83 indn.n += 2;
84 if (q <= pq_arrelem_in_line) file << indn;
85 long i;
86 for (i = 0; i < q; i++) {
87 if (q <= pq_arrelem_in_line)
88 file << f[i] << ' '; // all in one line
89 else
90 Ifile << std::setw(4) << i << ' ' << f[i] << '\n'; // column
91 }
92 if (q <= pq_arrelem_in_line) file << '\n';
93 indn.n -= 2;
94 file << std::flush;
95}
96
97void print_DynLinArr_double2(std::ostream& file, const DynLinArr<double>& f1,
98 const DynLinArr<double>& f2) {
99 Ifile << "Two arrays DynLinArr<double>:";
100 long q1 = f1.get_qel();
101 long q2 = f2.get_qel();
102 long q_max = q1;
103 if (q_max > q2) q_max = q2;
104 file << " q1=" << q1 << " q2=" << q2 << '\n';
105 f1.check();
106 f2.check();
107 if (q_max <= 0) return;
108 indn.n += 2;
109 if (q_max <= pq_arrelem_in_line) file << indn;
110 if (q_max >= pq_arrelem_in_line) {
111 Ifile << "index array1 array2\n";
112 long i;
113 for (i = 0; i < q_max; i++) {
114 Ifile << std::setw(4) << i << ' ';
115 if (i < q1)
116 file << std::setw(18) << f1[i] << ' ';
117 else
118 file << " "; // 19 blanks
119 if (i < q2)
120 file << std::setw(18) << f2[i] << '\n';
121 else
122 file << " \n"; // 18 blanks
123 }
124 } else {
125 long i;
126 Ifile << "array1=";
127 for (i = 0; i < q1; i++) {
128 file << std::setw(18) << f1[i] << ' '; // all in one line
129 }
130 file << '\n';
131 Ifile << "array2=";
132 for (i = 0; i < q2; i++) {
133 file << std::setw(18) << f2[i] << ' '; // all in one line
134 }
135 file << '\n';
136 }
137 indn.n -= 2;
138 file << std::flush;
139}
140
141void print_DynLinArr_int_double(std::ostream& file, const DynLinArr<int>& iar,
142 const DynLinArr<double>& dar) {
143 Ifile << "One DynLinArr<int> array and one DynLinArr<double>:\n";
144 long qiar = iar.get_qel();
145 long qdar = dar.get_qel();
146 long q_max = qiar;
147 if (q_max < qdar) q_max = qdar;
148 indn.n += 2;
149
150 Ifile << " qiar=" << qiar << " qdar=" << qdar << '\n';
151 iar.check();
152 dar.check();
153 if (q_max <= 0) {
154 indn.n -= 2;
155 return;
156 }
157 Ifile << "index int array double array\n";
158 long i;
159 for (i = 0; i < q_max; i++) {
160 Ifile << std::setw(4) << i << ' ';
161 if (i < qiar)
162 file << std::setw(8) << iar[i] << ' ';
163 else
164 file << " "; // 19 blanks
165 if (i < qdar)
166 file << std::setw(18) << dar[i] << ' ';
167 else
168 file << " "; // 18 blanks
169 }
170 indn.n -= 2;
171 file << std::flush;
172}
173
174void print_DynLinArr_int_double3(std::ostream& file, const DynLinArr<int>& iar,
175 const DynLinArr<double>& dar1,
176 const DynLinArr<double>& dar2,
177 const DynLinArr<double>& dar3) {
178 Ifile << "One DynLinArr<int> array and three arrays DynLinArr<double>:\n";
179 long qiar = iar.get_qel();
180 long qdar1 = dar1.get_qel();
181 long qdar2 = dar2.get_qel();
182 long qdar3 = dar3.get_qel();
183 long q_max = qiar;
184 if (q_max < qdar1) q_max = qdar1;
185 if (q_max < qdar2) q_max = qdar2;
186 if (q_max < qdar3) q_max = qdar3;
187 indn.n += 2;
188
189 Ifile << "qiar=" << qiar << " qdar1=" << qdar1 << " qdar2=" << qdar2
190 << " qdar3=" << qdar3 << '\n';
191 iar.check();
192 dar1.check();
193 dar2.check();
194 dar3.check();
195 if (q_max <= 0) {
196 indn.n -= 2;
197 return;
198 }
199 Ifile << "index int array double array1 double array2 double "
200 "array3\n";
201 long i;
202 for (i = 0; i < q_max; i++) {
203 Ifile << std::setw(4) << i << ' ';
204 if (i < qiar)
205 file << std::setw(8) << iar[i] << ' ';
206 else
207 file << " "; // 19 blanks
208 if (i < qdar1)
209 file << std::setw(18) << dar1[i] << ' ';
210 else
211 file << " "; // 18 blanks
212 if (i < qdar2)
213 file << std::setw(18) << dar2[i] << ' ';
214 else
215 file << " "; // 18 blanks
216 if (i < qdar3)
217 file << std::setw(18) << dar3[i] << '\n';
218 else
219 file << " \n"; // 18 blanks
220 }
221 indn.n -= 2;
222 file << std::flush;
223}
224
225void print_DynArr_int_w(std::ostream& file, const DynArr<int>& f, int w) {
226 mfunname(
227 "void print_DynArr_int_w(ostream& file, const DynArr<int>& f, int w)");
228 f.check();
229 Ifile << "DynArr<int>:";
230 long qdim = f.get_qdim();
231 file << " qdim=" << qdim << " sizes:";
232 const DynLinArr<long>& qe = f.get_qel();
233 qe.check();
234 long n;
235 for (n = 0; n < qdim; n++) {
236 file << ' ' << qe[n];
237 }
238 file << '\n';
239 indn.n += 2;
240 if (qdim == 1) {
241 long q = qe[0];
242 if (q <= 0) return;
243 indn.n += 2;
244 if (indn.n + 3 + q * (w + 1) <= 80) { // printing in one line
245 Ifile << "ar=";
246 long i;
247 for (i = 0; i < q; i++) {
248 file << ' ' << std::setw(w) << f.ac(i);
249 }
250 file << '\n';
251 } else {
252 Ifile << "array:\n";
253 long i;
254 for (i = 0; i < q; i++) {
255 Ifile << std::setw(4) << i << ' ' << f.ac(i) << '\n'; // column
256 }
257 }
258 } else if (qdim == 2) {
259 long qr = qe[0];
260 long qc = qe[1];
261 if (qr <= 0 && qc <= 0) return;
262 indn.n += 2;
263 if (indn.n + 3 + qc * (w + 1) <= 80) { // lines in lines
264 Ifile << "first index - columns, second index - lines\n";
265 Ifile << "first index\n";
266 long ir, ic;
267 for (ir = 0; ir < qr; ir++) {
268 Ifile << std::setw(3) << ir;
269 for (ic = 0; ic < qc; ic++) {
270 Ifile << ' ' << std::setw(w) << f.ac(ir, ic);
271 }
272 file << '\n';
273 }
274 } else if (indn.n + 3 + qr * (w + 1) <= 80) {
275 Imcout << "first index - lines, second index - columns\n";
276 Imcout << "second index\n";
277 long ir, ic;
278 for (ic = 0; ic < qc; ic++) {
279 Ifile << std::setw(3) << ic;
280 for (ir = 0; ir < qr; ir++) {
281 Ifile << ' ' << std::setw(w) << f.ac(ir, ic);
282 }
283 file << '\n';
284 }
285 } else {
286 Ifile << " row col value of element\n";
287 long ir, ic;
288 for (ir = 0; ir < qr; ir++) {
289 for (ic = 0; ic < qc; ic++) {
290 Ifile << std::setw(4) << ir << ' ' << std::setw(4) << ic << ' ' << f.ac(ir, ic)
291 << '\n'; // column
292 }
293 }
294 }
295 } else {
296 IterDynArr<int> iter_f(&((DynArr<int>&)f));
297 int* at;
298 while ((at = iter_f.more()) != NULL) {
299 Ifile << "ncur=" << noindent << iter_f.get_ncur() << yesindent;
300 Ifile << "element=" << noindent << (*at) << yesindent << '\n';
301 }
302 file << yesindent;
303 }
304 // if(qc<=pq_elem_in_line) file<<'\n';
305 indn.n -= 2;
306 /*
307 }
308 else
309 {
310 file<<f;
311 }
312 */
313}
314
315void print_DynArr_double(std::ostream& file, const DynArr<double>& f) {
316 mfunname("void print_DynArr_double(ostream& file, const DynArr<double>& f)");
317 f.check();
318 Ifile << "DynArr<double>:";
319 long qdim = f.get_qdim();
320 file << " qdim=" << qdim << " sizes:";
321 const DynLinArr<long>& qe = f.get_qel();
322 qe.check();
323 long n;
324 for (n = 0; n < qdim; n++) {
325 file << ' ' << qe[n];
326 }
327 file << '\n';
328 if (qdim == 1) {
329 long q = qe[0];
330 if (q <= 0) return;
331 indn.n += 2;
332 if (q <= pq_arrelem_in_line) file << indn;
333 long i;
334 for (i = 0; i < q; i++) {
335 if (q <= pq_arrelem_in_line)
336 file << f.ac(i) << ' '; // all in one line
337 else
338 Ifile << std::setw(4) << i << ' ' << f.ac(i) << '\n'; // column
339 }
340 if (q <= pq_arrelem_in_line) file << '\n';
341 indn.n -= 2;
342 } else if (qdim == 2) {
343 long qr = qe[0];
344 long qc = qe[1];
345 if (qr <= 0 && qc <= 0) return;
346 indn.n += 2;
347 if (qc > pq_arrelem_in_line) Ifile << " row col value of element\n";
348 long ir, ic;
349 for (ir = 0; ir < qr; ir++) {
350 if (qc <= pq_arrelem_in_line) file << indn;
351 for (ic = 0; ic < qc; ic++) {
352 if (qc <= pq_arrelem_in_line)
353 file << f.ac(ir, ic) << ' '; // all in one line
354 else
355 Ifile << std::setw(4) << ir << ' ' << std::setw(4) << ic << ' ' << f.ac(ir, ic)
356 << '\n'; // column
357 }
358 if (qc <= pq_arrelem_in_line) file << '\n';
359 }
360 // if(qc<=pq_elem_in_line) file<<'\n';
361 indn.n -= 2;
362 } else {
363 file << f;
364 }
365}
366
367void print_DynArr_float(std::ostream& file, const DynArr<float>& f) {
368 mfunname("void print_DynArr_float(ostream& file, const DynArr<float>& f)");
369 f.check();
370 Ifile << "DynArr<float>:";
371 long qdim = f.get_qdim();
372 file << " qdim=" << qdim << " sizes:";
373 const DynLinArr<long>& qe = f.get_qel();
374 qe.check();
375 for (long n = 0; n < qdim; n++) {
376 file << ' ' << qe[n];
377 }
378 file << '\n';
379 if (qdim == 1) {
380 long q = qe[0];
381 if (q <= 0) return;
382 indn.n += 2;
383 if (q <= pq_arrelem_in_line) file << indn;
384 long i;
385 for (i = 0; i < q; i++) {
386 if (q <= pq_arrelem_in_line)
387 file << f.ac(i) << ' '; // all in one line
388 else
389 Ifile << std::setw(4) << i << ' ' << f.ac(i) << '\n'; // column
390 }
391 if (q <= pq_arrelem_in_line) file << '\n';
392 indn.n -= 2;
393 } else if (qdim == 2) {
394 long qr = qe[0];
395 long qc = qe[1];
396 if (qr <= 0 && qc <= 0) return;
397 indn.n += 2;
398 if (qc > pq_arrelem_in_line) Ifile << " row col value of element\n";
399 long ir, ic;
400 for (ir = 0; ir < qr; ir++) {
401 if (qc <= pq_arrelem_in_line) file << indn;
402 for (ic = 0; ic < qc; ic++) {
403 if (qc <= pq_arrelem_in_line)
404 file << f.ac(ir, ic) << ' '; // all in one line
405 else
406 Ifile << std::setw(4) << ir << ' ' << std::setw(4) << ic << ' ' << f.ac(ir, ic)
407 << '\n'; // column
408 }
409 if (qc <= pq_arrelem_in_line) file << '\n';
410 }
411 // if(qc<=pq_elem_in_line) file<<'\n';
412 indn.n -= 2;
413 } else {
414 file << f;
415 }
416}
417
418int gconfirm_ind(const DynLinArr<long>& qel, const DynLinArr<long>& ind) {
419 if (qel.get_qel() != ind.get_qel()) {
420 mcerr << "gconfirm_ind(...): "
421 << "qel.get_qel()!= ind.get_qel()\n"
422 << "qel.get_qel()=" << qel.get_qel()
423 << "ind.get_qel()=" << ind.get_qel() << '\n';
424 spexit(mcerr);
425 }
426 long qd = qel.get_qel();
427 // if( ind.get_qel() < qd) qd=ind.get_qel();
428 long n;
429 for (n = 0; n < qd; n++)
430 if (ind[n] < 0 || ind[n] >= qel[n]) return 0;
431 return 1;
432}
434 if (qel.get_qel() > ind.get_qel()) {
435 mcerr << "gconfirm_ind_ext(...): "
436 << "qel.get_qel()> ind.get_qel()\n"
437 << "qel.get_qel()=" << qel.get_qel()
438 << " ind.get_qel()=" << ind.get_qel() << '\n';
439 spexit(mcerr);
440 }
441 long qd = qel.get_qel();
442 long n;
443 for (n = 0; n < qd; n++)
444 if (ind[n] < 0 || ind[n] >= qel[n]) return 0;
445 for (n = qd; n < ind.get_qel(); n++)
446 if (ind[n] != 0) return 0;
447 return 1;
448}
449
451 long n;
452 long qdim = qel.get_qel();
453 if (qdim <= 0) return 0;
454 if (qdim != f.get_qel()) return 0; //@@
455#ifdef DEBUG_DYNARR
456 for (n = qdim - 1; n >= 0; n--) {
457 if (f[n] < qel[n] - 1) {
458 f[n]++;
459 return 1;
460 } else {
461 f[n] = 0;
462 } // the first element
463
464 } // it was last combination
465 for (n = 0; n < qdim - 1; n++) f[n] = qel[n] - 1; // the last element
466 f[qdim - 1] = qel[qdim - 1]; // next after last
467#else
468 for (n = qdim - 1; n >= 0; n--) {
469 if (f.acu(n) < qel.acu(n) - 1) {
470 f.acu(n)++;
471 return 1;
472 } else {
473 f.acu(n) = 0;
474 } // the first element
475
476 } // it was last combination
477 for (n = 0; n < qdim - 1; n++) f.acu(n) = qel.acu(n) - 1; // the last element
478 f.acu(qdim - 1) = qel.acu(qdim - 1); // next after last
479#endif
480 return 0;
481}
482
484 long n;
485 long qdim = qel.get_qel();
486 if (qdim <= 0) return 0;
487 if (qdim != f.get_qel()) return 0; //@@
488 for (n = qdim - 1; n >= 0; n--) {
489 if (f[n] < qel[n] - 1) {
490 f[n]++;
491 int n1;
492 for (n1 = n + 1; n1 < qdim; n1++) f[n1] = f[n];
493 return 1;
494 }
495 } // it was last combination
496 for (n = 0; n < qdim - 1; n++) f[n] = qel[n] - 1; // the last element
497 f[qdim - 1] = qel[qdim - 1]; // next after last
498 return 0;
499}
500
502 long n;
503 long qdim = qel.get_qel();
504 if (qdim <= 0) return 0;
505 if (qdim != f.get_qel()) return 0; //@@
506 for (n = qdim - 1; n >= 0; n--) {
507 if (f[n] >= 1) {
508 f[n]--;
509 return 1;
510 } else {
511 f[n] = qel[n] - 1;
512 } // the last element
513 }
514 for (n = 0; n < qdim - 1; n++) f[n] = 0; // the first element
515 f[qdim - 1] = -1;
516 return 0; // previous before first
517}
518
520}
#define spexit(stream)
Definition: FunNameStack.h:256
#define mfunname(string)
Definition: FunNameStack.h:45
void check(void) const
Definition: AbsArr.h:2209
T & ac(long i)
Definition: AbsArr.h:1717
const DynLinArr< long > & get_qel(void) const
Definition: AbsArr.h:2169
long get_qdim(void) const
Definition: AbsArr.h:2168
long get_qel(void) const
Definition: AbsArr.h:283
T & acu(long n)
Definition: AbsArr.h:247
void check(void) const
Definition: AbsArr.h:433
const DynLinArr< long > & get_ncur(void) const
Definition: AbsArr.h:2398
T * more(void)
Definition: AbsArr.h:2370
Definition: BGMesh.cpp:6
void print_DynArr_double(std::ostream &file, const DynArr< double > &f)
Definition: AbsArr.cpp:315
std::ostream & noindent(std::ostream &f)
Definition: prstream.cpp:17
long max_qel_DynLinArr
Definition: AbsArr.cpp:17
void print_DynArr_float(std::ostream &file, const DynArr< float > &f)
Definition: AbsArr.cpp:367
void print_DynLinArr_int_double3(std::ostream &file, const DynLinArr< int > &iar, const DynLinArr< double > &dar1, const DynLinArr< double > &dar2, const DynLinArr< double > &dar3)
Definition: AbsArr.cpp:174
const int pq_arrelem_in_line
Definition: AbsArr.h:1180
void print_DynLinArr_long(std::ostream &file, const DynLinArr< long > &f)
Definition: AbsArr.cpp:37
void print_DynLinArr_int_double(std::ostream &file, const DynLinArr< int > &iar, const DynLinArr< double > &dar)
Definition: AbsArr.cpp:141
int find_prev_comb(const DynLinArr< long > &qel, DynLinArr< long > &f)
Definition: AbsArr.cpp:501
void print_DynLinArr_double2(std::ostream &file, const DynLinArr< double > &f1, const DynLinArr< double > &f2)
Definition: AbsArr.cpp:97
int gconfirm_ind_ext(const DynLinArr< long > &qel, const DynLinArr< long > &ind)
Definition: AbsArr.cpp:433
void print_DynLinArr_float(std::ostream &file, const DynLinArr< float > &f)
Definition: AbsArr.cpp:57
int gconfirm_ind(const DynLinArr< long > &qel, const DynLinArr< long > &ind)
Definition: AbsArr.cpp:418
void print_DynLinArr_double(std::ostream &file, const DynLinArr< double > &f)
Definition: AbsArr.cpp:77
void print_DynArr_int_w(std::ostream &file, const DynArr< int > &f, int w)
Definition: AbsArr.cpp:225
int find_next_comb(const DynLinArr< long > &qel, DynLinArr< long > &f)
Definition: AbsArr.cpp:450
int find_next_comb_not_less(const DynLinArr< long > &qel, DynLinArr< long > &f)
Definition: AbsArr.cpp:483
indentation indn
Definition: prstream.cpp:15
void print_DynLinArr_int(std::ostream &file, const DynLinArr< int > &f)
Definition: AbsArr.cpp:19
std::ostream & yesindent(std::ostream &f)
Definition: prstream.cpp:21
DynLinArr< long > qel_communicat
Definition: AbsArr.cpp:519
#define Ifile
Definition: prstream.h:196
#define mcerr
Definition: prstream.h:128
#define Imcout
Definition: prstream.h:197