http://code.google.com/p/casacore/source/detail?r=21236
Modified:
/trunk/images/Images/ImageAttrGroup.h
/trunk/images/Images/ImageAttrGroupCasa.cc
/trunk/images/Images/ImageAttrGroupCasa.h
/trunk/images/Images/ImageAttrGroupHDF5.cc
/trunk/images/Images/ImageAttrGroupHDF5.h
/trunk/images/Images/ImageProxy.cc
/trunk/images/Images/ImageProxy.h
/trunk/images/Images/ImageUtilities.cc
/trunk/images/Images/test/tImageAttrHandler.cc
/trunk/images/Images/test/tImageAttrHandler.out
/trunk/images/Images/test/tImageReorderer.cc
=======================================
--- /trunk/images/Images/ImageAttrGroup.h Tue Mar 20 02:55:47 2012
+++ /trunk/images/Images/ImageAttrGroup.h Tue Apr 3 05:53:02 2012
@@ -121,9 +121,8 @@
virtual ~ImageAttrGroup();
- // Get the number of values of the group.
- // This is the number of elements in an attribute.
- virtual uInt nvalues() const = 0;
+ // Get the number of rows in the group.
+ virtual uInt nrows() const = 0;
// Test if an attribute exists.
virtual Bool hasAttr (const String& attrName) const = 0;
@@ -135,8 +134,11 @@
// It returns TpOther if the attribute is not defined.
virtual DataType dataType (const String& attrName) const = 0;
- // Get the data of the given attribute.
- virtual ValueHolder getData (const String& attrName) = 0;
+ // Get the data of the given attribute in the given row
+ virtual ValueHolder getData (const String& attrName, uInt rownr) = 0;
+
+ // Get the data of all attributes in a rows.
+ virtual Record getDataRow (uInt rownr) = 0;
// Get the possible units of the values.
// An empty vector is returned if no units.
@@ -146,12 +148,13 @@
// An empty vector is returned if no MEASINFO exists.
virtual Vector<String> getMeasInfo (const String& attrName) = 0;
- // Put the data of the given attribute.
- // If the table does not contain data yet, it will be sized to the size
- // of the vector. Otherwise the vector size has to match the table size.
+ // Put the data of the given attribute in the given row.
+ // If the row or attribute is new, it will be added. Note that the
+ // new row must be directly after the last row in the group.
// <br>If not empty, the units and MEASINFO will be put as column
keywords.
// The MEASINFO vector must be given as type,Ref.
- virtual void putData (const String& attrName, const ValueHolder& data,
+ virtual void putData (const String& attrName, uInt rownr,
+ const ValueHolder& data,
const Vector<String>& units = Vector<String>(),
const Vector<String>& measInfo = Vector<String>())
= 0;
};
=======================================
--- /trunk/images/Images/ImageAttrGroupCasa.cc Tue Mar 20 02:55:47 2012
+++ /trunk/images/Images/ImageAttrGroupCasa.cc Tue Apr 3 05:53:02 2012
@@ -28,6 +28,7 @@
//# Includes
#include <images/Images/ImageAttrGroupCasa.h>
#include <tables/Tables/TableRecord.h>
+#include <tables/Tables/TableRow.h>
#include <tables/Tables/TableColumn.h>
#include <tables/Tables/ArrColDesc.h>
#include <tables/Tables/ScaColDesc.h>
@@ -52,7 +53,7 @@
}
}
- uInt ImageAttrGroupCasa::nvalues() const
+ uInt ImageAttrGroupCasa::nrows() const
{
return itsTable.table().nrow();
}
@@ -76,14 +77,21 @@
return TpOther;
}
- ValueHolder ImageAttrGroupCasa::getData (const String& attrName)
- {
- ValueHolder value (itsTable.getColumn (attrName, 0, -1, 1));
+ ValueHolder ImageAttrGroupCasa::getData (const String& attrName, uInt
rownr)
+ {
+ ValueHolder value (itsTable.getCell (attrName, rownr));
if (value.isNull()) {
value = ValueHolder (Array<Int>());
}
return value;
}
+
+ Record ImageAttrGroupCasa::getDataRow (uInt rownr)
+ {
+ ROTableRow tabrow (itsTable.table());
+ // Transform TableRecord to Record.
+ return ValueHolder(tabrow.get(rownr)).asRecord();
+ }
Vector<String> ImageAttrGroupCasa::getUnit (const String& attrName)
{
@@ -108,149 +116,117 @@
}
void ImageAttrGroupCasa::putData (const String& attrName,
+ uInt rownr,
const ValueHolder& data,
const Vector<String>& units,
const Vector<String>& measInfo)
{
itsTable.reopenRW();
- addColumn (attrName, data);
- TableColumn col(itsTable.table(), attrName);
- if (!units.empty()) {
- itsTable.putKeyword (attrName, "QuantumUnits", -1, False,
- ValueHolder(units));
- }
- if (!measInfo.empty()) {
- AlwaysAssert (measInfo.size() == 2, AipsError);
- // Define MEASINFO if not defined yet.
- if (! col.rwKeywordSet().isDefined("MEASINFO")) {
- TableRecord rec;
- col.rwKeywordSet().defineRecord ("MEASINFO", rec);
- }
- itsTable.putKeyword (attrName, "MEASINFO.type", -1, False,
- ValueHolder(measInfo[0]));
- itsTable.putKeyword (attrName, "MEASINFO.Ref", -1, False,
- ValueHolder(measInfo[1]));
- }
- itsTable.putColumn (attrName, 0, -1 , 1, data);
+ // If needed, add the column for the attribute.
+ if (addNewColumn (attrName, data)) {
+ // Units and MEASINFO are supposed to be the same for all rows,
+ // so only put them for the first time, thus if the column has been
added.
+ TableColumn col(itsTable.table(), attrName);
+ if (!units.empty()) {
+ itsTable.putKeyword (attrName, "QuantumUnits", -1, False,
+ ValueHolder(units));
+ }
+ if (!measInfo.empty()) {
+ AlwaysAssert (measInfo.size() == 2, AipsError);
+ // Define MEASINFO if not defined yet.
+ if (! col.rwKeywordSet().isDefined("MEASINFO")) {
+ TableRecord rec;
+ col.rwKeywordSet().defineRecord ("MEASINFO", rec);
+ }
+ itsTable.putKeyword (attrName, "MEASINFO.type", -1, False,
+ ValueHolder(measInfo[0]));
+ itsTable.putKeyword (attrName, "MEASINFO.Ref", -1, False,
+ ValueHolder(measInfo[1]));
+ }
+ }
+ checkRows (attrName, rownr);
+ itsTable.putCell (attrName, Vector<Int>(1,rownr), data);
}
- void ImageAttrGroupCasa::checkRows (const String& attrName, uInt size)
+ void ImageAttrGroupCasa::checkRows (const String& attrName, uInt rownr)
{
uInt nrow = itsTable.nrows();
- if (nrow == 0) {
- itsTable.addRow (size);
- } else if (size != nrow) {
- throw AipsError("ImageAttrGroupCasa: cannot put " +
- String::toString(size) +
- " elements of attr " + attrName +
- " into table containing " +
- String::toString(nrow) + " rows");
+ // A new row can only be added right after the last row.
+ if (rownr > nrow) {
+ throw AipsError("ImageAttrGroupCasa: row " + String::toString(rownr)
+
+ " of attribute " + attrName +
+ " cannot be added; beyond current #rows " +
+ String::toString(nrow));
+ }
+ if (rownr == nrow) {
+ itsTable.addRow(1);
}
}
- void ImageAttrGroupCasa::addColumn (const String& attrName,
- const ValueHolder& data)
+ Bool ImageAttrGroupCasa::addNewColumn (const String& attrName,
+ const ValueHolder& data)
{
Table& tab = itsTable.table();
- Bool doAdd = !tab.tableDesc().isColumn(attrName);
+ if (tab.tableDesc().isColumn(attrName)) {
+ // Column already exists.
+ return False;
+ }
+ // Add the column with the correct type.
+ // Assume arrays can have varying shapes.
IPosition colShape(1,1);
switch (data.dataType()) {
- case TpArrayBool:
- colShape.resize(0);
- colShape = data.asArrayBool().shape(); // fall through
case TpBool:
- if (doAdd) {
- if (colShape.size() == 1) {
- tab.addColumn (ScalarColumnDesc<Bool>(attrName));
- } else{
- tab.addColumn (ArrayColumnDesc<Bool>
- (attrName, colShape.getFirst(colShape.size()-1)));
- }
- }
+ tab.addColumn (ScalarColumnDesc<Bool>(attrName));
break;
- case TpArrayInt:
- colShape.resize(0);
- colShape = data.asArrayInt().shape(); // fall through
+ case TpArrayBool:
+ tab.addColumn (ArrayColumnDesc<Bool> (attrName));
+ break;
+ case TpChar:
+ case TpUChar:
+ case TpShort:
+ case TpUShort:
case TpInt:
- if (doAdd) {
- if (colShape.size() == 1) {
- tab.addColumn (ScalarColumnDesc<Int>(attrName));
- } else{
- tab.addColumn (ArrayColumnDesc<Int>
- (attrName, colShape.getFirst(colShape.size()-1)));
- }
- }
+ case TpUInt:
+ tab.addColumn (ScalarColumnDesc<Int>(attrName));
break;
- case TpArrayFloat:
- colShape.resize(0);
- colShape = data.asArrayFloat().shape(); // fall through
+ case TpArrayInt:
+ tab.addColumn (ArrayColumnDesc<Int> (attrName));
+ break;
case TpFloat:
- if (doAdd) {
- if (colShape.size() == 1) {
- tab.addColumn (ScalarColumnDesc<Float>(attrName));
- } else{
- tab.addColumn (ArrayColumnDesc<Float>
- (attrName, colShape.getFirst(colShape.size()-1)));
- }
- }
+ tab.addColumn (ScalarColumnDesc<Float>(attrName));
break;
- case TpArrayDouble:
- colShape.resize(0);
- colShape = data.asArrayDouble().shape(); // fall through
+ case TpArrayFloat:
+ tab.addColumn (ArrayColumnDesc<Float> (attrName));
+ break;
case TpDouble:
- if (doAdd) {
- if (colShape.size() == 1) {
- tab.addColumn (ScalarColumnDesc<Double>(attrName));
- } else{
- tab.addColumn (ArrayColumnDesc<Double>
- (attrName, colShape.getFirst(colShape.size()-1)));
- }
- }
+ tab.addColumn (ScalarColumnDesc<Double>(attrName));
break;
- case TpArrayComplex:
- colShape.resize(0);
- colShape = data.asArrayComplex().shape(); // fall through
+ case TpArrayDouble:
+ tab.addColumn (ArrayColumnDesc<Double> (attrName));
+ break;
case TpComplex:
- if (doAdd) {
- if (colShape.size() == 1) {
- tab.addColumn (ScalarColumnDesc<Complex>(attrName));
- } else{
- tab.addColumn (ArrayColumnDesc<Complex>
- (attrName, colShape.getFirst(colShape.size()-1)));
- }
- }
+ tab.addColumn (ScalarColumnDesc<Complex>(attrName));
break;
- case TpArrayDComplex:
- colShape.resize(0);
- colShape = data.asArrayDComplex().shape(); // fall through
+ case TpArrayComplex:
+ tab.addColumn (ArrayColumnDesc<Complex> (attrName));
+ break;
case TpDComplex:
- if (doAdd) {
- if (colShape.size() == 1) {
- tab.addColumn (ScalarColumnDesc<DComplex>(attrName));
- } else{
- tab.addColumn (ArrayColumnDesc<DComplex>
- (attrName, colShape.getFirst(colShape.size()-1)));
- }
- }
+ tab.addColumn (ScalarColumnDesc<DComplex>(attrName));
break;
- case TpArrayString:
- colShape.resize(0);
- colShape = data.asArrayString().shape(); // fall through
+ case TpArrayDComplex:
+ tab.addColumn (ArrayColumnDesc<DComplex> (attrName));
+ break;
case TpString:
- if (doAdd) {
- if (colShape.size() == 1) {
- tab.addColumn (ScalarColumnDesc<String>(attrName));
- } else{
- tab.addColumn (ArrayColumnDesc<String>
- (attrName, colShape.getFirst(colShape.size()-1)));
- }
- }
+ tab.addColumn (ScalarColumnDesc<String>(attrName));
+ break;
+ case TpArrayString:
+ tab.addColumn (ArrayColumnDesc<String> (attrName));
break;
default:
- throw AipsError("ImageAttrGroupCasa::addColumn: Unknown datatype " +
+ throw AipsError("ImageAttrGroupCasa::addNewColumn: Unknown
datatype " +
String::toString(data.dataType()));
}
- checkRows (attrName, colShape[colShape.size()-1]);
+ return True;
}
} //# NAMESPACE CASA - END
=======================================
--- /trunk/images/Images/ImageAttrGroupCasa.h Tue Mar 20 02:55:47 2012
+++ /trunk/images/Images/ImageAttrGroupCasa.h Tue Apr 3 05:53:02 2012
@@ -73,9 +73,8 @@
// Flush the attibrutes if needed.
void flush();
- // Get the number of values of the group.
- // This is the number of elements in an attribute.
- virtual uInt nvalues() const;
+ // Get the number of rows in the group.
+ virtual uInt nrows() const;
// Test if an attribute exists.
virtual Bool hasAttr (const String& attrName) const;
@@ -88,7 +87,10 @@
virtual DataType dataType (const String& attrName) const;
// Get the data of the given attribute.
- virtual ValueHolder getData (const String& attrName);
+ virtual ValueHolder getData (const String& attrName, uInt rownr);
+
+ // Get the data of all attributes in a rows.
+ virtual Record getDataRow (uInt rownr);
// Get the possible units of the values.
// An empty vector is returned if no units.
@@ -103,7 +105,8 @@
// of the vector. Otherwise the vector size has to match the table size.
// <br>If not empty, the units and MEASINFO will be put as column
keywords.
// The MEASINFO vector must be given as type,Ref.
- virtual void putData (const String& attrName, const ValueHolder& data,
+ virtual void putData (const String& attrName, uInt rownr,
+ const ValueHolder& data,
const Vector<String>& units = Vector<String>(),
const Vector<String>& measInfo = Vector<String>());
@@ -112,8 +115,8 @@
// Add rows if the table is still empty.
void checkRows (const String& attrName, uInt size);
- // Add a column for the given attribute for the data type in the value.
- void addColumn (const String& attrName, const ValueHolder&);
+ // Add a new column for the given attribute for the data type in the
value.
+ Bool addNewColumn (const String& attrName, const ValueHolder&);
//# Data members.
TableProxy itsTable;
=======================================
--- /trunk/images/Images/ImageAttrGroupHDF5.cc Tue Mar 20 02:55:47 2012
+++ /trunk/images/Images/ImageAttrGroupHDF5.cc Tue Apr 3 05:53:02 2012
@@ -30,6 +30,7 @@
#include <casa/HDF5/HDF5Group.h>
#include <casa/HDF5/HDF5Record.h>
#include <casa/Exceptions/Error.h>
+#include <iomanip>
namespace casa {
@@ -37,13 +38,9 @@
const String& attrName,
Bool isWritable)
: itsChanged (False),
- itsCanWrite (isWritable),
- itsNValues (0)
+ itsCanWrite (isWritable)
{
itsRecord = HDF5Record::readRecord (image, attrName);
- if (! itsRecord.empty()) {
- itsNValues = itsRecord.shape(0).last();
- }
}
ImageAttrGroupHDF5::~ImageAttrGroupHDF5()
@@ -57,32 +54,33 @@
}
}
- uInt ImageAttrGroupHDF5::nvalues() const
- {
- if (itsRecord.empty()) {
- return 0;
- }
- // Return the length of the first attribute.
- // Assert it is not a UNIT or MEASINFO.
- IPosition shape (itsRecord.shape(0));
- return shape[shape.size()-1];
+ uInt ImageAttrGroupHDF5::nrows() const
+ {
+ return itsRecord.nfields();
}
Bool ImageAttrGroupHDF5::hasAttr (const String& attrName) const
{
- return itsRecord.isDefined (attrName);
+ if (itsRecord.empty()) {
+ return False;
+ }
+ return itsRecord.subRecord(0).isDefined (attrName);
}
Vector<String> ImageAttrGroupHDF5::attrNames() const
{
- Vector<String> names(itsRecord.size());
+ if (itsRecord.empty()) {
+ return Vector<String>();
+ }
+ const Record& subRecord = itsRecord.subRecord(0);
+ Vector<String> names(subRecord.size());
uInt nr = 0;
for (uInt i=0; i<names.size(); ++i) {
// Only names not ending in _UNIT or _MEASINFO
- String name = itsRecord.name(i);
+ String name = subRecord.name(i);
if (!((name.size() >= 5 && name.substr(name.size()-5) == "_UNIT")
||
(name.size() >= 9 && name.substr(name.size()-9)
== "_MEASINFO"))){
- names[nr++] = itsRecord.name(i);
+ names[nr++] = subRecord.name(i);
}
}
names.resize (nr, True);
@@ -91,34 +89,59 @@
DataType ImageAttrGroupHDF5::dataType (const String& attrName) const
{
- if (itsRecord.isDefined (attrName)) {
- return itsRecord.dataType (attrName);
+ if (itsRecord.empty()) {
+ return TpOther;
+ }
+ const Record& subRecord = itsRecord.subRecord(0);
+ if (subRecord.isDefined (attrName)) {
+ return subRecord.dataType (attrName);
}
return TpOther;
}
- ValueHolder ImageAttrGroupHDF5::getData (const String& attrName)
- {
- return itsRecord.asValueHolder (attrName);
+ ValueHolder ImageAttrGroupHDF5::getData (const String& attrName, uInt
rownr)
+ {
+ if (rownr >= itsRecord.nfields()) {
+ throw AipsError("ImageAttrGroupHDF5: rownr " +
String::toString(rownr) +
+ " does not exist");
+ }
+ const Record& subRecord = itsRecord.subRecord(rownr);
+ return subRecord.asValueHolder (attrName);
+ }
+
+ Record ImageAttrGroupHDF5::getDataRow (uInt rownr)
+ {
+ if (rownr >= itsRecord.nfields()) {
+ throw AipsError("ImageAttrGroupHDF5: rownr " +
String::toString(rownr) +
+ " does not exist");
+ }
+ return itsRecord.subRecord(rownr);
}
Vector<String> ImageAttrGroupHDF5::getUnit (const String& attrName)
{
- if (itsRecord.isDefined (attrName + "_UNIT")) {
- return itsRecord.asArrayString(attrName + "_UNIT");
+ if (! itsRecord.empty()) {
+ const Record& subRecord = itsRecord.subRecord(0);
+ if (subRecord.isDefined (attrName + "_UNIT")) {
+ return subRecord.asArrayString(attrName + "_UNIT");
+ }
}
return Vector<String>();
}
Vector<String> ImageAttrGroupHDF5::getMeasInfo (const String& attrName)
{
- if (itsRecord.isDefined (attrName + "_MEASINFO")) {
- return itsRecord.asArrayString(attrName + "_MEASINFO");
+ if (! itsRecord.empty()) {
+ const Record& subRecord = itsRecord.subRecord(0);
+ if (subRecord.isDefined (attrName + "_MEASINFO")) {
+ return subRecord.asArrayString(attrName + "_MEASINFO");
+ }
}
return Vector<String>();
}
void ImageAttrGroupHDF5::putData (const String& attrName,
+ uInt rownr,
const ValueHolder& data,
const Vector<String>& units,
const Vector<String>& measInfo)
@@ -126,30 +149,38 @@
if (!itsCanWrite) {
throw AipsError("ImageAttrGroupHDF5: attribute data cannot be
written");
}
- itsRecord.defineFromValueHolder (attrName, data);
- checkSize (attrName);
+ checkRows(attrName, rownr);
+ Record& subRecord = itsRecord.rwSubRecord(rownr);
+ subRecord.defineFromValueHolder (attrName, data);
if (!units.empty()) {
- itsRecord.define (attrName + "_UNIT", units);
+ subRecord.define (attrName + "_UNIT", units);
}
if (!measInfo.empty()) {
AlwaysAssert (measInfo.size() == 2, AipsError);
- itsRecord.define (attrName + "_MEASINFO", measInfo);
+ subRecord.define (attrName + "_MEASINFO", measInfo);
}
itsChanged = True;
}
- void ImageAttrGroupHDF5::checkSize (const String& attrName)
- {
- IPosition shape (itsRecord.shape(attrName));
- uInt size = shape(shape.size() - 1);
- if (itsNValues == 0) {
- itsNValues = size;
- } else if (size != itsNValues) {
- throw AipsError("ImageAttrGroupHDF5: cannot put " +
- String::toString(size) +
- " elements of attr " + attrName +
- " into group containing " +
- String::toString(itsNValues) + " rows");
+ String makeRowName (uInt rownr)
+ {
+ ostringstream ostr;
+ ostr << std::setfill('0') << std::setw(5) << rownr;
+ return ostr.str();
+ }
+
+ void ImageAttrGroupHDF5::checkRows (const String& attrName, uInt rownr)
+ {
+ uInt nrow = itsRecord.nfields();
+ // A new row can only be added right after the last row.
+ if (rownr > nrow) {
+ throw AipsError("ImageAttrGroupHDF5: row " + String::toString(rownr)
+
+ " of attribute " + attrName +
+ " cannot be added; beyond current #rows " +
+ String::toString(nrow));
+ }
+ if (rownr == nrow) {
+ itsRecord.defineRecord (makeRowName(rownr), Record());
}
}
=======================================
--- /trunk/images/Images/ImageAttrGroupHDF5.h Tue Mar 20 02:55:47 2012
+++ /trunk/images/Images/ImageAttrGroupHDF5.h Tue Apr 3 05:53:02 2012
@@ -60,8 +60,7 @@
// The default constructor creates a null object.
explicit ImageAttrGroupHDF5 (Bool isWritable=False)
: itsChanged (False),
- itsCanWrite (isWritable),
- itsNValues (0)
+ itsCanWrite (isWritable)
{}
// Construct the object for an attribute group in the image.
@@ -78,9 +77,8 @@
// Flush the attibrutes if needed.
void flush (HDF5Group& image, const String& attrGroupName);
- // Get the number of values of the group.
- // This is the number of elements in an attribute.
- virtual uInt nvalues() const;
+ // Get the number of rows in the group.
+ virtual uInt nrows() const;
// Test if an attribute exists.
virtual Bool hasAttr (const String& attrName) const;
@@ -92,8 +90,11 @@
// It returns TpOther if the attribute is not defined.
virtual DataType dataType (const String& attrName) const;
- // Get the data of the given attribute.
- virtual ValueHolder getData (const String& attrName);
+ // Get the data of the given attribute in the given row.
+ virtual ValueHolder getData (const String& attrName, uInt rownr);
+
+ // Get the data of all attributes in a rows.
+ virtual Record getDataRow (uInt rownr);
// Get the possible units of the values (stored as <name>_UNIT).
// An empty vector is returned if no units.
@@ -108,19 +109,19 @@
// of the vector. Otherwise the vector size has to match the table size.
// <br>If not empty, the units and MEASINFO will be put as column
keywords.
// The MEASINFO vector must be given as type,Ref.
- virtual void putData (const String& attrName, const ValueHolder& data,
+ virtual void putData (const String& attrName, uInt rownr,
+ const ValueHolder& data,
const Vector<String>& units = Vector<String>(),
const Vector<String>& measInfo = Vector<String>());
private:
- // Check if the value size is correct.
- void checkSize (const String& attrName);
+ // Check the rownr and add a row if needed.
+ void checkRows (const String& attrName, uInt rownr);
//# Data members.
- Record itsRecord; //# Record containing all attributes
+ Record itsRecord; //# Record containing all attributes (subrecord
per row)
Bool itsChanged; //# Has the Record changed?
Bool itsCanWrite; //# Can attributes be written?
- uInt itsNValues; //# Number of values per attribute; 0 = unknown yet
};
} //# NAMESPACE CASA - END
=======================================
--- /trunk/images/Images/ImageProxy.cc Mon Apr 2 05:08:10 2012
+++ /trunk/images/Images/ImageProxy.cc Tue Apr 3 05:53:02 2012
@@ -557,11 +557,23 @@
{
return itsAttrHandler->openGroup(groupName).attrNames();
}
+
+ uInt ImageProxy::attrNrows (const String& groupName) const
+ {
+ return itsAttrHandler->openGroup(groupName).nrows();
+ }
ValueHolder ImageProxy::getAttr (const String& groupName,
- const String& attrName) const
- {
- return itsAttrHandler->openGroup(groupName).getData (attrName);
+ const String& attrName,
+ uInt rownr) const
+ {
+ return itsAttrHandler->openGroup(groupName).getData (attrName, rownr);
+ }
+
+ Record ImageProxy::getAttrRow (const String& groupName,
+ uInt rownr) const
+ {
+ return itsAttrHandler->openGroup(groupName).getDataRow (rownr);
}
Vector<String> ImageProxy::getAttrUnit(const String& groupName,
@@ -578,11 +590,12 @@
void ImageProxy::putAttr (const String& groupName,
const String& attrName,
+ uInt rownr,
const ValueHolder& value,
const Vector<String>& units,
const Vector<String>& measInfo)
{
- itsAttrHandler->openGroup(groupName).putData (attrName, value,
+ itsAttrHandler->openGroup(groupName).putData (attrName, rownr, value,
units, measInfo);
}
=======================================
--- /trunk/images/Images/ImageProxy.h Tue Mar 20 02:55:47 2012
+++ /trunk/images/Images/ImageProxy.h Tue Apr 3 05:53:02 2012
@@ -184,9 +184,17 @@
// Get the names of all attributes in a group.
Vector<String> attrNames (const String& groupName) const;
- // Get the value of an attribute in a group.
+ // Get the number of rows in an attribute group.
+ uInt attrNrows (const String& groupName) const;
+
+ // Get the value of an attribute in a group row.
ValueHolder getAttr (const String& groupName,
- const String& attrName) const;
+ const String& attrName,
+ uInt rownr) const;
+
+ // Get all attributes in a group row.
+ Record getAttrRow (const String& groupName,
+ uInt rownr) const;
// Get the unit(s) of an attribute in a group.
Vector<String> getAttrUnit(const String& groupName,
@@ -196,8 +204,9 @@
Vector<String> getAttrMeas(const String& groupName,
const String& attrName) const;
- // Put the value, unit, and measinfo of an attribute in a group.
- void putAttr (const String& groupName, const String& attrName,
+ // Put the value, unit, and measinfo of an attribute in a group row.
+ // The attribute or row is added if new.
+ void putAttr (const String& groupName, const String& attrName, uInt
rownr,
const ValueHolder& value,
const Vector<String>& units,
const Vector<String>& measInfo);
=======================================
--- /trunk/images/Images/ImageUtilities.cc Tue Mar 20 02:55:47 2012
+++ /trunk/images/Images/ImageUtilities.cc Tue Apr 3 05:53:02 2012
@@ -1125,11 +1125,13 @@
ImageAttrGroup& inGroup = in.openGroup (groupNames[i]);
ImageAttrGroup& outGroup = out.createGroup (groupNames[i]);
Vector<String> attrNames = inGroup.attrNames();
- for (uInt j=0; j<attrNames.size(); ++j) {
- outGroup.putData (attrNames[j],
- inGroup.getData (attrNames[j]),
- inGroup.getUnit (attrNames[j]),
- inGroup.getMeasInfo (attrNames[j]));
+ for (uInt rownr=0; rownr<inGroup.nrows(); ++rownr) {
+ for (uInt j=0; j<attrNames.size(); ++j) {
+ outGroup.putData (attrNames[j], rownr,
+ inGroup.getData (attrNames[j], rownr),
+ inGroup.getUnit (attrNames[j]),
+ inGroup.getMeasInfo (attrNames[j]));
+ }
}
in.closeGroup (groupNames[i]);
out.closeGroup (groupNames[i]);
=======================================
--- /trunk/images/Images/test/tImageAttrHandler.cc Wed Mar 21 05:55:04 2012
+++ /trunk/images/Images/test/tImageAttrHandler.cc Tue Apr 3 05:53:02 2012
@@ -47,12 +47,12 @@
cout << attrHand.groupNames()<<endl;
cout << attrHand.hasGroup("testGroup1")<<endl;
ImageAttrGroup& group = attrHand.createGroup ("testGroup1");
- cout << "GOT GROUP "<<group.nvalues()<<' '<<group.attrNames()<<endl;
+ cout << "GOT GROUP "<<group.nrows()<<' '<<group.attrNames()<<endl;
cout << attrHand.hasGroup("testGroup1")<<endl;
cout << attrHand.groupNames()<<endl;
- group.putData ("attr1", ValueHolder(Vector<String>(1,"aa")));
- cout << "GOT GROUP "<<group.nvalues()<<' '<<group.attrNames()<<endl;
- cout<<group.attrNames() << endl;
+ group.putData ("attr1", 0, ValueHolder("aa"));
+ cout << "GOT GROUP "<<group.nrows()<<' '<<group.attrNames()<<endl;
+ cout <<group.attrNames() << endl;
}
void testCreateCasa (const String& imageName)
@@ -86,7 +86,7 @@
ImageAttrHandler& attrHand (image->attrHandler());
cout << attrHand.groupNames()<<endl;
ImageAttrGroup& group = attrHand.openGroup ("testGroup1");
- cout << "GOT GROUP "<<group.nvalues()<<' '<<group.attrNames()<<endl;
+ cout << "GOT GROUP "<<group.nrows()<<' '<<group.attrNames()<<endl;
delete image;
}
@@ -96,17 +96,20 @@
ImageInterface<Float>* image = doOpen(imageName);
ImageAttrHandler& attrHand (image->attrHandler());
ImageAttrGroup& group1 = attrHand.openGroup ("testGroup1");
- Array<Int> arr1(IPosition(2,4,1));
+ Array<Int> arr1(IPosition(1,4));
indgen (arr1);
- group1.putData ("attr2", ValueHolder(arr1));
+ group1.putData ("attr2", 0, ValueHolder(arr1));
ImageAttrGroup& group2 = attrHand.createGroup ("testGroup2");
- Array<Int> arr2(IPosition(2,3,4));
+ Array<Int> arr2(IPosition(1,3));
indgen (arr2);
Vector<String> measInfo(2);
measInfo[0] = "direction";
measInfo[1] = "J2000";
- group2.putData ("attr2", ValueHolder(arr2),
- Vector<String>(1,"rad"), measInfo);
+ for (uInt rownr=0; rownr<4; ++rownr) {
+ group2.putData ("attr2", rownr, ValueHolder(arr2),
+ Vector<String>(1,"rad"), measInfo);
+ arr2 += 3;
+ }
delete image;
}
@@ -160,13 +163,15 @@
Vector<String> groupNames = attrHand.groupNames();
for (uInt i=0; i<groupNames.size(); ++i) {
ImageAttrGroup& group = attrHand.openGroup (groupNames[i]);
- cout << "Attribute group " << groupNames[i] << " nvalues="
- << group.nvalues() << endl;
+ cout << "Attribute group " << groupNames[i] << " nrows="
+ << group.nrows() << endl;
Vector<String> attrNames = group.attrNames();
for (uInt j=0; j<attrNames.size(); ++j) {
- cout << attrNames[j] << ": "
- << group.getData(attrNames[j]) << " "
- << group.getUnit(attrNames[j]) << " "
+ cout << attrNames[j] << ": ";
+ for (uInt rownr=0; rownr<group.nrows(); ++rownr) {
+ cout << group.getData(attrNames[j], rownr) << ",";
+ }
+ cout << " " << group.getUnit(attrNames[j]) << " "
<< group.getMeasInfo(attrNames[j]) << endl;
}
}
=======================================
--- /trunk/images/Images/test/tImageAttrHandler.out Wed Mar 21 05:55:04 2012
+++ /trunk/images/Images/test/tImageAttrHandler.out Tue Apr 3 05:53:02 2012
@@ -14,83 +14,47 @@
GOT GROUP 1 [attr1]
image = tImageAttrHandler_tmp.img1
-Attribute group testGroup1 nvalues=1
-attr1: [aa] [] []
+Attribute group testGroup1 nrows=1
+attr1: aa, [] []
testUpdate ...
image = tImageAttrHandler_tmp.img1
-Attribute group testGroup1 nvalues=1
-attr1: [aa] [] []
-attr2: Axis Lengths: [4, 1] (NB: Matrix in Row/Column order)
-[0
- 1
- 2
- 3]
- [] []
-Attribute group testGroup2 nvalues=4
-attr2: Axis Lengths: [3, 4] (NB: Matrix in Row/Column order)
-[0, 3, 6, 9
- 1, 4, 7, 10
- 2, 5, 8, 11]
- [rad] [direction, J2000]
+Attribute group testGroup1 nrows=1
+attr1: aa, [] []
+attr2: [0, 1, 2, 3], [] []
+Attribute group testGroup2 nrows=4
+attr2: [0, 1, 2],[3, 4, 5],[6, 7, 8],[9, 10, 11], [rad] [direction,
J2000]
testCopy tImageAttrHandler_tmp.img1 to tImageAttrHandler_tmp.img1_cp1
>>> to Casa<<<
image = tImageAttrHandler_tmp.img1_cp1
-Attribute group testGroup1 nvalues=1
-attr1: [aa] [] []
-attr2: Axis Lengths: [4, 1] (NB: Matrix in Row/Column order)
-[0
- 1
- 2
- 3]
- [] []
-Attribute group testGroup2 nvalues=4
-attr2: Axis Lengths: [3, 4] (NB: Matrix in Row/Column order)
-[0, 3, 6, 9
- 1, 4, 7, 10
- 2, 5, 8, 11]
- [rad] [direction, J2000]
+Attribute group testGroup1 nrows=1
+attr1: aa, [] []
+attr2: [0, 1, 2, 3], [] []
+Attribute group testGroup2 nrows=4
+attr2: [0, 1, 2],[3, 4, 5],[6, 7, 8],[9, 10, 11], [rad] [direction,
J2000]
testCopy tImageAttrHandler_tmp.img1 to tImageAttrHandler_tmp.img1_cp2
>>> to HDF5<<<
image = tImageAttrHandler_tmp.img1_cp2
-Attribute group testGroup1 nvalues=1
-attr1: [aa] [] []
-attr2: Axis Lengths: [4, 1] (NB: Matrix in Row/Column order)
-[0
- 1
- 2
- 3]
- [] []
-Attribute group testGroup2 nvalues=4
-attr2: Axis Lengths: [3, 4] (NB: Matrix in Row/Column order)
-[0, 3, 6, 9
- 1, 4, 7, 10
- 2, 5, 8, 11]
- [rad] [direction, J2000]
+Attribute group testGroup1 nrows=1
+attr1: aa, [] []
+attr2: [0, 1, 2, 3], [] []
+Attribute group testGroup2 nrows=4
+attr2: [0, 1, 2],[3, 4, 5],[6, 7, 8],[9, 10, 11], [rad] [direction,
J2000]
testSub tImageAttrHandler_tmp.img1 to tImageAttrHandler_tmp.img1_sub
>>> to Casa<<<
image = tImageAttrHandler_tmp.img1_sub
-Attribute group testGroup1 nvalues=1
-attr1: [aa] [] []
-attr2: Axis Lengths: [4, 1] (NB: Matrix in Row/Column order)
-[0
- 1
- 2
- 3]
- [] []
-Attribute group testGroup2 nvalues=4
-attr2: Axis Lengths: [3, 4] (NB: Matrix in Row/Column order)
-[0, 3, 6, 9
- 1, 4, 7, 10
- 2, 5, 8, 11]
- [rad] [direction, J2000]
+Attribute group testGroup1 nrows=1
+attr1: aa, [] []
+attr2: [0, 1, 2, 3], [] []
+Attribute group testGroup2 nrows=4
+attr2: [0, 1, 2],[3, 4, 5],[6, 7, 8],[9, 10, 11], [rad] [direction,
J2000]
>>> Test HDF5 image <<<
testCreate ...
@@ -107,80 +71,44 @@
GOT GROUP 1 [attr1]
image = tImageAttrHandler_tmp.img2
-Attribute group testGroup1 nvalues=1
-attr1: [aa] [] []
+Attribute group testGroup1 nrows=1
+attr1: aa, [] []
testUpdate ...
image = tImageAttrHandler_tmp.img2
-Attribute group testGroup1 nvalues=1
-attr1: [aa] [] []
-attr2: Axis Lengths: [4, 1] (NB: Matrix in Row/Column order)
-[0
- 1
- 2
- 3]
- [] []
-Attribute group testGroup2 nvalues=4
-attr2: Axis Lengths: [3, 4] (NB: Matrix in Row/Column order)
-[0, 3, 6, 9
- 1, 4, 7, 10
- 2, 5, 8, 11]
- [rad] [direction, J2000]
+Attribute group testGroup1 nrows=1
+attr1: aa, [] []
+attr2: [0, 1, 2, 3], [] []
+Attribute group testGroup2 nrows=4
+attr2: [0, 1, 2],[3, 4, 5],[6, 7, 8],[9, 10, 11], [rad] [direction,
J2000]
testCopy tImageAttrHandler_tmp.img2 to tImageAttrHandler_tmp.img2_cp1
>>> to Casa<<<
image = tImageAttrHandler_tmp.img2_cp1
-Attribute group testGroup1 nvalues=1
-attr1: [aa] [] []
-attr2: Axis Lengths: [4, 1] (NB: Matrix in Row/Column order)
-[0
- 1
- 2
- 3]
- [] []
-Attribute group testGroup2 nvalues=4
-attr2: Axis Lengths: [3, 4] (NB: Matrix in Row/Column order)
-[0, 3, 6, 9
- 1, 4, 7, 10
- 2, 5, 8, 11]
- [rad] [direction, J2000]
+Attribute group testGroup1 nrows=1
+attr1: aa, [] []
+attr2: [0, 1, 2, 3], [] []
+Attribute group testGroup2 nrows=4
+attr2: [0, 1, 2],[3, 4, 5],[6, 7, 8],[9, 10, 11], [rad] [direction,
J2000]
testCopy tImageAttrHandler_tmp.img2 to tImageAttrHandler_tmp.img2_cp2
>>> to HDF5<<<
image = tImageAttrHandler_tmp.img2_cp2
-Attribute group testGroup1 nvalues=1
-attr1: [aa] [] []
-attr2: Axis Lengths: [4, 1] (NB: Matrix in Row/Column order)
-[0
- 1
- 2
- 3]
- [] []
-Attribute group testGroup2 nvalues=4
-attr2: Axis Lengths: [3, 4] (NB: Matrix in Row/Column order)
-[0, 3, 6, 9
- 1, 4, 7, 10
- 2, 5, 8, 11]
- [rad] [direction, J2000]
+Attribute group testGroup1 nrows=1
+attr1: aa, [] []
+attr2: [0, 1, 2, 3], [] []
+Attribute group testGroup2 nrows=4
+attr2: [0, 1, 2],[3, 4, 5],[6, 7, 8],[9, 10, 11], [rad] [direction,
J2000]
testSub tImageAttrHandler_tmp.img2 to tImageAttrHandler_tmp.img2_sub
>>> to Casa<<<
image = tImageAttrHandler_tmp.img2_sub
-Attribute group testGroup1 nvalues=1
-attr1: [aa] [] []
-attr2: Axis Lengths: [4, 1] (NB: Matrix in Row/Column order)
-[0
- 1
- 2
- 3]
- [] []
-Attribute group testGroup2 nvalues=4
-attr2: Axis Lengths: [3, 4] (NB: Matrix in Row/Column order)
-[0, 3, 6, 9
- 1, 4, 7, 10
- 2, 5, 8, 11]
- [rad] [direction, J2000]
+Attribute group testGroup1 nrows=1
+attr1: aa, [] []
+attr2: [0, 1, 2, 3], [] []
+Attribute group testGroup2 nrows=4
+attr2: [0, 1, 2],[3, 4, 5],[6, 7, 8],[9, 10, 11], [rad] [direction,
J2000]
=======================================
--- /trunk/images/Images/test/tImageReorderer.cc Wed Jan 4 04:03:36 2012
+++ /trunk/images/Images/test/tImageReorderer.cc Tue Apr 3 05:53:02 2012
@@ -132,9 +132,9 @@
vector<Float> inVec, outVec;
inData.tovector(inVec);
outData.tovector(outVec);
- for(uInt i=0; i<inShape[0]; i++) {
- for(uInt j=0; j<inShape[1]; j++) {
- for(uInt k=0; k<inShape[2]; k++) {
+ for(Int i=0; i<inShape[0]; i++) {
+ for(Int j=0; j<inShape[1]; j++) {
+ for(Int k=0; k<inShape[2]; k++) {
AlwaysAssert(inCube(i,j,k) == outCube(k,i,j), AipsError);
}
}