~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to .pc/support-gcc-5.x.patch/src/mod/mth/shl/Rsamples.cpp

  • Committer: Package Import Robot
  • Author(s): Nobuhiro Iwamatsu
  • Date: 2015-07-11 02:00:35 UTC
  • mfrom: (10.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20150711020035-2nhpztq7s15qyc0v
Tags: 2.5.1-1
* New upstream release. (Closes: #789968)
* Update debian/control.
  - Update Standards-Version to 3.9.6.
* Add support mips64(el) and ppc64el. (Closes: #741508, #748146)
* Add patches/support-gcc-5.x.patch. (Closes: #777767)
  - Fix build with gcc-5.x.
* Add patches/Disable-NET0001.als.patch.
  - Disable test of NET0001.als.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ---------------------------------------------------------------------------
 
2
// - Rsamples.cpp                                                            -
 
3
// - afnix:mth module - real array samples class implementation              -
 
4
// ---------------------------------------------------------------------------
 
5
// - This program is free software;  you can redistribute it  and/or  modify -
 
6
// - it provided that this copyright notice is kept intact.                  -
 
7
// -                                                                         -
 
8
// - This program  is  distributed in  the hope  that it will be useful, but -
 
9
// - without  any  warranty;  without  even   the   implied    warranty   of -
 
10
// - merchantability or fitness for a particular purpose.  In no event shall -
 
11
// - the copyright holder be liable for any  direct, indirect, incidental or -
 
12
// - special damages arising in any way out of the use of this software.     -
 
13
// ---------------------------------------------------------------------------
 
14
// - copyright (c) 1999-2015 amaury darsch                                   -
 
15
// ---------------------------------------------------------------------------
 
16
 
 
17
#include "Math.hpp"
 
18
#include "Mthsid.hxx"
 
19
#include "Vector.hpp"
 
20
#include "Rsamples.hpp"
 
21
#include "QuarkZone.hpp"
 
22
#include "Exception.hpp"
 
23
 
 
24
namespace afnix {
 
25
 
 
26
  // -------------------------------------------------------------------------
 
27
  // - private section                                                       -
 
28
  // -------------------------------------------------------------------------
 
29
 
 
30
  // the default columns size
 
31
  static const long RS_COLS_DEF = 1;
 
32
  // the default row size
 
33
  static const long RS_SIZE_DEF = 1024;
 
34
  // the default number precision
 
35
  static const long RS_PSIZ_DEF = 0;
 
36
  // the default scientific flag
 
37
  static const long RS_SFLG_DEF = false;
 
38
 
 
39
  // this procedure returns a new rsamples for deserialization
 
40
  static Serial* mksob (void) {
 
41
    return new Rsamples;
 
42
  }
 
43
  // register this array serial id
 
44
  static const t_byte SERIAL_ID = Serial::setsid (SERIAL_RSPL_ID, mksob);
 
45
 
 
46
  // -------------------------------------------------------------------------
 
47
  // - class section                                                         -
 
48
  // -------------------------------------------------------------------------
 
49
 
 
50
  // create a default array
 
51
 
 
52
  Rsamples::Rsamples (void) {
 
53
    d_cols = RS_COLS_DEF;
 
54
    d_size = 0;
 
55
    d_rows = 0;
 
56
    d_psiz = RS_PSIZ_DEF;
 
57
    d_sflg = RS_SFLG_DEF;
 
58
    p_time = nilp;
 
59
    p_data = nilp;
 
60
  }
 
61
 
 
62
  // create an array by columns
 
63
 
 
64
  Rsamples::Rsamples (const long cols) {
 
65
    if (cols <= 0) {
 
66
      throw Exception ("rsample-error", "invalid column size");
 
67
    }
 
68
    d_cols = cols;
 
69
    d_size = 0;
 
70
    d_rows = 0;
 
71
    d_psiz = RS_PSIZ_DEF;
 
72
    d_sflg = RS_SFLG_DEF;
 
73
    p_time = nilp;
 
74
    p_data = nilp;
 
75
  }
 
76
 
 
77
  // create an array by name, info and columns
 
78
 
 
79
  Rsamples::Rsamples (const String& name, const String& info, const long cols) {
 
80
    if (cols <= 0) {
 
81
      throw Exception ("rsample-error", "invalid column size");
 
82
    }
 
83
    d_name = name;
 
84
    d_info = info;
 
85
    d_cols = cols;
 
86
    d_size = 0;
 
87
    d_rows = 0;
 
88
    d_psiz = RS_PSIZ_DEF;
 
89
    d_sflg = RS_SFLG_DEF;
 
90
    p_time = nilp;
 
91
    p_data = nilp;
 
92
  }
 
93
 
 
94
  // copy construct this array
 
95
 
 
96
  Rsamples::Rsamples (const Rsamples& that) {
 
97
    that.rdlock ();
 
98
    try {
 
99
      // copy the size and allocate
 
100
      d_name = that.d_name;
 
101
      d_info = that.d_info;
 
102
      d_cols = that.d_cols;
 
103
      d_size = that.d_size;
 
104
      d_rows = that.d_rows;
 
105
      d_psiz = that.d_psiz;
 
106
      d_sflg = that.d_sflg;
 
107
      p_time = (that.p_time == nilp) ? nilp : new t_real[d_size];
 
108
      p_data = (d_size == 0) ? nilp : new t_real*[d_size];
 
109
      // copy the array
 
110
      for (long i = 0; i < d_size; i++) {
 
111
        // copy the time stamp
 
112
        if (p_time != nilp) p_time[i] = that.p_time[i];
 
113
        // copy the samples
 
114
        if (that.p_data[i] != nilp) {
 
115
          p_data[i] = new t_real[d_cols];
 
116
          for (t_long j = 0; j < d_cols; j++) p_data[i][j] = that.p_data[i][j];
 
117
        } else p_data[i] = nilp;
 
118
      }
 
119
      that.unlock ();
 
120
    } catch (...) {
 
121
      that.unlock ();
 
122
      throw;
 
123
    }
 
124
  }
 
125
  
 
126
  // destroy this array samples
 
127
 
 
128
  Rsamples::~Rsamples (void) {
 
129
    for (t_long i = 0; i < d_size; i++) delete [] p_data[i];
 
130
    delete [] p_time;
 
131
    delete [] p_data;
 
132
  }
 
133
 
 
134
  // return the class name
 
135
 
 
136
  String Rsamples::repr (void) const {
 
137
    return "Rsamples";
 
138
  }
 
139
 
 
140
  // return a clone of this object
 
141
 
 
142
  Object* Rsamples::clone (void) const {
 
143
    return new Rsamples (*this);
 
144
  }
 
145
 
 
146
  // return the array serial code
 
147
 
 
148
  t_byte Rsamples::serialid (void) const {
 
149
    return SERIAL_RSPL_ID;
 
150
  }
 
151
  
 
152
  // serialize this object
 
153
  
 
154
  void Rsamples::wrstream (OutputStream& os) const {
 
155
    rdlock ();
 
156
    try {
 
157
      // write the object name and info
 
158
      d_name.wrstream (os);
 
159
      d_info.wrstream (os);
 
160
      // write the object data
 
161
      Serial::wrlong (d_cols, os);
 
162
      Serial::wrlong (d_size, os);
 
163
      Serial::wrlong (d_rows, os);
 
164
      Serial::wrlong (d_psiz, os);
 
165
      Serial::wrbool (d_sflg, os);
 
166
      // eventually write the time stamps
 
167
      if (p_time != nilp) {
 
168
        Serial::wrbool (true, os);
 
169
        Serial::Block blok (RS_SIZE_DEF, Serial::Block::REAL);
 
170
        for (long row = 0; row < d_rows; row++) {
 
171
          blok.add (p_time[row]);
 
172
          if (blok.full () == false) continue;
 
173
          Serial::wrblok (blok, os);
 
174
          blok.clear ();
 
175
        }
 
176
        if (blok.empty () == false) Serial::wrblok (blok, os);
 
177
      } else {
 
178
        Serial::wrbool (false, os);
 
179
      }
 
180
      // write the data
 
181
      if (p_data != nilp) {
 
182
        Serial::wrbool (true, os);
 
183
        long dlen = d_rows * d_cols;
 
184
        Serial::Block blok (RS_SIZE_DEF, Serial::Block::REAL);
 
185
        for (long k = 0; k < dlen; k++) {
 
186
          long row = k / d_cols;
 
187
          long col = k % d_cols;
 
188
          blok.add (p_data[row][col]);
 
189
          if (blok.full () == false) continue;
 
190
          Serial::wrblok (blok, os);
 
191
          blok.clear ();
 
192
        }
 
193
        if (blok.empty () == false) Serial::wrblok (blok, os);
 
194
      } else {
 
195
        Serial::wrbool (false, os);
 
196
      }
 
197
      unlock ();
 
198
    } catch (...) {
 
199
      unlock ();
 
200
      throw;
 
201
    }
 
202
  }
 
203
 
 
204
  // deserialize this object
 
205
 
 
206
  void Rsamples::rdstream (InputStream& is) {
 
207
    wrlock ();
 
208
    try {
 
209
      // get the object info
 
210
      d_name.rdstream (is);
 
211
      d_info.rdstream (is);
 
212
      // get the object data
 
213
      d_cols = Serial::rdlong (is);
 
214
      d_size = Serial::rdlong (is);
 
215
      d_rows = Serial::rdlong (is);
 
216
      d_psiz = Serial::rdlong (is);
 
217
      d_sflg = Serial::rdbool (is);
 
218
      // check for time stamps
 
219
      if (Serial::rdbool (is) == true) {
 
220
        p_time = new t_real[d_size];
 
221
        for (long i = 0; i < d_rows; i++) {
 
222
          Block blok = Serial::rdblok (is);
 
223
          long  blen = blok.length ();
 
224
          for (long k = 0; k < blen; k++) p_time[i+k] = blok.getreal (k);
 
225
          i += (blen - 1);
 
226
        }
 
227
        for (long i = d_rows; i < d_size; i++) p_time[i] = Math::M_NAN;
 
228
      }
 
229
      // check for data
 
230
      if (Serial::rdbool (is) == true) {
 
231
        p_data = new t_real*[d_size];
 
232
        for (long i = 0; i < d_rows; i++) p_data[i] = new t_real[d_cols];
 
233
        long dlen = d_rows * d_cols;
 
234
        for (long i = 0; i < dlen; i++) {
 
235
          Block blok = Serial::rdblok (is);
 
236
          long  blen = blok.length ();
 
237
          for (long k = 0; k < blen; k++) {
 
238
            long row = (i + k) / d_cols;
 
239
            long col = (i + k) % d_cols;
 
240
            if (row >= d_rows) {
 
241
              i = dlen - blen;
 
242
              break;
 
243
            }
 
244
            p_data[row][col] = blok.getreal (k);
 
245
          }
 
246
          i += (blen - 1);
 
247
        }
 
248
        for (long i = d_rows; i < d_size; i++) p_data[i] = nilp;
 
249
      }      
 
250
      unlock ();
 
251
    } catch (...) {
 
252
      unlock ();
 
253
      throw;
 
254
    }
 
255
  }
 
256
 
 
257
  // assign an array samples to this one
 
258
 
 
259
  Rsamples& Rsamples::operator = (const Rsamples& that) {
 
260
    // check for self-assignation
 
261
    if (this == &that) return *this;
 
262
    // lock and assign
 
263
    wrlock ();
 
264
    that.rdlock ();
 
265
    try {
 
266
      // delete the old array
 
267
      for (long i = 0; i < d_size; i++) delete [] p_data[i];
 
268
      delete [] p_data; p_data = nilp;
 
269
      // copy the size and allocate
 
270
      d_name = that.d_name;
 
271
      d_info = that.d_info;
 
272
      d_cols = that.d_cols;
 
273
      d_size = that.d_size;
 
274
      d_rows = that.d_rows;
 
275
      d_psiz = that.d_psiz;
 
276
      d_sflg = that.d_sflg;
 
277
      p_time = (that.p_time == nilp) ? nilp : new t_real[d_size];
 
278
      p_data = (d_size == 0) ? nilp : new t_real*[d_size];
 
279
      // copy the array
 
280
      for (long i = 0; i < d_size; i++) {
 
281
        // copy the time stamp
 
282
        if (p_time != nilp) p_time[i] = that.p_time[i];
 
283
        // copy the samples
 
284
        if (that.p_data[i] != nilp) {
 
285
          p_data[i] = new t_real[d_cols];
 
286
          for (t_long j = 0; j < d_cols; j++) p_data[i][j] = that.p_data[i][j];
 
287
        } else p_data[i] = nilp;
 
288
      }
 
289
      // unlock and return
 
290
      unlock ();
 
291
      that.unlock ();
 
292
      return *this;
 
293
    } catch (...) {
 
294
      that.unlock ();
 
295
      throw;
 
296
    }
 
297
  }
 
298
 
 
299
  // get the samples name
 
300
 
 
301
  String Rsamples::getname (void) const {
 
302
    rdlock ();
 
303
    try {
 
304
      String result = d_name;
 
305
      unlock ();
 
306
      return result;
 
307
    } catch (...) {
 
308
      unlock ();
 
309
      throw;
 
310
    }
 
311
  }
 
312
 
 
313
  // set the samples name
 
314
 
 
315
  void Rsamples::setname (const String& name) {
 
316
    wrlock ();
 
317
    try {
 
318
      d_name = name;
 
319
      unlock ();
 
320
    } catch (...) {
 
321
      unlock ();
 
322
      throw;
 
323
    }
 
324
  }
 
325
 
 
326
  // set the samples info
 
327
 
 
328
  void Rsamples::setinfo (const String& info) {
 
329
    wrlock ();
 
330
    try {
 
331
      d_info = info;
 
332
      unlock ();
 
333
    } catch (...) {
 
334
      unlock ();
 
335
      throw;
 
336
    }
 
337
  }
 
338
 
 
339
  // get the samples info
 
340
 
 
341
  String Rsamples::getinfo (void) const {
 
342
    rdlock ();
 
343
    try {
 
344
      String result = d_info;
 
345
      unlock ();
 
346
      return result;
 
347
    } catch (...) {
 
348
      unlock ();
 
349
      throw;
 
350
    }
 
351
  }
 
352
 
 
353
  // clear this array samples
 
354
 
 
355
  void Rsamples::clear (void) {
 
356
    wrlock ();
 
357
    try {
 
358
      for (t_long i = 0; i < d_size; i++) delete [] p_data[i];
 
359
      delete [] p_time; p_time = nilp;
 
360
      delete [] p_data; p_data = nilp;
 
361
      d_rows = 0;
 
362
      d_size = 0;
 
363
      unlock ();
 
364
    } catch (...) {
 
365
      unlock ();
 
366
      throw;
 
367
    }
 
368
  }
 
369
 
 
370
  // get the number of rows
 
371
  
 
372
  long Rsamples::getrows (void) const {
 
373
    rdlock ();
 
374
    try {
 
375
      long result = d_rows;
 
376
      unlock ();
 
377
      return result;
 
378
    } catch (...) {
 
379
      unlock ();
 
380
      throw;
 
381
    }
 
382
  }
 
383
 
 
384
  // set the number of colimns
 
385
 
 
386
  void Rsamples::setcols (const long cols) {
 
387
    wrlock ();
 
388
    try {
 
389
      // check for valid columns
 
390
      if (cols <= 0) {
 
391
        throw Exception ("rsample-error", "invalid column size");
 
392
      }
 
393
      // clear the samples
 
394
      clear ();
 
395
      // set a new columns
 
396
      d_cols = cols;
 
397
      unlock ();
 
398
    } catch (...) {
 
399
      unlock ();
 
400
      throw;
 
401
    }
 
402
  }
 
403
 
 
404
  // get the number of columns
 
405
  
 
406
  long Rsamples::getcols (void) const {
 
407
    rdlock ();
 
408
    try {
 
409
      long result = d_cols;
 
410
      unlock ();
 
411
      return result;
 
412
    } catch (...) {
 
413
      unlock ();
 
414
      throw;
 
415
    }
 
416
  }
 
417
 
 
418
  // set the number precision
 
419
 
 
420
  void Rsamples::setpsiz (const long psiz) {
 
421
    wrlock ();
 
422
    try {
 
423
      if (psiz < 0) {
 
424
        throw Exception ("rsamples-error", "invalid negative number precision");
 
425
      }
 
426
      d_psiz = psiz;
 
427
      unlock ();
 
428
    } catch (...) {
 
429
      unlock ();
 
430
      throw;
 
431
    }
 
432
  }
 
433
 
 
434
  // get the number precision
 
435
 
 
436
  long Rsamples::getpsiz (void) const {
 
437
    rdlock ();
 
438
    try {
 
439
      long result = d_psiz;
 
440
      unlock ();
 
441
      return result;
 
442
    } catch (...) {
 
443
      unlock ();
 
444
      throw;
 
445
    }
 
446
  }
 
447
 
 
448
  // set the scientific flag
 
449
 
 
450
  void Rsamples::setsflg (const bool sflg) {
 
451
    wrlock ();
 
452
    try {
 
453
      d_sflg = sflg;
 
454
      unlock ();
 
455
    } catch (...) {
 
456
      unlock ();
 
457
      throw;
 
458
    }
 
459
  } 
 
460
 
 
461
  // get the scientific flag
 
462
 
 
463
  bool Rsamples::getsflg (void) const {
 
464
    rdlock ();
 
465
    try {
 
466
      bool result = d_sflg;
 
467
      unlock ();
 
468
      return result;
 
469
    } catch (...) {
 
470
      unlock ();
 
471
      throw;
 
472
    }
 
473
  }
 
474
 
 
475
  // return true if the samples are stamped
 
476
 
 
477
  bool Rsamples::stamped (void) const {
 
478
    rdlock ();
 
479
    try {
 
480
      bool result = (p_time != nilp);
 
481
      unlock ();
 
482
      return result;
 
483
    } catch (...) {
 
484
      unlock ();
 
485
      throw;
 
486
    }
 
487
  }
 
488
 
 
489
  // get a time value by position
 
490
 
 
491
  t_real Rsamples::gettime (const long row) const {
 
492
    rdlock ();
 
493
    try {
 
494
      // check for valid position
 
495
      if ((row < 0) || (row >= d_rows)) {
 
496
        throw Exception ("sample-error", "invalid row position");
 
497
      }
 
498
      t_real result = (p_time == nilp) ? Math::M_NAN : p_time[row];
 
499
      unlock ();
 
500
      return result;
 
501
    } catch (...) {
 
502
      unlock ();
 
503
      throw;
 
504
    }
 
505
  }
 
506
 
 
507
  // set a sample by position and value
 
508
 
 
509
  void Rsamples::set (const long row, const long col, const t_real val) {
 
510
    wrlock ();
 
511
    try {
 
512
      // check for valid position
 
513
      if ((row < 0) || (row >= d_rows)) {
 
514
        throw Exception ("sample-error", "invalid row position");
 
515
      }
 
516
      if ((col < 0) || (col >= d_cols)) {
 
517
        throw Exception ("sample-error", "invalid column position");
 
518
      }
 
519
      // set sample value
 
520
      p_data[row][col] = val;
 
521
      unlock ();
 
522
    } catch (...) {
 
523
      unlock ();
 
524
      throw;
 
525
    }
 
526
  }
 
527
 
 
528
  // get a sample by position
 
529
 
 
530
  t_real Rsamples::get (const long row, const long col) const {
 
531
    rdlock ();
 
532
    try {
 
533
      // check for valid position
 
534
      if ((row < 0) || (row >= d_rows)) {
 
535
        throw Exception ("sample-error", "invalid row position");
 
536
      }
 
537
      if ((col < 0) || (col >= d_cols)) {
 
538
        throw Exception ("sample-error", "invalid column position");
 
539
      }
 
540
      // get sample value
 
541
      t_real result = p_data[row][col];
 
542
      unlock ();
 
543
      return result;
 
544
    } catch (...) {
 
545
      unlock ();
 
546
      throw;
 
547
    }
 
548
  }
 
549
 
 
550
  // add a new unitialized row
 
551
 
 
552
  long Rsamples::newrow (void) {
 
553
    wrlock ();
 
554
    try {
 
555
      // eventually resize the array
 
556
      if ((d_rows + 1) > d_size) resize ((d_size == 0) ? 1 : (d_size * 2));
 
557
      // save result and allocate
 
558
      long result = d_rows;
 
559
      p_data[d_rows++] = new t_real[d_cols];
 
560
      // initialized as nan
 
561
      for (long i = 0; i < d_cols; i++) p_data[result][i] = Math::M_NAN;
 
562
      // here it is
 
563
      unlock ();
 
564
      return result;
 
565
    } catch (...) {
 
566
      unlock ();
 
567
      throw;
 
568
    }
 
569
  }
 
570
 
 
571
  // add a new uninitialized row with a time stamp
 
572
 
 
573
  long Rsamples::newrow (const t_real tval) {
 
574
    wrlock ();
 
575
    try {
 
576
      // allocate the new row
 
577
      long result = newrow ();
 
578
      // check for non-allocated time
 
579
      if ((p_time == nilp) && (tval == Math::M_NAN)) {
 
580
        unlock ();
 
581
        return result;
 
582
      }
 
583
      // eventually allocate the time stamps
 
584
      if (p_time == nilp) {
 
585
        p_time = new t_real[d_size];
 
586
        for (long i = 0; i < d_size; i++) p_time[i] = Math::M_NAN;
 
587
      }
 
588
      // set the time stamp
 
589
      p_time[result] = tval;
 
590
      // unlock and return
 
591
      unlock ();
 
592
      return result;
 
593
    } catch (...) {
 
594
      unlock ();
 
595
      throw;
 
596
    }
 
597
  }
 
598
 
 
599
  // resize this array samples
 
600
 
 
601
  void Rsamples::resize (const long size) {
 
602
    wrlock ();
 
603
    try {
 
604
      // check for resizing
 
605
      if (size <= d_size) {
 
606
        unlock ();
 
607
        return;
 
608
      }
 
609
      // allocate a new time stamp
 
610
      t_real* tptr = (p_time == nilp) ? nilp : new t_real[size];
 
611
      // allocate new array
 
612
      t_real** data = new t_real*[size];
 
613
      // copy the data
 
614
      for (long i = 0; i < d_rows; i++) {
 
615
        if (tptr != nilp) tptr[i] = p_time[i];
 
616
        data[i] = p_data[i];
 
617
      }
 
618
      for (long i = d_rows; i < size; i++) {
 
619
        if (tptr != nilp) tptr[i] = Math::M_NAN;
 
620
        data[i] = nilp;
 
621
      }
 
622
      // clean old and adjust
 
623
      delete [] p_time;
 
624
      delete [] p_data;
 
625
      p_time = tptr;
 
626
      p_data = data;
 
627
      d_size = size;
 
628
      // that's all
 
629
      unlock ();
 
630
    } catch (...) {
 
631
      unlock ();
 
632
      throw;
 
633
    }
 
634
  }
 
635
 
 
636
  // get the minimum signed time
 
637
 
 
638
  t_real Rsamples::minst (void) const {
 
639
    rdlock ();
 
640
    try {
 
641
      t_real result = Math::M_NAN;
 
642
      if (p_time != nilp) {
 
643
        for (long i = 0; i < d_rows; i++) {
 
644
          t_real tval = p_time[i];
 
645
          if (Math::isnan (tval) == true) continue;
 
646
          if ((Math::isnan (result) == true) || (tval < result)) result = tval;
 
647
        }
 
648
      }
 
649
      unlock ();
 
650
      return result;
 
651
    } catch (...) {
 
652
      unlock ();
 
653
      throw;
 
654
    }
 
655
  }
 
656
 
 
657
  // get the maximum signed time
 
658
 
 
659
  t_real Rsamples::maxst (void) const {
 
660
    rdlock ();
 
661
    try {
 
662
      t_real result = Math::M_NAN;
 
663
      if (p_time != nilp) {
 
664
        for (long i = 0; i < d_rows; i++) {
 
665
          t_real tval = p_time[i];
 
666
          if (Math::isnan (tval) == true) continue;
 
667
          if ((Math::isnan (result) == true) || (tval > result)) result = tval;
 
668
        }
 
669
      }
 
670
      unlock ();
 
671
      return result;
 
672
    } catch (...) {
 
673
      unlock ();
 
674
      throw;
 
675
    }
 
676
  }
 
677
 
 
678
  // get the minimum column value
 
679
 
 
680
  t_real Rsamples::minsc (const long col) const {
 
681
    rdlock ();
 
682
    try {
 
683
      // check for valid column
 
684
      if ((col < 0) || (col >= d_cols)) {
 
685
        throw Exception ("sample-error", "invalid column position");
 
686
      }
 
687
      t_real result = Math::M_NAN;
 
688
      if (p_data!= nilp) {
 
689
        for (long i = 0; i < d_rows; i++) {
 
690
          t_real cval = p_data[i][col];
 
691
          if (Math::isnan  (cval)   == true) continue;
 
692
          if ((Math::isnan (result) == true) || (cval < result)) result = cval;
 
693
        }
 
694
      }
 
695
      unlock ();
 
696
      return result;
 
697
    } catch (...) {
 
698
      unlock ();
 
699
      throw;
 
700
    }
 
701
  }
 
702
 
 
703
  // get the maximum column value
 
704
 
 
705
  t_real Rsamples::maxsc (const long col) const {
 
706
    rdlock ();
 
707
    try {
 
708
      // check for valid column
 
709
      if ((col < 0) || (col >= d_cols)) {
 
710
        throw Exception ("sample-error", "invalid column position");
 
711
      }
 
712
      t_real result = Math::M_NAN;
 
713
      if (p_data != nilp) {
 
714
        for (long i = 0; i < d_rows; i++) {
 
715
          t_real cval = p_data[i][col];
 
716
          if (Math::isnan (cval)    == true) continue;
 
717
          if ((Math::isnan (result) == true) || (cval > result)) result = cval;
 
718
        }
 
719
      }
 
720
      unlock ();
 
721
      return result;
 
722
    } catch (...) {
 
723
      unlock ();
 
724
      throw;
 
725
    }
 
726
  }
 
727
 
 
728
  // smooth the sample array upto a relative error
 
729
 
 
730
  Rsamples* Rsamples::smooth (void) const {
 
731
    rdlock ();
 
732
    try {
 
733
      Rsamples* result = smooth (Math::d_reps);
 
734
      unlock ();
 
735
      return result;
 
736
    } catch (...) {
 
737
      unlock ();
 
738
      throw;
 
739
    }
 
740
  }
 
741
 
 
742
  // smooth the sample array upto a relative error
 
743
 
 
744
  Rsamples* Rsamples::smooth (const t_real reps) const {
 
745
    rdlock ();
 
746
    Rsamples* result = nilp;
 
747
    try {
 
748
      // check for valid rows
 
749
      if (d_rows == 0) {
 
750
        unlock ();
 
751
        return result;
 
752
      }
 
753
      // create a result sample array
 
754
      result = new Rsamples (d_cols);
 
755
      result->d_psiz = d_psiz;
 
756
      result->d_sflg = d_sflg;
 
757
      // prepare the working columns
 
758
      t_real time = Math::M_NAN;
 
759
      t_real data[d_cols];
 
760
      if (p_time != nilp) time = p_time[0];
 
761
      if (p_data != nilp) {
 
762
        for (long col = 0; col < d_cols; col++) data[col] = p_data[0][col];
 
763
      }
 
764
      // loop in the rows
 
765
      long rows = d_rows - 1;
 
766
      for (long row = 1; row < rows; row++) {
 
767
        // prepare operating row
 
768
        t_real tval = Math::M_NAN;
 
769
        t_real dval[d_cols];
 
770
        if (p_time != nilp) tval = p_time[row];
 
771
        if (p_data != nilp) {
 
772
          for (long col = 0; col < d_cols; col++) dval[col] = p_data[row][col];
 
773
        }
 
774
        // check for relative error
 
775
        bool status = 
 
776
          ((Math::isnan (time) == true) && (Math::isnan (tval) == true)) ||
 
777
          ((Math::isnan (time) != true) && (Math::isnan (tval) != true));
 
778
        for (long col = 0; col < d_cols; col++) {
 
779
          if (Math::rcmp (data[col], dval[col], reps) == false) {
 
780
            status = false;
 
781
            break;
 
782
          }
 
783
        }
 
784
        // check for data push
 
785
        if (status == false) {
 
786
          long nr = result->newrow (time);
 
787
          time = tval;
 
788
          for (long col = 0; col < d_cols; col++) {
 
789
            result->p_data[nr][col] = data[col];
 
790
            data[col] = dval[col];
 
791
          }
 
792
        } 
 
793
      }
 
794
      // push last record
 
795
      if (rows > 0) {
 
796
        time = (p_time == nilp) ? Math::M_NAN : p_time[rows];
 
797
          long nr = result->newrow (time);
 
798
        for (long col = 0; col < d_cols; col++) {
 
799
          result->p_data[nr][col] = p_data[rows][col];
 
800
        }
 
801
      }
 
802
      unlock ();
 
803
      return result;
 
804
    } catch (...) {
 
805
      delete result;
 
806
      unlock ();
 
807
      throw;
 
808
    }
 
809
  }
 
810
 
 
811
  // create a print table with the samples
 
812
  
 
813
  PrintTable* Rsamples::toptbl (const bool tflg) const {
 
814
    rdlock ();
 
815
    PrintTable* result = nilp;
 
816
    try {
 
817
      // compute the effective columns
 
818
      long ecol = (tflg == true) ? d_cols + 1 : d_cols;
 
819
      // create the print table
 
820
      result = (d_rows == 0) ? new PrintTable (ecol) :
 
821
        new PrintTable (ecol, d_rows);
 
822
      // set the style
 
823
      Style gstl = result->getstyle ();
 
824
      gstl.setpsiz (d_psiz);
 
825
      gstl.setsflg (d_sflg);
 
826
      result->setstyle (gstl);
 
827
      // loop in the data samples
 
828
      for (long row = 0; row < d_rows; row++) {
 
829
        // create a new row in the table
 
830
        if (result->add () != row) {
 
831
          throw Exception ("internal-error", 
 
832
                           "inconsistent rsample row index in print-table");
 
833
        }
 
834
        // set the time if requested
 
835
        if (tflg == true) {
 
836
          t_real tval = (p_time == nilp) ? Math::M_NAN : p_time[row];
 
837
          result->set (row, 0, tval);
 
838
          // set the samples
 
839
          for (long col = 0; col < d_cols; col++) {
 
840
            result->set (row, col+1, p_data[row][col]);
 
841
          }
 
842
        } else {
 
843
          // set the samples
 
844
          for (long col = 0; col < d_cols; col++) {
 
845
            result->set (row, col, p_data[row][col]);
 
846
          }
 
847
        }
 
848
      }
 
849
      // unlock and return
 
850
      unlock ();
 
851
      return result;
 
852
    } catch (...) {
 
853
      delete result;
 
854
      unlock ();
 
855
      throw;
 
856
    }
 
857
  }
 
858
 
 
859
  // -------------------------------------------------------------------------
 
860
  // - object section                                                        -
 
861
  // -------------------------------------------------------------------------
 
862
 
 
863
  // the quark zone
 
864
  static const long QUARK_ZONE_LENGTH = 23;
 
865
  static QuarkZone  zone (QUARK_ZONE_LENGTH);
 
866
 
 
867
  // the object supported quarks
 
868
  static const long QUARK_SET     = zone.intern ("set");
 
869
  static const long QUARK_GET     = zone.intern ("get");
 
870
  static const long QUARK_CLEAR   = zone.intern ("clear");
 
871
  static const long QUARK_MINST   = zone.intern ("min-signed-time");
 
872
  static const long QUARK_MAXST   = zone.intern ("max-signed-time");
 
873
  static const long QUARK_MINSC   = zone.intern ("min-signed-column");
 
874
  static const long QUARK_MAXSC   = zone.intern ("max-signed-column");
 
875
  static const long QUARK_SMOOTH  = zone.intern ("smooth");
 
876
  static const long QUARK_NEWROW  = zone.intern ("new-row");
 
877
  static const long QUARK_RESIZE  = zone.intern ("resize");
 
878
  static const long QUARK_TOPTBL  = zone.intern ("to-print-table");
 
879
  static const long QUARK_SETNAME = zone.intern ("set-name");
 
880
  static const long QUARK_SETINFO = zone.intern ("set-info");
 
881
  static const long QUARK_GETINFO = zone.intern ("get-info");
 
882
  static const long QUARK_STAMPED = zone.intern ("stamped-p");
 
883
  static const long QUARK_GETTIME = zone.intern ("get-time");
 
884
  static const long QUARK_GETROWS = zone.intern ("get-rows");
 
885
  static const long QUARK_SETCOLS = zone.intern ("set-columns");
 
886
  static const long QUARK_GETCOLS = zone.intern ("get-columns");
 
887
  static const long QUARK_SETPSIZ = zone.intern ("set-number-precision");
 
888
  static const long QUARK_GETPSIZ = zone.intern ("get-number-precision");
 
889
  static const long QUARK_SETSFLG = zone.intern ("set-scientific-notation");
 
890
  static const long QUARK_GETSFLG = zone.intern ("get-scientific-notation");
 
891
 
 
892
  // create a new object in a generic way
 
893
 
 
894
  Object* Rsamples::mknew (Vector* argv) {
 
895
    long argc = (argv == nilp) ? 0 : argv->length ();
 
896
    
 
897
    // check for 0 argument
 
898
    if (argc == 0) return new Rsamples;
 
899
    // check for 1 argument
 
900
    if (argc == 1) {
 
901
      long cols = argv->getlong (0);
 
902
      return new Rsamples (cols);
 
903
    }
 
904
    // invalid arguments
 
905
    throw Exception ("argument-error", 
 
906
                     "invalid arguments with real samples object");
 
907
  }
 
908
 
 
909
  // return true if the given quark is defined
 
910
 
 
911
  bool Rsamples::isquark (const long quark, const bool hflg) const {
 
912
    rdlock ();
 
913
    try {
 
914
      if (zone.exists (quark) == true){
 
915
        unlock ();
 
916
        return true;
 
917
      }
 
918
      bool result = hflg ? Serial::isquark (quark, hflg) : false;
 
919
      if (result == false) {
 
920
        result = hflg ? Nameable::isquark (quark, hflg) : false;
 
921
      }
 
922
      unlock ();
 
923
      return result;
 
924
    } catch (...) {
 
925
      unlock ();
 
926
      throw;
 
927
    }
 
928
  }
 
929
 
 
930
  // apply this object with a set of arguments and a quark
 
931
  
 
932
  Object* Rsamples::apply (Runnable* robj, Nameset* nset, const long quark,
 
933
                           Vector* argv) {
 
934
    // get the number of arguments
 
935
    long argc = (argv == nilp) ? 0 : argv->length ();
 
936
 
 
937
    // dispatch 0 argument
 
938
    if (argc == 0) {
 
939
      if (quark == QUARK_MINST)   return new Real    (minst ());
 
940
      if (quark == QUARK_MAXST)   return new Real    (maxst ());
 
941
      if (quark == QUARK_SMOOTH)  return smooth ();
 
942
      if (quark == QUARK_GETINFO) return new String  (getinfo ());
 
943
      if (quark == QUARK_GETROWS) return new Integer (getrows ());
 
944
      if (quark == QUARK_GETCOLS) return new Integer (getcols ());
 
945
      if (quark == QUARK_NEWROW)  return new Integer (newrow  ());
 
946
      if (quark == QUARK_GETPSIZ) return new Integer (getpsiz ());
 
947
      if (quark == QUARK_GETSFLG) return new Boolean (getsflg ());
 
948
      if (quark == QUARK_STAMPED) return new Boolean (stamped ());
 
949
      if (quark == QUARK_TOPTBL)  return toptbl (stamped ());
 
950
      if (quark == QUARK_CLEAR) {
 
951
        clear ();
 
952
        return nilp;
 
953
      }
 
954
    }
 
955
    // dispatch 1 argument
 
956
    if (argc == 1) {
 
957
      if (quark == QUARK_SETNAME) {
 
958
        String name = argv->getstring (0);
 
959
        setname (name);
 
960
        return nilp;
 
961
      }
 
962
      if (quark == QUARK_SETINFO) {
 
963
        String info = argv->getstring (0);
 
964
        setinfo (info);
 
965
        return nilp;
 
966
      }
 
967
      if (quark == QUARK_SETCOLS) {
 
968
        long cols = argv->getlong (0);
 
969
        setcols (cols);
 
970
        return nilp;
 
971
      }
 
972
      if (quark == QUARK_NEWROW) {
 
973
        t_real tval = argv->getrint (0);
 
974
        return new Integer (newrow (tval));
 
975
      }
 
976
      if (quark == QUARK_RESIZE) {
 
977
        long size = argv->getlong (0);
 
978
        resize (size);
 
979
        return nilp;
 
980
      }
 
981
      if (quark == QUARK_GETTIME) {
 
982
        long row = argv->getlong (0);
 
983
        return new Real (gettime (row));
 
984
      }
 
985
      if (quark == QUARK_TOPTBL) {
 
986
        bool tflg = argv->getbool (0);
 
987
        return toptbl (tflg);
 
988
      }
 
989
      if (quark == QUARK_MINSC) {
 
990
        long col = argv->getlong (0);
 
991
        return new Real (minsc (col));
 
992
      }
 
993
      if (quark == QUARK_MAXSC) {
 
994
        long col = argv->getlong (0);
 
995
        return new Real (maxsc (col));
 
996
      }
 
997
      if (quark == QUARK_SMOOTH) {
 
998
        t_real reps = argv->getreal (0);
 
999
        return smooth (reps);
 
1000
      }
 
1001
      if (quark == QUARK_SETPSIZ) {
 
1002
        long psiz = argv->getlong (0);
 
1003
        setpsiz (psiz);
 
1004
        return nilp;
 
1005
      }
 
1006
      if (quark == QUARK_SETSFLG) {
 
1007
        bool sflg = argv->getbool (0);
 
1008
        setsflg (sflg);
 
1009
        return nilp;
 
1010
      }
 
1011
    }
 
1012
    // dispatch 2 arguments
 
1013
    if (argc == 2) {
 
1014
      if (quark == QUARK_GET) {
 
1015
        long row = argv->getlong (0);
 
1016
        long col = argv->getlong (1);
 
1017
        return new Real (get (row, col));
 
1018
      }
 
1019
    }
 
1020
    // dispatch 3 arguments
 
1021
    if (argc == 3) {
 
1022
      if (quark == QUARK_SET) {
 
1023
        long   row = argv->getlong (0);
 
1024
        long   col = argv->getlong (1);
 
1025
        t_real val = argv->getrint (2);
 
1026
        set (row, col, val);
 
1027
        return nilp;
 
1028
      }
 
1029
    }
 
1030
    // check the nameable class
 
1031
    if (Nameable::isquark (quark, true) == true) {
 
1032
      return Nameable::apply (robj, nset, quark, argv);
 
1033
    }
 
1034
    // call the serial object
 
1035
    return Serial::apply (robj, nset, quark, argv);
 
1036
  }
 
1037
}