Commit 7c90451e authored by Jerry Clarke's avatar Jerry Clarke
Browse files

Add methods for building Xdmf XML strings

parent 02c832f9
......@@ -69,24 +69,7 @@ XdmfAttribute::Build(){
if(XdmfElement::Build() != XDMF_SUCCESS) return(XDMF_FAIL);
this->Set("AttributeType", this->GetAttributeTypeAsString());
this->Set("Center", this->GetAttributeCenterAsString());
if(this->DataXml){
if(this->DOM){
if(this->InsertedDataXml == this->DataXml){
// Already done
return(XDMF_SUCCESS);
}
if(this->DOM->InsertFromString(this->GetElement(), this->DataXml)){
this->SetInsertedDataXml(this->DataXml);
return(XDMF_SUCCESS);
}else{
XdmfErrorMessage("Error Inserting Raw XML : " << endl << this->DataXml);
return(XDMF_FAIL);
}
}else{
XdmfErrorMessage("Can't insert raw XML sine DOM is not set");
return(XDMF_FAIL);
}
}
if(this->BuildFromDataXml() == XDMF_SUCCESS) return(XDMF_SUCCESS);
if(this->Values){
XdmfDataItem *di = NULL;
XdmfXmlNode node;
......
......@@ -191,10 +191,10 @@ ostrstream StringOutput;
XdmfInt64 i, rank, Dimensions[ XDMF_MAX_DIMENSION ];
rank = this->GetShape( Dimensions );
for( i = 0 ; i < rank ; i++ ){
for( i = 0 ; i < rank - 1 ; i++ ){
StringOutput << XDMF_64BIT_CAST Dimensions[i] << " ";
}
StringOutput << ends;
StringOutput << XDMF_64BIT_CAST Dimensions[i] << ends;
this->SetShapeString(StringOutput.str());
StringOutput.rdbuf()->freeze(0);
return( this->ShapeString );
......
......@@ -594,35 +594,7 @@ XdmfInt32 XdmfDataItem::Build(){
default :
break;
}
if(this->DataXml){
if(this->DOM){
if(this->InsertedDataXml == this->DataXml){
// Already done
return(XDMF_SUCCESS);
}
switch (this->Format) {
case XDMF_FORMAT_HDF :
this->Set("Format", "HDF");
break;
case XDMF_FORMAT_XML :
this->Set("Format", "XML");
break;
default :
XdmfErrorMessage("Unsupported Data Format");
return(XDMF_FAIL);
}
if(this->DOM->InsertFromString(this->GetElement(), this->DataXml)){
this->SetInsertedDataXml(this->DataXml);
return(XDMF_SUCCESS);
}else{
XdmfErrorMessage("Error Inserting Raw XML : " << endl << this->DataXml);
return(XDMF_FAIL);
}
}else{
XdmfErrorMessage("Can't insert raw XML sine DOM is not set");
return(XDMF_FAIL);
}
}
if(this->BuildFromDataXml(1) == XDMF_SUCCESS) return(XDMF_SUCCESS);
if(this->CheckValues(this->Format) != XDMF_SUCCESS){
XdmfErrorMessage("Error Accessing Internal XdmfValues");
return(XDMF_FAIL);
......
......@@ -423,6 +423,42 @@ XdmfConstString XdmfElement::GetElementType(){
return((XdmfConstString)this->Element->name);
}
XdmfInt32
XdmfElement::BuildFromDataXml(XdmfInt32 AllowCData){
if(this->DataXml){
if(AllowCData){
char first = 0;
XdmfInt64 i = 0;
while((first <= ' ') && (i < strlen(this->DataXml))){
first = this->DataXml[i++];
if((first > ' ') && (first != '<')){
this->Set("CData", this->DataXml);
return(XDMF_SUCCESS);
}
}
}
if(this->DOM){
if(this->InsertedDataXml == this->DataXml){
// Already done
return(XDMF_SUCCESS);
}
if(this->DOM->InsertFromString(this->GetElement(), this->DataXml)){
this->SetInsertedDataXml(this->DataXml);
return(XDMF_SUCCESS);
}else{
XdmfErrorMessage("Error Inserting Raw XML : " << endl << this->DataXml);
return(XDMF_FAIL);
}
}else{
XdmfErrorMessage("Can't insert raw XML sine DOM is not set");
return(XDMF_FAIL);
}
}
return(XDMF_SUCCESS);
}
XdmfInt32 XdmfElement::Build(){
XdmfConstString name;
......
......@@ -148,6 +148,9 @@ public:
//! Set the DataXml. This will override the Build() method and inject the raw XML
XdmfInt32 SetInsertedDataXml(XdmfString Inserted){this->InsertedDataXml = Inserted; return(XDMF_SUCCESS);};
//! Build XML from user supplied DataXml
XdmfInt32 BuildFromDataXml(XdmfInt32 AllowCData = 0);
//! Get the Element type : Grid, Topology, etc.
XdmfConstString GetElementType();
......
......@@ -88,6 +88,7 @@ XdmfGeometry::GetDataItem(XdmfInt32 Index, XdmfXmlNode Node){
return(di);
}
XdmfInt32
XdmfGeometry::Build(){
XdmfDataItem *di = NULL;
......@@ -96,24 +97,8 @@ XdmfGeometry::Build(){
cout << "Building Geometry" << endl;
if(XdmfElement::Build() != XDMF_SUCCESS) return(XDMF_FAIL);
this->Set("GeometryType", this->GetGeometryTypeAsString());
if(this->DataXml){
if(this->DOM){
if(this->InsertedDataXml == this->DataXml){
// Already done
return(XDMF_SUCCESS);
}
if(this->DOM->InsertFromString(this->GetElement(), this->DataXml)){
this->SetInsertedDataXml(this->DataXml);
return(XDMF_SUCCESS);
}else{
XdmfErrorMessage("Error Inserting Raw XML : " << endl << this->DataXml);
return(XDMF_FAIL);
}
}else{
XdmfErrorMessage("Can't insert raw XML sine DOM is not set");
return(XDMF_FAIL);
}
}
// Build Children from String , if provided
if(this->BuildFromDataXml() == XDMF_SUCCESS) return(XDMF_SUCCESS);
switch( this->GeometryType ){
case XDMF_GEOMETRY_VXVYVZ:
if(!this->VectorX || !this->VectorY || !this->VectorZ){
......
......@@ -83,24 +83,7 @@ XdmfTopology::Build(){
OffsetStream << this->BaseOffset << ends;
this->Set("BaseOffset", Offset);
}
if(this->DataXml){
if(this->DOM){
if(this->InsertedDataXml == this->DataXml){
// Already done
return(XDMF_SUCCESS);
}
if(this->DOM->InsertFromString(this->GetElement(), this->DataXml)){
this->SetInsertedDataXml(this->DataXml);
return(XDMF_SUCCESS);
}else{
XdmfErrorMessage("Error Inserting Raw XML : " << endl << this->DataXml);
return(XDMF_FAIL);
}
}else{
XdmfErrorMessage("Can't insert raw XML sine DOM is not set");
return(XDMF_FAIL);
}
}
if(this->BuildFromDataXml() == XDMF_SUCCESS) return(XDMF_SUCCESS);
if(this->Connectivity){
XdmfDataItem *di = NULL;
XdmfXmlNode node;
......
......@@ -164,3 +164,29 @@ XdmfValuesHDF::Write(XdmfArray *anArray, XdmfConstString aHeavyDataSetName){
delete [] hds;
return(XDMF_SUCCESS);
}
XdmfString XdmfValuesHDF::DataItemFromHDF(XdmfConstString H5DataSet){
XdmfHDF H5;
ostrstream StringOutput;
char *Ptr;
static XdmfString ReturnString = NULL;
if(H5.Open(H5DataSet, "r") == XDMF_FAIL){
XdmfErrorMessage("Can't open H5 Dataset " << H5DataSet << " for reading");
return(NULL);
}
StringOutput << "<DataItem NumberType=\"";
StringOutput << XdmfTypeToClassString(H5.GetNumberType());
StringOutput << "\" Precision=\"";
StringOutput << H5.GetElementSize();
StringOutput << "\" Dimensions=\"";
StringOutput << H5.GetShapeAsString();
StringOutput << "\">" << H5DataSet << "</DataItem>";
StringOutput << ends;
if ( ReturnString != NULL ) delete [] ReturnString;
Ptr = StringOutput.str();
ReturnString = new char[strlen(Ptr) + 2 ];
strcpy( ReturnString, Ptr );
return(ReturnString);
}
......@@ -28,20 +28,20 @@
#include "XdmfValues.h"
//! Parent Class for handeling I/O of actual data for an XdmfDataStructure
//! Parent Class for handeling I/O of actual data for an XdmfDataItem
/*!
An HDF XdmfDataStructure Node Looks like :
An HDF XdmfDataItem Node Looks like :
\verbatim
<DataStructure
<DataItem
Rank="2"
Dimensions="2 4"
Precision="4"
DataType="Float"
Format="HDF">
MyData.h5:/AllValuesHDF/ThisArray
</DataStructure>
</DataItem>
\endverbatim
XdmfValuesHDF is used to access the "MyData.h5:/AllValuesHDF/ThisArray" part wheather it's in the
......@@ -61,6 +61,8 @@ public :
XdmfArray *Read(XdmfArray *Array=NULL);
//! Write the Array to the External Representation
XdmfInt32 Write(XdmfArray *Array, XdmfConstString HeavyDataSetName=NULL);
//! Produce Xml for an existing HDF5 Dataset
XdmfString DataItemFromHDF(XdmfConstString H5DataSet);
protected :
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment