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