47 #ifndef _INCLUDED_Field3D_Field3DFile_H_
48 #define _INCLUDED_Field3D_Field3DFile_H_
58 #include <boost/intrusive_ptr.hpp>
83 template <
class Data_T>
85 readField(
const std::string &className, hid_t layerGroup,
86 const std::string &filename,
const std::string &layerPath);
149 typedef boost::intrusive_ptr<Partition>
Ptr;
150 typedef boost::intrusive_ptr<const Partition>
CPtr;
281 const std::string &partitionName)
const;
284 const std::string &partitionName)
const;
300 const std::string &layerName,
305 std::string
removeUniqueId(
const std::string &partitionName)
const;
454 template <
class Data_T>
459 template <
class Data_T>
462 const std::string &layerName)
const;
468 template <
class Data_T>
473 template <
class Data_T>
476 const std::string &layerName)
const;
480 template <
template <
typename T>
class Field_T,
class Data_T>
481 typename Field_T<Data_T>::Vec
486 template <
template <
typename T>
class Field_T,
class Data_T>
487 typename Field_T<Data_T>::Vec
489 const std::string &layerName)
const;
493 template <
template <
typename T>
class Field_T,
class Data_T>
494 typename Field_T<Data_T>::Vec
499 template <
template <
typename T>
class Field_T,
class Data_T>
500 typename Field_T<Data_T>::Vec
502 const std::string &layerName)
const;
514 template <
class Data_T>
517 const std::string &layerName,
518 bool isVectorLayer)
const;
525 template <
class Data_T>
534 template <
class Data_T>
544 bool open(
const std::string &filename);
552 herr_t
parsePartition(hid_t loc_id,
const std::string partitionName);
555 herr_t
parseLayer(hid_t loc_id,
const std::string &partitionName,
556 const std::string &layerName);
571 template <
class Data_T>
574 const std::string &layerName)
const;
578 template <
class Data_T>
581 const std::string &layerName)
const;
585 template <
class Data_T>
587 readLayer(
const std::string &intPartitionName,
588 const std::string &layerName,
589 bool isVectorLayer)
const;
653 template <
class Data_T>
656 {
return writeScalarLayer<Data_T>(layerName, std::string(
"default"), layer); }
659 template <
class Data_T>
661 typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr layer)
662 {
return writeVectorLayer<Data_T>(layerName, std::string(
"default"), layer); }
666 template <
class Data_T>
668 const std::string &layerName,
673 template <
class Data_T>
678 template <
class Data_T>
680 const std::string &layerName,
681 typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr layer);
685 template <
class Data_T>
704 template <
class Data_T>
707 const std::string &layerName,
719 template <
class Data_T>
720 bool writeLayer(
const std::string &partitionName,
721 const std::string &layerName,
738 namespace InputFile {
753 const H5L_info_t *linfo,
void *opdata);
758 herr_t
parseLayers(hid_t loc_id,
const char *partitionName,
759 const H5L_info_t *linfo,
void *opdata);
767 template <
class Data_T>
777 std::vector<std::string> parts;
780 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
781 std::vector<std::string> layers;
783 for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
785 if ((name.length() == 0) || (*l == name)) {
786 FieldPtr mf = readScalarLayer<Data_T>(*p, *l);
799 template <
class Data_T>
802 const std::string &layerName)
const
811 if ((layerName.length() == 0) || (partitionName.length() == 0))
814 std::vector<std::string> parts;
817 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
818 std::vector<std::string> layers;
821 for (vector<string>::iterator l = layers.begin();
822 l != layers.end(); ++l) {
824 if (*l == layerName) {
825 FieldPtr mf = readScalarLayer<Data_T>(*p, *l);
838 template <
class Data_T>
849 std::vector<std::string> parts;
852 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
853 std::vector<std::string> layers;
855 for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
857 if ((name.length() == 0) || (*l == name)) {
858 FieldPtr mf = readVectorLayer<Data_T>(*p, *l);
870 template <
class Data_T>
873 const std::string &layerName)
const
882 if ((layerName.length() == 0) || (partitionName.length() == 0))
885 std::vector<std::string> parts;
888 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
889 std::vector<std::string> layers;
892 for (vector<string>::iterator l = layers.begin();
893 l != layers.end(); ++l) {
895 if (*l == layerName) {
896 FieldPtr mf = readVectorLayer<Data_T>(*p, *l);
909 template <
class Data_T>
912 const std::string &layerName,
913 bool isVectorLayer)
const
915 using namespace boost;
917 using namespace Hdf5Util;
932 l = part->vectorLayer(layerName);
934 l = part->scalarLayer(layerName);
941 string layerPath = l->parent +
"/" + l->name;
944 if (layerGroup.id() < 0) {
952 if (!
readAttribute(layerGroup.id(),
"class_name", className)) {
961 field = readField<Data_T>(className, layerGroup.id(),
m_filename, layerPath);
964 #if 0 // This isn't really an error
972 string metadataPath = layerPath +
"/metadata";
974 if (metadataGroup.id() > 0) {
980 field->attribute = layerName;
981 field->setMapping(part->mapping);
988 template <
template <
typename T>
class Field_T,
class Data_T>
989 typename Field_T<Data_T>::Vec
993 typedef typename Field_T<Data_T>::Vec TypedFieldList;
997 originals = readScalarLayers<Data_T>(layerName);
1000 TypedFieldList output;
1001 typename FieldList::iterator i = originals.begin();
1002 for (; i != originals.end(); ++i) {
1003 typename Field_T<Data_T>::Ptr targetField;
1006 output.push_back(targetField);
1008 typename Field_T<Data_T>::Ptr newTarget(
new Field_T<Data_T>);
1009 newTarget->name = (*i)->name;
1010 newTarget->attribute = (*i)->attribute;
1011 newTarget->copyMetadata(*i);
1012 newTarget->copyFrom(*i);
1013 output.push_back(newTarget);
1022 template <
template <
typename T>
class Field_T,
class Data_T>
1023 typename Field_T<Data_T>::Vec
1025 const std::string &layerName)
const
1028 typedef typename Field_T<Data_T>::Vec TypedFieldList;
1031 FieldList originals;
1032 originals = readScalarLayers<Data_T>(partitionName, layerName);
1035 TypedFieldList output;
1036 typename FieldList::iterator i = originals.begin();
1037 for (; i != originals.end(); ++i) {
1038 typename Field_T<Data_T>::Ptr targetField;
1041 output.push_back(targetField);
1043 typename Field_T<Data_T>::Ptr newTarget(
new Field_T<Data_T>);
1044 newTarget->name = (*i)->name;
1045 newTarget->attribute = (*i)->attribute;
1046 newTarget->copyMetadata(**i);
1047 newTarget->copyFrom(*i);
1048 output.push_back(newTarget);
1057 template <
template <
typename T>
class Field_T,
class Data_T>
1058 typename Field_T<Data_T>::Vec
1062 typedef typename Field_T<Data_T>::Vec TypedFieldList;
1065 FieldList originals;
1066 originals = readVectorLayers<Data_T>(layerName);
1069 TypedFieldList output;
1070 typename FieldList::iterator i = originals.begin();
1071 for (; i != originals.end(); ++i) {
1072 typename Field_T<Data_T>::Ptr targetField;
1075 output.push_back(targetField);
1077 typename Field_T<Data_T>::Ptr newTarget(
new Field_T<Data_T>);
1078 newTarget->name = (*i)->name;
1079 newTarget->attribute = (*i)->attribute;
1080 newTarget->copyMetadata(*i);
1081 newTarget->copyFrom(*i);
1082 output.push_back(newTarget);
1091 template <
template <
typename T>
class Field_T,
class Data_T>
1092 typename Field_T<Data_T>::Vec
1094 const std::string &layerName)
const
1097 typedef typename Field_T<Data_T>::Vec TypedFieldList;
1100 FieldList originals;
1101 originals = readVectorLayers<Data_T>(partitionName, layerName);
1104 TypedFieldList output;
1105 typename FieldList::iterator i = originals.begin();
1106 for (; i != originals.end(); ++i) {
1107 typename Field_T<Data_T>::Ptr targetField;
1110 output.push_back(targetField);
1112 typename Field_T<Data_T>::Ptr newTarget(
new Field_T<Data_T>);
1113 newTarget->name = (*i)->name;
1114 newTarget->attribute = (*i)->attribute;
1115 newTarget->copyMetadata(*i);
1116 newTarget->copyFrom(*i);
1117 output.push_back(newTarget);
1126 template <
class Data_T>
1129 const std::string &layerName,
1130 bool isVectorLayer)
const
1132 using namespace boost;
1133 using namespace std;
1134 using namespace Hdf5Util;
1139 if ((layerName.length() == 0) || (partitionName.length() == 0))
1142 std::vector<std::string> parts, layers;
1145 bool foundPartition =
false;
1147 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1149 foundPartition =
true;
1150 if (isVectorLayer) {
1155 for (vector<string>::iterator l = layers.begin();
1156 l != layers.end(); ++l) {
1157 if (*l == layerName) {
1167 layer = part->vectorLayer(layerName);
1169 layer = part->scalarLayer(layerName);
1175 string layerPath = layer->
parent +
"/" + layer->
name;
1177 if (layerGroup.id() < 0) {
1179 + layerName +
" in .f3d file ");
1183 Box3i extents, dataW;
1184 if (!
readAttribute(layerGroup,
"extents", 6, extents.min.x)) {
1187 if (!
readAttribute(layerGroup,
"data_window", 6, dataW.min.x)) {
1192 field->
setSize(extents, dataW);
1195 string metadataPath = layerPath +
"/metadata";
1197 if (metadataGroup.id() > 0) {
1203 field->
name = partitionName;
1207 output.push_back(field);
1213 if (!foundPartition) {
1223 template <
class Data_T>
1227 using namespace std;
1230 typedef std::vector<FieldPtr> FieldList;
1234 std::vector<std::string> parts;
1237 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1238 std::vector<std::string> layers;
1240 for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1242 if ((name.length() == 0) || (*l == name)) {
1243 FieldList f = readProxyLayer<Data_T>(*p, *l,
false);
1244 for (
typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1258 template <
class Data_T>
1262 using namespace std;
1265 typedef std::vector<FieldPtr> FieldList;
1269 std::vector<std::string> parts;
1272 for (vector<string>::iterator p = parts.begin(); p != parts.end(); ++p) {
1273 std::vector<std::string> layers;
1275 for (vector<string>::iterator l = layers.begin(); l != layers.end(); ++l) {
1277 if ((name.length() == 0) || (*l == name)) {
1278 FieldList f = readProxyLayer<Data_T>(*p, *l,
true);
1279 for (
typename FieldList::iterator i = f.begin(); i != f.end(); ++i) {
1293 template <
class Data_T>
1296 const std::string &layerName)
const
1303 template <
class Data_T>
1306 const std::string &layerName)
const
1308 return readLayer<FIELD3D_VEC3_T<Data_T> >(
intPartitionName, layerName,
true);
1315 template <
class Data_T>
1318 const std::string &layerName,
1321 using namespace Hdf5Util;
1322 using namespace Exc;
1326 newPart->name = partitionName;
1329 if (partGroup.id() < 0) {
1331 "Error creating partition: " + newPart->name);
1344 if (!writeMapping(partGroup.id(), field->
mapping())) {
1346 "writeMapping returned false for an unknown reason ");
1350 catch (WriteMappingException &e) {
1357 "Unknown error when writing mapping for partition: "
1365 part->mapping = field->
mapping();
1369 if (!
writeAttribute(partGroup.id(),
"is_field3d_partition",
"1")) {
1379 template <
class Data_T>
1382 const std::string &layerName,
1386 using namespace std;
1387 using namespace Exc;
1388 using namespace Hdf5Util;
1392 "Called writeLayer with null pointer. Ignoring...");
1398 "Attempting to write layer without opening file first. ");
1402 string partitionName =
intPartitionName(userPartitionName, layerName, field);
1409 part = createNewPartition<Data_T>(partitionName,layerName,field);
1416 "Couldn't add layer \"" + layerName +
"\" to partition \""
1417 + partitionName +
"\" because the layer's mapping is null.");
1423 if (!isVectorLayer) {
1424 if (part->scalarLayer(layerName)) {
1426 std::string newPartitionName = incrementPartitionName(partitionName);
1427 part = createNewPartition<Data_T>(newPartitionName,layerName,field);
1432 if (part->vectorLayer(layerName)) {
1434 std::string newPartitionName = incrementPartitionName(partitionName);
1435 part = createNewPartition<Data_T>(newPartitionName,layerName,field);
1442 if (!part->mapping) {
1449 if (!field->
mapping()->isIdentical(part->mapping)) {
1451 +
"\" to partition \"" + partitionName
1452 +
"\" because mapping doesn't match");
1462 layer.
name = layerName;
1463 layer.parent = partitionName;
1468 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
1470 if (layerGroup.id() < 0) {
1476 if (!
writeAttribute(layerGroup.id(),
"class_type",
"field3d_layer")) {
1483 if (metadataGroup.id() < 0) {
1487 if (!writeMetadata(metadataGroup.id(), field)) {
1500 part->addVectorLayer(layer);
1502 part->addScalarLayer(layer);
1509 template <
class Data_T>
1512 const std::string &layerName,
1515 return writeLayer<Data_T>(partitionName, layerName,
false, field);
1520 template <
class Data_T>
1524 if (layer->
name.size() == 0) {
1526 "Tried to write a scalar layer with no name");
1531 "Tried to write a scalar layer with no attribute name");
1534 return writeScalarLayer<Data_T>(layer->
name, layer->
attribute, layer);
1539 template <
class Data_T>
1543 const std::string &layerName,
1544 typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr field)
1546 return writeLayer<FIELD3D_VEC3_T<Data_T> >(partitionName, layerName,
1552 template <
class Data_T>
1555 (
typename Field<FIELD3D_VEC3_T<Data_T> >::Ptr layer)
1557 if (layer->name.size() == 0) {
1559 "Tried to write a vector layer with no name");
1562 if (layer->attribute.size() == 0) {
1564 "Tried to write a vector layer with no attribute name");
1567 return writeVectorLayer<Data_T>(layer->name, layer->attribute, layer);
1574 template <
class Data_T>
1577 const std::string &filename,
const std::string &layerPath)
1593 FieldBase::Ptr field = io->read(layerGroup, filename, layerPath, typeEnum);