File: tTableQuantum.cc

package info (click to toggle)
casacore 3.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,912 kB
  • sloc: cpp: 471,569; fortran: 16,372; ansic: 7,416; yacc: 4,714; lex: 2,346; sh: 1,865; python: 629; perl: 531; sed: 499; csh: 201; makefile: 32
file content (605 lines) | stat: -rw-r--r-- 21,198 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
//# tTableQuantum.cc: test program for Quantum columns in TableMeasures module
//# Copyright (C) 1997,1998,1999,2000,2001,2004
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//#        Internet email: casa-feedback@nrao.edu.
//#        Postal address: AIPS++ Project Office
//#                        National Radio Astronomy Observatory
//#                        520 Edgemont Road
//#                        Charlottesville, VA 22903-2475 USA

#include <casacore/measures/TableMeasures/TableQuantumDesc.h>
#include <casacore/measures/TableMeasures/ScalarQuantColumn.h>
#include <casacore/measures/TableMeasures/ArrayQuantColumn.h>
#include <casacore/casa/Quanta/Quantum.h>
#include <casacore/casa/Quanta/Unit.h>
#include <casacore/measures/Measures/MEpoch.h>
#include <casacore/casa/BasicSL/Complex.h>
#include <casacore/tables/Tables/ArrColDesc.h>
#include <casacore/tables/Tables/ScaColDesc.h>
#include <casacore/tables/Tables/SetupNewTab.h>
#include <casacore/tables/Tables/Table.h>
#include <casacore/tables/Tables/ArrayColumn.h>
#include <casacore/tables/Tables/ScalarColumn.h>
#include <casacore/tables/Tables/TableDesc.h>
#include <casacore/casa/Arrays/Array.h>
#include <casacore/casa/Arrays/Vector.h>
#include <casacore/casa/Arrays/ArrayUtil.h>
#include <casacore/casa/IO/ArrayIO.h>
#include <casacore/casa/OS/Timer.h>
#include <casacore/casa/Utilities/Assert.h>
#include <casacore/casa/Exceptions/Error.h>
#include <casacore/casa/iostream.h>


#include <casacore/casa/namespace.h>
int main (int argc, const char* argv[])
{
  Bool doExcep = (argc<2);
  uInt nrrow = 5000;
  if (argc >= 2) {
    istringstream istr(argv[1]);
    istr >> nrrow;
  }

  try {

    cout << "Begin tTableQuantum.cc.\n";

    // Need a table to work with.
    TableDesc td("tTableQuantum_tmp", "1", TableDesc::New);
    td.comment() = "Created by tTableQuantum.cc";

    // This test uses two ScalarQuantum columns. They will be a
    // Quantum<Double> and a for Quantum<Complex> columns.  The Quantum<Double>
    // will have static "deg" units but the units for the Quantum<Complex>
    // column will be variable.  This requires an additional String column for
    // storing the units.
    ScalarColumnDesc<Double> scdQD("ScaQuantDouble",
	"A scalar column of Quantum<Double> with units 'deg'.");
    ScalarColumnDesc<Complex> scdQC("ScaQuantComplex",
	"A scalar column Quantum<Complex> with variable units.");
    ScalarColumnDesc<String> scdStr("varUnitsColumn",
	"Units columns for column ScaQuantComplex");

    // Also create ArrayQuantum columns for the test
    ArrayColumnDesc<Double> acdQD("ArrQuantDouble",
	"A Quantum<double> array column");
    ArrayColumnDesc<Double> acdQD3("ArrQuantDoubleNonVar",
	"A Quantum<double> array column");
    ArrayColumnDesc<Double> acdQD4("ArrQuantDoubleNonVar2",
	"A Quantum<double> array column with 2 units");
    ArrayColumnDesc<Double> acdQD2("ArrQuantScaUnits",
	"A Quantum<double> array column");
    ArrayColumnDesc<String> acdStr("varArrUnitsColumn",
	"String column for array of units");
    ScalarColumnDesc<String> ascdStr("varArrScaUnitsColumn",
	"Scalar string column for variable units per row");

    ArrayColumnDesc<Double> bogusCol("BogusQuantCol",
	"an array column but won't be made a quantum column");

    // These must be added to the table descriptor
    cout << "Adding column descriptors to the table...\n";
    td.addColumn(scdQD);
    td.addColumn(scdQC);
    td.addColumn(acdQD);
    td.addColumn(acdQD2);
    td.addColumn(acdQD3);
    td.addColumn(acdQD4);
    td.addColumn(scdStr);
    td.addColumn(acdStr);
    td.addColumn(ascdStr);
    td.addColumn(bogusCol);

    // Now create the Table Quantum Descriptors.  Three are used below but
    // a couple of dummy objects are created to test assignment and the copy
    // constructor.  The object we finally want is tqdSQD.
    TableQuantumDesc tqddummy(td, "ScaQuantDouble", Unit("deg"));
    // test copy constructor
    TableQuantumDesc tqddummy2 = tqddummy;
    // test empty unit
    TableQuantumDesc tqdSQD(td, "ScaQuantDouble");
    // test assignment
    tqdSQD = tqddummy2;

    Vector<String> un1(2);
    Vector<Unit> un2(2);
    un1(0) = "MHz";
    un1(1) = "GHz";
    un2(0) = "kHz";
    un2(1) = "MHz";
    TableQuantumDesc tqdSQC(td, "ScaQuantComplex", "varUnitsColumn");
    TableQuantumDesc tqdAQC(td, "ArrQuantDouble", "varArrUnitsColumn");
    TableQuantumDesc tqdAQC2(td, "ArrQuantScaUnits", "varArrScaUnitsColumn");
    TableQuantumDesc tqdAQC3(td, "ArrQuantDoubleNonVar", Unit("MHz"));
    TableQuantumDesc tqdAQC4(td, "ArrQuantDoubleNonVar2", un1);
    cout << tqdAQC4.getUnits() << endl;
    TableQuantumDesc tqdAQC4a(td, "ArrQuantDoubleNonVar2", un2);
    cout << tqdAQC4a.getUnits() << endl;

    // test the exceptions
    if (doExcep) {
      cout << "Testing TableQuantumDesc constructor exceptions...\n";
      try {
	// no such column
	TableQuantumDesc taexcep(td, "SillyName");
      } catch (std::exception& x) {
	cout << "A no such column message should follow\n";
	cout << x.what() << endl;
      } 

      try {
	// variable unit's column doesn't exist.
	TableQuantumDesc taexcep(td, "ScaQuantComplex", "SillyName");
      } catch (std::exception& x) {
	cout << "A no such unit's column message should follow\n";
	cout << x.what() << endl;
      } 

      try {
	// The variable unit's column exists but the units type isn't String
	ScalarColumnDesc<Int> eucol("testvarcolumn",
		  "variable units column with incorrect type");
	td.addColumn(eucol);
	TableQuantumDesc taexcep(td, "ScaQuantComplex", "testvarcolumn");
      } catch (std::exception& x) {
	cout << "A message about an incorrect variable unit's type...\n";
	cout << x.what() << endl;
      } 
    }
    // ...and make them persistent.
    // the last one is done later after the table is created
    // (to test if write() works fine with the Table object).
    tqdSQD.write(td);
    tqdSQC.write(td);
    tqdAQC.write(td);
    tqdAQC2.write(td);
    tqdAQC3.write(td);

    cout << "Column's name is: " + tqdSQD.columnName() << endl;
    if (tqdSQD.isUnitVariable()) {
      cout << "Quantum column " + tqdSQD.columnName()
	   << " has variable units.\n";
      cout << "\tIts units are stored in String column '"
	                         + tqdSQD.unitColumnName() << "' \n";
    }
    cout << "Column's name is: " + tqdSQC.columnName() << endl;

    // create a table with 5 rows.
    SetupNewTable newtab("tTableQuantum_tmp.tab", td, Table::New);
    Table qtab(newtab, 5);

    // 
    tqdAQC4.write(qtab);

    // Check that columns contain quanta.
    AlwaysAssertExit (TableQuantumDesc::hasQuanta
		             ( TableColumn (qtab, "ScaQuantDouble")));
    AlwaysAssertExit (TableQuantumDesc::hasQuanta
		             ( TableColumn (qtab, "ScaQuantComplex")));
    AlwaysAssertExit (! TableQuantumDesc::hasQuanta
		             ( TableColumn (qtab, "varUnitsColumn")));
    AlwaysAssertExit (TableQuantumDesc::hasQuanta
		             ( TableColumn (qtab, "ArrQuantDouble")));
    AlwaysAssertExit (TableQuantumDesc::hasQuanta
		             ( TableColumn (qtab, "ArrQuantDoubleNonVar")));
    AlwaysAssertExit (TableQuantumDesc::hasQuanta
		             ( TableColumn (qtab, "ArrQuantDoubleNonVar2")));
    AlwaysAssertExit (TableQuantumDesc::hasQuanta
		             ( TableColumn (qtab, "ArrQuantScaUnits")));
    AlwaysAssertExit (! TableQuantumDesc::hasQuanta
		             ( TableColumn (qtab, "varArrUnitsColumn")));
    AlwaysAssertExit (! TableQuantumDesc::hasQuanta
		             ( TableColumn (qtab, "varArrScaUnitsColumn")));
    AlwaysAssertExit (! TableQuantumDesc::hasQuanta
		             ( TableColumn (qtab, "BogusQuantCol")));
    {
      // Play with a null object first
      cout << "Creating a null ScaQuantumCol()\n";
      ScalarQuantColumn<Double> sq1Col;
      ScalarQuantColumn<Double> sqCol(sq1Col);

      cout << "Check if isNull and then throwIfNull\n";
      if (sqCol.isNull()) {
	if (doExcep) {
	  // test isnull exception
	  try {
	    sqCol.throwIfNull();
	  } catch (std::exception& x) {
	    cout << "Catch an AipsError. Column is null...\n";
	    cout << x.what() << endl;
	  } 
	}
	cout << "Object says it is null...attach a column\n";
	sqCol.attach(qtab, "ScaQuantDouble");
	if (sqCol.isNull()) {
	  cout << "Apparantly still null...this isn't correct!\n";
	} else {
	  cout << "No longer null...good\n";
	}
	sqCol.throwIfNull();
      }

      // This should be a quantum column with fixed units
      if (sqCol.isUnitVariable()) {
	cout << "Columns units: " << sqCol.getUnits() << endl;
      }

      // put some quanta into the columns.
      Quantum<Double> q;
      for (uInt i=0; i<qtab.nrow(); i++) {
	q.setValue(i * 3.12);
	q.setUnit ("rad");
	sqCol.put(i, q);
      }
      ScalarQuantColumn<Double> sq2Col(sqCol);
      sq2Col.throwIfNull();
    }
    {
      // Could also read values from sqCol but instead a ScalarQuantCol
      // is created here to do that.
      // test attach member for this first
      ScalarQuantColumn<Double> rosq1Col;
      ScalarQuantColumn<Double> rosqCol(rosq1Col);
      if (rosqCol.isNull()) {
	rosqCol.attach(qtab, "ScaQuantDouble");
      }
      rosqCol.throwIfNull();
      cout << "Column's quantum units are: " << rosqCol.getUnits() << endl;
      uInt i;
      for (i=0; i<qtab.nrow(); i++) {
	cout << "Quantum " << i << ": " << rosqCol(i) << endl;
      }

      // get them again but convert them to arcmin
      Quantum<Double> q;
      for (i=0; i<qtab.nrow(); i++) {
	cout << "Quantum arcmin " << i << ": "
	     << rosqCol(i, Unit("arcmin")) << endl;
      }

      // get them again but convert them to arcsec.
      rosqCol.attach(qtab, "ScaQuantDouble", "arcsec");
      for (i=0; i<qtab.nrow(); i++) {
	cout << "Quantum arcsec " << i << ": " << rosqCol(i) << endl;
      }
      for (i=0; i<qtab.nrow(); i++) {
	cout << "Quantum arcmin " << i << ": "
	     << rosqCol(i, "arcmin") << endl;
      }
      ScalarQuantColumn<Double> rosq2Col(rosqCol);
      rosq2Col.throwIfNull();
    }
    {
      // Store a column of complex quantums with variable units.
      ScalarQuantColumn<Complex> sqCol(qtab, "ScaQuantComplex");
      if (sqCol.isUnitVariable()) {
	cout << "The units for ScaQuantComplex are variable.\n";
	cout << "getUnits() should produce an empty string: "
	     << sqCol.getUnits() << endl;
      } else {
	cout << "The units for ScaQuantComplex are not variable.\n";
	cout << "This is an error.\n";
      }
      Quantum<Complex> q(Complex(4., 0.21), "deg");
      sqCol.put(0, q);
      cout << q.get("m/s") << endl;
      q.convert("ms");
      sqCol.put(1, q);
      cout << q.get("m/s") << endl;
      q.convert("g");
      sqCol.put(2, q);
      cout << q.get("m/s") << endl;
      q.convert("Jy");
      sqCol.put(3, q);
      cout << q.get("m/s") << endl;
      q.convert("GHz");
      sqCol.put(4, q);	
      cout << q.get("m/s") << endl;
    }
    {
      // Lets have a look at them
      ScalarQuantColumn<Complex> rosqCol(qtab, "ScaQuantComplex");
      uInt i;
      for (i=0; i<qtab.nrow(); i++) {
	cout << "Complex quantum (var unit) " << i << ": " << rosqCol(i)
	     << endl;
      }
      Quantum<Complex> q(1., "m/s");
      for (i=0; i<qtab.nrow(); i++) {
	// this get the units converted to the units in q
	cout << "Complex quantum (var unit) " << i << ": "
	     << rosqCol(i, q) << endl;
      }
    }

    cout << "\nFinished test of Quantum scalar column...........\n";
    cout << "\nStart test of Quantum array column...........\n";

    // Fill an array with quanta.
    IPosition shape(2, 3, 2);
    Array<Quantum<Double> > quantArr(shape);
    Bool deleteIt;
    Quantum<Double>* q_p = quantArr.getStorage(deleteIt);
    q_p->setValue(1.41212);
    q_p->setUnit("GHz");
    q_p++;
    q_p->setValue(1.4921);
    q_p->setUnit("MHz");
    q_p++;
    q_p->setValue(1.4111);
    q_p->setUnit("kHz");
    q_p++;
    q_p->setValue(1.4003);
    q_p->setUnit("Hz");
    q_p++;
    q_p->setValue(1.22);
    q_p->setUnit("GHz");
    q_p++;
    q_p->setValue(1.090909);
    q_p->setUnit("Hz");
    quantArr.putStorage(q_p, deleteIt);

    {
      // Now for array columns.  This set up a Quant Array column with
      // variable units where the units vary per array element.
      ArrayQuantColumn<Double> tmpCol;
      if (doExcep) {
	try {
	  tmpCol.throwIfNull();
	} catch (std::exception& x) {
	  cout << "Catch an AipsError. Array column is null...\n";
	  cout << x.what() << endl;
	} 

	// test attaching a bogus quantum column
	try {
	  // create with a real column but not a quantum column
          // It will succeed because the QuantumDesc does not require a unit.
	  ArrayQuantColumn<Double> testCol(qtab, "BogusQuantCol");
	} catch (std::exception& x) {
	  cout << "Exception should not occur" << endl;
	} 
      }
      if (tmpCol.isNull()) {
	cout << "Array Quantum Column is initially null.\n";
	tmpCol.attach(qtab, "ArrQuantDouble");
      }
      // cover copy constructor
      ArrayQuantColumn<Double> aqCol = tmpCol;
      aqCol.throwIfNull();
      if (aqCol.isUnitVariable()) {
	cout << "Array quantum column: units are variable.\n";
      } else {
	cout << "Array quantum column units: " << aqCol.getUnits() << endl;
      }

      // cover putting an empty array (which should be OK)
      Array<Quantum<Double> > emptyArr;
      aqCol.put(0, emptyArr);

      // put the quantum array in the column (having variable units).
      aqCol.put(0, quantArr);
    }
    {
      ArrayQuantColumn<Double> roaqColx(qtab, "ArrQuantDouble");
      ArrayQuantColumn<Double> roaqCol(roaqColx);

      // test array conformance error exception on get()
      if (doExcep) {
	try {
	  Array<Quantum<Double> > badShapeArr(IPosition(2,2));
	  roaqCol.get(0, badShapeArr, False);
	} catch (std::exception& x) {
	  cout << "The following line should be a ";
	  cout << "Table array conformance error exception.\n";
	  cout << x.what() << endl;
	} 
      }
      {
	// This should succeed.
	Array<Quantum<Double> > badShapeArr(IPosition(2,2));
	roaqCol.get(0, badShapeArr, True);
	cout << badShapeArr << endl;
      }

      cout << roaqCol(0) << endl;
      cout << roaqCol(0, "Hz") << endl;

      ArrayQuantColumn<Double> roaqCol1(qtab, "ArrQuantDouble", "kHz");
      cout << roaqCol1(0) << endl;
      cout << roaqCol1(0, "Hz") << endl;
      cout << roaqCol1(0, un2) << endl;

      ArrayQuantColumn<Double> roaqCol2;
      roaqCol2.attach (qtab, "ArrQuantDouble");
      roaqCol2.attach (qtab, "ArrQuantDouble", "MHz");
      roaqCol2.attach (qtab, "ArrQuantDouble", un2);
      roaqCol2.reference (roaqCol1);

      ArrayQuantColumn<Double> roaqCol3(qtab, "ArrQuantDouble", un2);
      cout << roaqCol3(0) << endl;
      cout << roaqCol3(0, "Hz") << endl;
    }
    {
      // A second ArrayQuantColumn with variable units but in this case
      // the units only vary once per row as opposed to per array element
      // per row as in the example above.  This can be done because the
      // TableQuantDesc for the row specified a ScalarColumn as the
      // units column.
      // Could just construct the column completely but test attach member
      ArrayQuantColumn<Double> aqCol;
      aqCol.attach(qtab, "ArrQuantScaUnits");
      if (aqCol.isUnitVariable()) {
	cout << "Array quantum column: units are variable.\n";
      } else {
	cout << "Array quantum column units: " << aqCol.getUnits() << endl;
      }

      // cover putting an empty array (which should be OK)
      Array<Quantum<Double> > emptyArr;
      aqCol.put(0, emptyArr);

      // Put the quantum array in the column
      // Use unit "kHz" for the 2nd row.
      aqCol.put(0, quantArr);
      quantArr(IPosition(2,0,0)).setUnit ("kHz");
      aqCol.put(1, quantArr);
    }
    {
      // another way of creating the object
      ArrayQuantColumn<Double> roaqCol(qtab, "ArrQuantScaUnits");
      cout << roaqCol(0) << endl;
      cout << roaqCol(0, "Hz") << endl;
      cout << roaqCol(1) << endl;
      cout << roaqCol(1, "Hz") << endl;

      Quantum<Double> q(0.21, "Hz");
      cout << roaqCol(0, q);
    }
    {
      // These should complete the coverage of the class
      // contructor
      ArrayQuantColumn<Double> aqc(qtab, "ArrQuantDouble");
      // copy constructor
      ArrayQuantColumn<Double> aqc1 = aqc;
      // attach
      ArrayQuantColumn<Double> aqc2;
      aqc2.attach(qtab, "ArrQuantDouble");

      // cover putting an empty array (which should be OK)
      Array<Quantum<Double> > emptyArr;

      // non-variable units column
      ArrayQuantColumn<Double> aqc3(qtab, "ArrQuantDoubleNonVar");
      aqc3.put(0, emptyArr);
      aqc3.put(0, quantArr);
      ArrayQuantColumn<Double> aqc4(qtab, "ArrQuantDoubleNonVar2");
      aqc4.put(0, emptyArr);
      aqc4.put(0, quantArr);

      ArrayQuantColumn<Double> aqc3a(qtab, "ArrQuantDoubleNonVar");
      cout << aqc3a.getUnits() << endl;
      cout << aqc3a(0) << endl;
      ArrayQuantColumn<Double> aqc4a(qtab, "ArrQuantDoubleNonVar2");
      cout << aqc4a.getUnits() << endl;
      cout << aqc4a(0) << endl;
    }
    {
        // test ScalarQuantColumn::getColumn()
        ScalarQuantColumn<Double> col(qtab, "ScaQuantDouble"); 
        std::shared_ptr<Quantum<Vector<Double> > > v = col.getColumn();
        AlwaysAssert(v->getValue().size() == 5, AipsError);
        std::shared_ptr<Quantum<Vector<Double> > > w = col.getColumn("rad");
        AlwaysAssert(w->getValue().size() == 5, AipsError);
        Double frac = M_PI/180;
        for (uInt i=0; i<5; ++i) {
            AlwaysAssert(
                near(w->getValue()[i], frac*v->getValue()[i]), AipsError
            );
        }
        ScalarQuantColumn<Complex> ccol(qtab, "ScaQuantComplex");
        std::shared_ptr<Quantum<Vector<Complex> > > x = ccol.getColumn(); 
        AlwaysAssert(x->getValue().size() == 5, AipsError);
        std::shared_ptr<Quantum<Vector<Complex> > > y = ccol.getColumn("rad"); 
        for (uInt i=0; i<5; ++i) {
            AlwaysAssert(
                near(y->getValue()[i], frac*x->getValue()[i]), AipsError
            );
        }
    }

  } catch (std::exception& x) {
    cout << "Unexpected exception1: " << x.what() << endl;
    return 1;
  } 

  // Try it with a readonly table.
  try {
    Table qtab ("tTableQuantum_tmp.tab");
    // Could also read values from sqCol but instead a ScalarQuantCol
    // is created here to do that.
    // test attach member for this first
    ScalarQuantColumn<Double> rosqCol;
    if (rosqCol.isNull()) {
      rosqCol.attach(qtab, "ScaQuantDouble");
    }
    rosqCol.throwIfNull();
    cout << "Column's quantum units are: " << rosqCol.getUnits() << endl;
    uInt i;
    for (i=0; i<qtab.nrow(); i++) {
      cout << "Quantum " << i << ": " << rosqCol(i) << endl;
    }
  } catch (std::exception& x) {
    cout << "Unexpected exception2: " << x.what() << endl;
    return 1;
  } 

  // Now test the performance by putting arrays in nrrow rows.
  try {
    Table qtab ("tTableQuantum_tmp.tab", Table::Update);
    qtab.addRow(nrrow);
    IPosition shape(2, 3, 2);
    Array<Quantum<Double> > aqArr(shape);
    aqArr = Quantum<Double>(1.41212, "GHz");
    Array<Double> tabArr(shape);
    tabArr = 1.41212;
    ArrayQuantColumn<Double> aqCol(qtab, "ArrQuantDouble");
    ArrayQuantColumn<Double> aqCol2(qtab, "ArrQuantDoubleNonVar");
    ArrayColumn<Double> tabCol(qtab, "ArrQuantDouble");
    cout << ">>>" << endl;
    Timer timer;
    for (uInt i=0; i<nrrow; i++) {
      aqCol.put (i, aqArr);
    }
    timer.show ("put tq var arrays");
    timer.mark();
    for (uInt i=0; i<nrrow; i++) {
      aqCol2.put (i, aqArr);
    }
    timer.show ("put tq fix arrays");
    timer.mark();
    for (uInt i=0; i<nrrow; i++) {
      tabCol.put (i, tabArr);
    }
    timer.show ("put tab    arrays");
    timer.mark();
    for (uInt i=0; i<nrrow; i++) {
      aqCol.get (i, aqArr);
    }
    timer.show ("get tq var arrays");
    timer.mark();
    for (uInt i=0; i<nrrow; i++) {
      aqCol2.get (i, aqArr);
    }
    timer.show ("get tq fix arrays");
    timer.mark();
    for (uInt i=0; i<nrrow; i++) {
      tabCol.get (i, tabArr);
    }
    timer.show ("get tab    arrays");
    cout << "<<<" << endl;
  } catch (std::exception& x) {
    cout << "Unexpected exception3: " << x.what() << endl;
    return 1;
  } 

  cout << "\nExecution of tTableQuantum.cc ended normally.\n";
  return 0;
}