File: tTiledEmpty.cc

package info (click to toggle)
casacore 3.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 51,680 kB
  • sloc: cpp: 462,815; fortran: 16,372; ansic: 7,403; yacc: 4,626; lex: 2,340; sh: 1,786; python: 629; perl: 531; sed: 499; csh: 34; makefile: 31
file content (104 lines) | stat: -rw-r--r-- 3,718 bytes parent folder | download
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
//# tTiledEmpty.cc: Test creation of a tiled array without write or flush
//# Copyright (C) 2010
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This program is free software; you can redistribute it and/or modify it
//# under the terms of the GNU General Public License as published by the Free
//# Software Foundation; either version 2 of the License, or (at your option)
//# any later version.
//#
//# This program 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 General Public License for
//# more details.
//#
//# You should have received a copy of the GNU General Public License along
//# with this program; 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: aips2-request@nrao.edu.
//#        Postal address: AIPS++ Project Office
//#                        National Radio Astronomy Observatory
//#                        520 Edgemont Road
//#                        Charlottesville, VA 22903-2475 USA
//#
//# $Id$

#include <casacore/tables/Tables/TableDesc.h>
#include <casacore/tables/Tables/SetupNewTab.h>
#include <casacore/tables/Tables/Table.h>
#include <casacore/tables/Tables/ArrColDesc.h>
#include <casacore/tables/Tables/ArrayColumn.h>
#include <casacore/tables/DataMan/TiledCellStMan.h>
#include <casacore/casa/Arrays/ArrayLogical.h>
#include <casacore/casa/Utilities/Assert.h>
#include <casacore/casa/Exceptions/Error.h>
#include <casacore/casa/iostream.h>

#include <casacore/casa/namespace.h>

// This program tests if the cration of a tiled array succeeds if the
// array is written nor flushed.

void writeTable(const TSMOption&, bool writeFlush);
void readTable(const TSMOption&, bool written);


int main() {
  try {
    for (uInt i=0; i<2; ++i) {
      writeTable(TSMOption::Cache, i==0);
      readTable(TSMOption::Cache, i==0);
      readTable(TSMOption::Buffer, i==0);
      readTable(TSMOption::MMap, i==0);
      writeTable(TSMOption::Buffer, i==0);
      readTable(TSMOption::Cache, i==0);
      readTable(TSMOption::Buffer, i==0);
      readTable(TSMOption::MMap, i==0);
      writeTable(TSMOption::MMap, i==0);
      readTable(TSMOption::Cache, i==0);
      readTable(TSMOption::Buffer, i==0);
      readTable(TSMOption::MMap, i==0);
    }
  } catch (std::exception& x) {
    cout << "Caught an exception: " << x.what() << endl;
    return 1;
  } 
  return 0;                           // exit with success status
}

// First build a description.
void writeTable (const TSMOption& tsmOpt, bool write)
{
  IPosition tileShape(2,64,64);
  IPosition cubeShape(2,256,256);
  // Build the table description.
  TableDesc td ("", "1", TableDesc::Scratch);
  td.addColumn (ArrayColumnDesc<float>  ("Data", 2));
  // Now create a new table from the description.
  SetupNewTable newtab("tTiledEmpty_tmp.data", td, Table::New);
  // Create a storage manager for it.
  TiledCellStMan sm1 ("TSMExample", tileShape);
  Table table(newtab, 0, False, Table::LittleEndian, tsmOpt);
  table.addRow();
  ArrayColumn<float> col(table, "Data");
  col.setShape (0, cubeShape);
  if (write) {
    Array<float> arr(cubeShape);
    arr = 0.;
    col.put (0, arr);
  }
}

void readTable(const TSMOption& tsmOpt, bool written)
{
  Table table("tTiledEmpty_tmp.data", Table::Old, tsmOpt);
  ArrayColumn<float> col(table, "Data");
  Array<float> arr;
  col.getColumn (arr);
  AlwaysAssertExit (arr.shape() == IPosition(3,256,256,1));
  if (written) {
    AlwaysAssertExit (allEQ(arr, float(0.)));
  }
}