Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Xdmf
Xdmf
Commits
5f4fe7f7
Commit
5f4fe7f7
authored
Jun 02, 2014
by
Andrew J. Burns (Cont
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of /data/Repository/Xdmf2
parents
d46a7a62
975536e3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
204 additions
and
123 deletions
+204
-123
XdmfSet.cpp
XdmfSet.cpp
+0
-5
core/XdmfCoreReader.cpp
core/XdmfCoreReader.cpp
+119
-105
core/XdmfHDF5Controller.cpp
core/XdmfHDF5Controller.cpp
+36
-12
tests/Cxx/CMakeLists.txt
tests/Cxx/CMakeLists.txt
+5
-1
tests/Cxx/TestXdmfMultiXPath.cpp
tests/Cxx/TestXdmfMultiXPath.cpp
+44
-0
No files found.
XdmfSet.cpp
View file @
5f4fe7f7
...
...
@@ -87,11 +87,6 @@ XdmfSet::populateItem(const std::map<std::string, std::string> & itemProperties,
if
(
name
!=
itemProperties
.
end
())
{
mName
=
name
->
second
;
}
else
{
XdmfError
::
message
(
XdmfError
::
FATAL
,
"'Name' not found in itemProperties in "
"XdmfSet::populateItem"
);
}
mType
=
XdmfSetType
::
New
(
itemProperties
);
for
(
std
::
vector
<
shared_ptr
<
XdmfItem
>
>::
const_iterator
iter
=
childItems
.
begin
();
...
...
core/XdmfCoreReader.cpp
View file @
5f4fe7f7
...
...
@@ -122,60 +122,8 @@ public:
while
(
currNode
!=
NULL
)
{
if
(
currNode
->
type
==
XML_ELEMENT_NODE
)
{
if
(
xmlStrcmp
(
currNode
->
name
,
(
xmlChar
*
)
"include"
)
==
0
)
{
// Deal with proper reading of XIncludes
xmlChar
*
xpointer
=
NULL
;
xmlChar
*
href
=
NULL
;
xmlAttrPtr
currAttribute
=
currNode
->
properties
;
while
(
currAttribute
!=
NULL
)
{
if
(
xmlStrcmp
(
currAttribute
->
name
,
(
xmlChar
*
)
"xpointer"
)
==
0
)
{
xpointer
=
currAttribute
->
children
->
content
;
}
if
(
xmlStrcmp
(
currAttribute
->
name
,
(
xmlChar
*
)
"href"
)
==
0
)
{
href
=
currAttribute
->
children
->
content
;
}
currAttribute
=
currAttribute
->
next
;
}
xmlXPathContextPtr
context
=
mXPathContext
;
if
(
href
)
{
xmlDocPtr
document
;
xmlChar
*
filePath
=
xmlBuildURI
(
href
,
mDocument
->
URL
);
std
::
map
<
std
::
string
,
xmlDocPtr
>::
const_iterator
iter
=
mDocuments
.
find
((
char
*
)
filePath
);
if
(
iter
==
mDocuments
.
end
())
{
document
=
xmlReadFile
((
char
*
)
filePath
,
NULL
,
0
);
mDocuments
.
insert
(
std
::
make_pair
((
char
*
)
document
->
URL
,
document
));
}
else
{
document
=
iter
->
second
;
}
context
=
xmlXPtrNewContext
(
document
,
NULL
,
NULL
);
}
if
(
xpointer
)
{
xmlXPathObjectPtr
result
=
xmlXPtrEval
(
xpointer
,
context
);
if
(
result
&&
!
xmlXPathNodeSetIsEmpty
(
result
->
nodesetval
))
{
for
(
int
i
=
0
;
i
<
result
->
nodesetval
->
nodeNr
;
++
i
)
{
this
->
readSingleNode
(
result
->
nodesetval
->
nodeTab
[
i
],
myItems
);
}
}
xmlXPathFreeObject
(
result
);
}
if
(
href
)
{
xmlXPathFreeContext
(
context
);
}
}
else
{
// Normal reading
this
->
readSingleNode
(
currNode
,
myItems
);
}
// Normal reading
this
->
readSingleNode
(
currNode
,
myItems
);
}
currNode
=
currNode
->
next
;
}
...
...
@@ -191,68 +139,134 @@ public:
readSingleNode
(
const
xmlNodePtr
currNode
,
std
::
vector
<
shared_ptr
<
XdmfItem
>
>
&
myItems
)
{
// Check to see if the node is already in the XPath Map (seen previously)
std
::
map
<
xmlNodePtr
,
shared_ptr
<
XdmfItem
>
>::
const_iterator
iter
=
mXPathMap
.
find
(
currNode
);
// If it is grab it from the previously stored items
if
(
iter
!=
mXPathMap
.
end
())
{
myItems
.
push_back
(
iter
->
second
);
}
else
{
// Otherwise, generate a new Item from the node
std
::
map
<
std
::
string
,
std
::
string
>
itemProperties
;
xmlNodePtr
childNode
=
currNode
->
children
;
if
(
XdmfArray
::
ItemTag
.
compare
((
char
*
)
currNode
->
name
)
==
0
||
strcmp
(
"DataStructure"
,
(
char
*
)
currNode
->
name
)
==
0
)
{
while
(
childNode
!=
NULL
)
{
if
(
childNode
->
type
==
XML_TEXT_NODE
&&
childNode
->
content
)
{
std
::
string
content
((
char
*
)
childNode
->
content
);
boost
::
algorithm
::
trim
(
content
);
if
(
content
.
size
()
!=
0
)
{
itemProperties
.
insert
(
std
::
make_pair
(
"Content"
,
content
));
itemProperties
.
insert
(
std
::
make_pair
(
"XMLDir"
,
mXMLDir
));
break
;
}
}
childNode
=
childNode
->
next
;
}
}
// Deal with proper resolution of XIncludes
if
(
xmlStrcmp
(
currNode
->
name
,
(
xmlChar
*
)
"include"
)
==
0
)
{
xmlChar
*
xpointer
=
NULL
;
xmlChar
*
href
=
NULL
;
xmlAttrPtr
currAttribute
=
currNode
->
properties
;
while
(
currAttribute
!=
NULL
)
{
itemProperties
.
insert
(
std
::
make_pair
((
char
*
)
currAttribute
->
name
,
(
char
*
)
currAttribute
->
children
->
content
));
if
(
xmlStrcmp
(
currAttribute
->
name
,
(
xmlChar
*
)
"xpointer"
)
==
0
)
{
xpointer
=
currAttribute
->
children
->
content
;
}
if
(
xmlStrcmp
(
currAttribute
->
name
,
(
xmlChar
*
)
"href"
)
==
0
)
{
href
=
currAttribute
->
children
->
content
;
}
currAttribute
=
currAttribute
->
next
;
}
const
std
::
vector
<
shared_ptr
<
XdmfItem
>
>
childItems
=
this
->
read
(
currNode
->
children
);
shared_ptr
<
XdmfItem
>
newItem
=
mItemFactory
->
createItem
((
const
char
*
)
currNode
->
name
,
itemProperties
,
childItems
);
if
(
newItem
==
NULL
)
{
XdmfError
::
message
(
XdmfError
::
FATAL
,
"mItemFactory failed to createItem in "
"XdmfCoreReader::XdmfCoreReaderImpl::readSingleNode"
);
xmlXPathContextPtr
oldContext
=
mXPathContext
;
if
(
href
)
{
xmlDocPtr
document
;
xmlChar
*
filePath
=
xmlBuildURI
(
href
,
mDocument
->
URL
);
std
::
map
<
std
::
string
,
xmlDocPtr
>::
const_iterator
iter
=
mDocuments
.
find
((
char
*
)
filePath
);
if
(
iter
==
mDocuments
.
end
())
{
document
=
xmlReadFile
((
char
*
)
filePath
,
NULL
,
0
);
mDocuments
.
insert
(
std
::
make_pair
((
char
*
)
document
->
URL
,
document
));
}
else
{
document
=
iter
->
second
;
}
mXPathContext
=
xmlXPtrNewContext
(
document
,
NULL
,
NULL
);
}
if
(
xpointer
)
{
xmlXPathObjectPtr
result
=
xmlXPtrEval
(
xpointer
,
mXPathContext
);
if
(
result
&&
!
xmlXPathNodeSetIsEmpty
(
result
->
nodesetval
))
{
for
(
int
i
=
0
;
i
<
result
->
nodesetval
->
nodeNr
;
++
i
)
{
this
->
readSingleNode
(
result
->
nodesetval
->
nodeTab
[
i
],
myItems
);
}
}
else
{
XdmfError
::
message
(
XdmfError
::
FATAL
,
"Invalid xpointer encountered."
);
}
xmlXPathFreeObject
(
result
);
}
if
(
href
)
{
xmlXPathFreeContext
(
mXPathContext
);
}
mXPathContext
=
oldContext
;
}
else
{
if
(
newItem
->
getItemTag
().
compare
((
const
char
*
)
currNode
->
name
)
!=
0
)
{
newItem
->
populateItem
(
itemProperties
,
std
::
vector
<
shared_ptr
<
XdmfItem
>
>
(),
mCoreReader
);
// Check to see if the node is already in the XPath Map (seen previously)
std
::
map
<
xmlNodePtr
,
shared_ptr
<
XdmfItem
>
>::
const_iterator
iter
=
mXPathMap
.
find
(
currNode
);
// If it is grab it from the previously stored items
if
(
iter
!=
mXPathMap
.
end
())
{
myItems
.
push_back
(
iter
->
second
);
}
else
{
newItem
->
populateItem
(
itemProperties
,
childItems
,
mCoreReader
);
// Otherwise, generate a new XdmfItem from the node
std
::
map
<
std
::
string
,
std
::
string
>
itemProperties
;
xmlNodePtr
childNode
=
currNode
->
children
;
if
(
XdmfArray
::
ItemTag
.
compare
((
char
*
)
currNode
->
name
)
==
0
||
strcmp
(
"DataStructure"
,
(
char
*
)
currNode
->
name
)
==
0
)
{
while
(
childNode
!=
NULL
)
{
if
(
childNode
->
type
==
XML_TEXT_NODE
&&
childNode
->
content
)
{
std
::
string
content
((
char
*
)
childNode
->
content
);
boost
::
algorithm
::
trim
(
content
);
if
(
content
.
size
()
!=
0
)
{
itemProperties
.
insert
(
std
::
make_pair
(
"Content"
,
content
));
itemProperties
.
insert
(
std
::
make_pair
(
"XMLDir"
,
mXMLDir
));
break
;
}
}
childNode
=
childNode
->
next
;
}
}
// Pull attributes from node
xmlAttrPtr
currAttribute
=
currNode
->
properties
;
while
(
currAttribute
!=
NULL
)
{
itemProperties
.
insert
(
std
::
make_pair
((
char
*
)
currAttribute
->
name
,
(
char
*
)
currAttribute
->
children
->
content
));
currAttribute
=
currAttribute
->
next
;
}
// Build XdmfItem
const
std
::
vector
<
shared_ptr
<
XdmfItem
>
>
childItems
=
this
->
read
(
currNode
->
children
);
shared_ptr
<
XdmfItem
>
newItem
=
mItemFactory
->
createItem
((
const
char
*
)
currNode
->
name
,
itemProperties
,
childItems
);
if
(
newItem
==
NULL
)
{
XdmfError
::
message
(
XdmfError
::
FATAL
,
"mItemFactory failed to createItem in "
"XdmfCoreReader::XdmfCoreReaderImpl::readSingleNode"
);
}
// Populate built XdmfItem
if
(
newItem
->
getItemTag
().
compare
((
const
char
*
)
currNode
->
name
)
!=
0
)
{
newItem
->
populateItem
(
itemProperties
,
std
::
vector
<
shared_ptr
<
XdmfItem
>
>
(),
mCoreReader
);
}
else
{
newItem
->
populateItem
(
itemProperties
,
childItems
,
mCoreReader
);
}
myItems
.
push_back
(
newItem
);
mXPathMap
.
insert
(
std
::
make_pair
(
currNode
,
newItem
));
}
myItems
.
push_back
(
newItem
);
mXPathMap
.
insert
(
std
::
make_pair
(
currNode
,
newItem
));
}
}
...
...
core/XdmfHDF5Controller.cpp
View file @
5f4fe7f7
...
...
@@ -22,6 +22,7 @@
/*****************************************************************************/
#include <hdf5.h>
#include <numeric>
#include <sstream>
#include "XdmfArray.hpp"
#include "XdmfArrayType.hpp"
...
...
@@ -173,22 +174,45 @@ XdmfHDF5Controller::read(XdmfArray * const array, const int fapl)
mOpenFileUsage
[
mFilePath
]
++
;
}
}
hid_t
dataset
=
H5Dopen
(
hdf5Handle
,
mDataSetPath
.
c_str
(),
H5P_DEFAULT
);
hid_t
dataspace
=
H5Dget_space
(
dataset
);
std
::
vector
<
hsize_t
>
start
(
mStart
.
begin
(),
mStart
.
end
());
std
::
vector
<
hsize_t
>
stride
(
mStride
.
begin
(),
mStride
.
end
());
std
::
vector
<
hsize_t
>
count
(
mDimensions
.
begin
(),
mDimensions
.
end
());
const
hid_t
dataset
=
H5Dopen
(
hdf5Handle
,
mDataSetPath
.
c_str
(),
H5P_DEFAULT
);
const
hid_t
dataspace
=
H5Dget_space
(
dataset
);
const
unsigned
int
dataspaceDims
=
H5Sget_simple_extent_ndims
(
dataspace
);
const
std
::
vector
<
hsize_t
>
count
(
mDimensions
.
begin
(),
mDimensions
.
end
());
status
=
H5Sselect_hyperslab
(
dataspace
,
H5S_SELECT_SET
,
&
start
[
0
],
&
stride
[
0
],
&
count
[
0
],
NULL
);
hssize_t
numVals
=
H5Sget_select_npoints
(
dataspace
);
if
(
dataspaceDims
!=
mDimensions
.
size
())
{
// special case where the number of dimensions of the hdf5 dataset
// does not equal the number of dimensions in the light data
// description - in this case we cannot properly take a hyperslab
// selection, so we assume we are reading the entire dataset and
// check whether that is ok to do
const
int
numberValuesHDF5
=
H5Sget_select_npoints
(
dataspace
);
const
int
numberValuesXdmf
=
std
::
accumulate
(
mDimensions
.
begin
(),
mDimensions
.
end
(),
1
,
std
::
multiplies
<
unsigned
int
>
());
if
(
numberValuesHDF5
!=
numberValuesXdmf
)
{
XdmfError
::
message
(
XdmfError
::
FATAL
,
"Number of dimensions in light data description in "
"Xdmf does not match number of dimensions in hdf5 "
"file."
);
}
}
else
{
const
std
::
vector
<
hsize_t
>
start
(
mStart
.
begin
(),
mStart
.
end
());
const
std
::
vector
<
hsize_t
>
stride
(
mStride
.
begin
(),
mStride
.
end
());
status
=
H5Sselect_hyperslab
(
dataspace
,
H5S_SELECT_SET
,
&
start
[
0
],
&
stride
[
0
],
&
count
[
0
],
NULL
);
}
const
hssize_t
numVals
=
H5Sget_select_npoints
(
dataspace
);
hid_t
memspace
=
H5Screate_simple
(
mDimensions
.
size
(),
&
count
[
0
],
NULL
);
...
...
tests/Cxx/CMakeLists.txt
View file @
5f4fe7f7
...
...
@@ -19,7 +19,8 @@ ADD_TEST_CXX(TestXdmfGraph)
ADD_TEST_CXX
(
TestXdmfGridCollection
)
ADD_TEST_CXX
(
TestXdmfHDF5Hyperslab
)
ADD_TEST_CXX
(
TestXdmfMap
)
ADD_TEST_Cxx
(
TestXdmfMultiOpen
)
ADD_TEST_CXX
(
TestXdmfMultiOpen
)
ADD_TEST_CXX
(
TestXdmfMultiXPath
)
ADD_TEST_CXX
(
TestXdmfReader
)
ADD_TEST_CXX
(
TestXdmfRegularGrid
)
ADD_TEST_CXX
(
TestXdmfRectilinearGrid
)
...
...
@@ -74,6 +75,9 @@ CLEAN_TEST_CXX(TestXdmfMap
CLEAN_TEST_CXX
(
TestXdmfMultiOpen
setfile.h5
attributefile.h5
)
CLEAN_TEST_CXX
(
TestXdmfMultiXPath
nestedOuter.xmf
nestedInner.xmf
)
CLEAN_TEST_CXX
(
TestXdmfReader
TestXdmfReader1.h5
TestXdmfReader1.xmf
...
...
tests/Cxx/TestXdmfMultiXPath.cpp
0 → 100644
View file @
5f4fe7f7
#include <XdmfDomain.hpp>
#include <XdmfInformation.hpp>
#include <XdmfReader.hpp>
#include <iostream>
#include <fstream>
int
main
(
int
ac
,
char
*
av
[])
{
//
// write outer file
//
std
::
ofstream
outerFile
(
"nestedOuter.xmf"
);
outerFile
<<
"<?xml version=
\"
1.0
\"
?><Xdmf Version=
\"
2.1
\"
xmlns:xi=
\"
http://www.w3.org/2001/XInclude
\"
><Domain><xi:include href=
\"
nestedInner.xmf
\"
xpointer=
\"
element(/1/1/2)
\"
/></Domain></Xdmf>"
;
outerFile
.
close
();
//
// write inner file
//
std
::
ofstream
innerFile
(
"nestedInner.xmf"
);
innerFile
<<
"<?xml version=
\"
1.0
\"
?><!DOCTYPE Xdmf SYSTEM
\"
Xdmf.dtd
\"
[]><Xdmf xmlns:xi=
\"
http://www.w3.org/2003/XInclude
\"
Version=
\"
2.1
\"
><Domain><Information Name=
\"
foo
\"
Value=
\"
bar
\"
/><xi:include xpointer=
\"
element(/1/1/1)
\"
/></Domain></Xdmf>"
;
innerFile
.
close
();
shared_ptr
<
XdmfReader
>
reader
=
XdmfReader
::
New
();
shared_ptr
<
XdmfDomain
>
innerDomain
=
shared_dynamic_cast
<
XdmfDomain
>
(
reader
->
read
(
"nestedInner.xmf"
));
assert
(
innerDomain
->
getNumberInformations
()
==
2
);
shared_ptr
<
XdmfInformation
>
information0
=
innerDomain
->
getInformation
(
0
);
shared_ptr
<
XdmfInformation
>
information1
=
innerDomain
->
getInformation
(
1
);
// should be the same since 1 is xpoint to 1
assert
(
information0
==
information1
);
shared_ptr
<
XdmfDomain
>
outerDomain
=
shared_dynamic_cast
<
XdmfDomain
>
(
reader
->
read
(
"nestedOuter.xmf"
));
assert
(
outerDomain
->
getNumberInformations
()
==
1
);
shared_ptr
<
XdmfInformation
>
information
=
outerDomain
->
getInformation
(
0
);
assert
(
information
->
getKey
().
compare
(
"foo"
)
==
0
);
assert
(
information
->
getValue
().
compare
(
"bar"
)
==
0
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment