Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Xdmf
Xdmf
Commits
63a0aff0
Commit
63a0aff0
authored
Jul 20, 2010
by
Kenneth Leiter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: Clean up changes to fix absolute/relative path adjustments.
parent
087b6d38
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
44 additions
and
125 deletions
+44
-125
XdmfReader.cpp
XdmfReader.cpp
+0
-6
XdmfReader.hpp
XdmfReader.hpp
+0
-2
core/XdmfArray.cpp
core/XdmfArray.cpp
+8
-6
core/XdmfCoreReader.cpp
core/XdmfCoreReader.cpp
+3
-7
core/XdmfCoreReader.hpp
core/XdmfCoreReader.hpp
+2
-2
core/XdmfHDF5Controller.cpp
core/XdmfHDF5Controller.cpp
+7
-30
core/XdmfHDF5Controller.hpp
core/XdmfHDF5Controller.hpp
+6
-13
core/XdmfHDF5Writer.cpp
core/XdmfHDF5Writer.cpp
+6
-10
core/XdmfObject.cpp
core/XdmfObject.cpp
+0
-7
core/XdmfObject.hpp
core/XdmfObject.hpp
+0
-7
core/XdmfWriter.cpp
core/XdmfWriter.cpp
+9
-24
core/tests/Cxx/TestXdmfHDF5Controller.cpp
core/tests/Cxx/TestXdmfHDF5Controller.cpp
+3
-10
tests/Cxx/TestXdmfWriter.cpp
tests/Cxx/TestXdmfWriter.cpp
+0
-1
No files found.
XdmfReader.cpp
View file @
63a0aff0
...
...
@@ -14,9 +14,3 @@ XdmfReader::~XdmfReader()
{
std
::
cout
<<
"Deleted XdmfReader "
<<
this
<<
std
::
endl
;
}
boost
::
shared_ptr
<
XdmfItem
>
XdmfReader
::
read
(
const
std
::
string
&
fileName
)
const
{
return
XdmfCoreReader
::
read
(
fileName
);
}
XdmfReader.hpp
View file @
63a0aff0
...
...
@@ -17,8 +17,6 @@ public:
XdmfNewMacro
(
XdmfReader
);
virtual
~
XdmfReader
();
boost
::
shared_ptr
<
XdmfItem
>
read
(
const
std
::
string
&
fileName
)
const
;
protected:
XdmfReader
();
...
...
core/XdmfArray.cpp
View file @
63a0aff0
...
...
@@ -580,19 +580,21 @@ void XdmfArray::populateItem(const std::map<std::string, std::string> & itemProp
size_t
colonLocation
=
contentVal
.
find
(
":"
);
if
(
colonLocation
!=
std
::
string
::
npos
)
{
size_t
fileDir
=
contentVal
.
substr
(
0
,
colonLocation
).
find_last_of
(
"/
\\
"
);
if
(
fileDir
==
std
::
string
::
npos
)
std
::
string
hdf5Path
=
contentVal
.
substr
(
0
,
colonLocation
);
std
::
string
dataSetPath
=
contentVal
.
substr
(
colonLocation
+
1
,
contentVal
.
size
()
-
colonLocation
-
1
);
if
(
hdf5Path
.
compare
(
XdmfObject
::
getRealPath
(
hdf5Path
))
!=
0
)
{
std
::
stringstream
newContentVal
;
newContentVal
<<
xmlDir
->
second
<<
"/"
<<
contentVal
;
contentVal
=
newContentVal
.
str
();
// Dealing with a relative path for hdf5 location
std
::
stringstream
newHDF5Path
;
newHDF5Path
<<
xmlDir
->
second
<<
hdf5Path
;
hdf5Path
=
newHDF5Path
.
str
();
}
mHDF5Controller
=
XdmfHDF5Controller
::
New
(
hdf5Path
,
dataSetPath
,
sizeVal
,
arrayType
);
}
else
{
assert
(
false
);
}
mHDF5Controller
=
XdmfHDF5Controller
::
New
(
contentVal
,
sizeVal
,
arrayType
);
}
else
if
(
format
->
second
.
compare
(
"XML"
)
==
0
)
{
...
...
core/XdmfCoreReader.cpp
View file @
63a0aff0
...
...
@@ -117,15 +117,11 @@ XdmfCoreReader::~XdmfCoreReader()
boost
::
shared_ptr
<
XdmfItem
>
XdmfCoreReader
::
read
(
const
std
::
string
&
filePath
)
const
{
std
::
string
xmlDir
=
""
;
size_t
index
=
filePath
.
find_last_of
(
"/
\\
"
);
std
::
string
xmlDir
=
XdmfObject
::
getRealPath
(
filePath
)
;
size_t
index
=
xmlDir
.
find_last_of
(
"/
\\
"
);
if
(
index
!=
std
::
string
::
npos
)
{
xmlDir
=
filePath
.
substr
(
0
,
index
);
}
else
{
xmlDir
=
XdmfObject
::
getCWD
();
xmlDir
=
xmlDir
.
substr
(
0
,
index
+
1
);
}
const
xmlDocPtr
document
=
xmlReadFile
(
filePath
.
c_str
(),
NULL
,
0
);
...
...
core/XdmfCoreReader.hpp
View file @
63a0aff0
...
...
@@ -23,10 +23,10 @@ public:
/**
* Read an Xdmf file from disk into memory.
*
* @param file
Name
the path on disk to the Xdmf file to read in.
* @param file
Path
the path on disk to the Xdmf file to read in.
* @return an XdmfItem at the root of the Xdmf tree.
*/
virtual
boost
::
shared_ptr
<
XdmfItem
>
read
(
const
std
::
string
&
file
Name
)
const
;
virtual
boost
::
shared_ptr
<
XdmfItem
>
read
(
const
std
::
string
&
file
Path
)
const
;
protected:
...
...
core/XdmfHDF5Controller.cpp
View file @
63a0aff0
...
...
@@ -7,44 +7,21 @@
#include "XdmfArrayType.hpp"
#include "XdmfHDF5Controller.hpp"
XdmfHDF5Controller
::
XdmfHDF5Controller
(
const
std
::
string
&
dataSetPath
,
const
unsigned
int
size
,
const
boost
::
shared_ptr
<
const
XdmfArrayType
>
type
)
:
mSize
(
size
),
mType
(
type
)
XdmfHDF5Controller
::
XdmfHDF5Controller
(
const
std
::
string
&
hdf5FilePath
,
const
std
::
string
&
dataSetPath
,
const
unsigned
int
size
,
const
boost
::
shared_ptr
<
const
XdmfArrayType
>
type
)
:
mDataSetPath
(
dataSetPath
),
mSize
(
size
),
mType
(
type
)
{
size_t
colonLocation
=
dataSetPath
.
find
(
":"
);
if
(
colonLocation
!=
std
::
string
::
npos
)
{
mFilePath
=
dataSetPath
.
substr
(
0
,
colonLocation
);
if
(
colonLocation
+
1
!=
mFilePath
.
size
())
{
mDataSetName
=
dataSetPath
.
substr
(
colonLocation
+
1
,
dataSetPath
.
size
());
}
else
{
assert
(
false
);
}
mFilePath
=
XdmfObject
::
getRealPath
(
mFilePath
);
}
else
{
assert
(
false
);
}
mFilePath
=
XdmfObject
::
getRealPath
(
hdf5FilePath
);
}
XdmfHDF5Controller
::~
XdmfHDF5Controller
()
{
}
std
::
string
XdmfHDF5Controller
::
getDataSetName
()
const
{
return
mDataSetName
;
}
std
::
string
XdmfHDF5Controller
::
getDataSetPath
()
const
{
std
::
stringstream
toReturn
;
toReturn
<<
mFilePath
<<
":"
<<
mDataSetName
;
return
toReturn
.
str
();
return
mDataSetPath
;
}
std
::
string
XdmfHDF5Controller
::
getFilePath
()
const
...
...
@@ -65,7 +42,7 @@ boost::shared_ptr<const XdmfArrayType> XdmfHDF5Controller::getType() const
void
XdmfHDF5Controller
::
read
(
XdmfArray
*
const
array
)
{
hid_t
hdf5Handle
=
H5Fopen
(
mFilePath
.
c_str
(),
H5F_ACC_RDONLY
,
H5P_DEFAULT
);
hid_t
dataset
=
H5Dopen
(
hdf5Handle
,
mDataSet
Name
.
c_str
(),
H5P_DEFAULT
);
hid_t
dataset
=
H5Dopen
(
hdf5Handle
,
mDataSet
Path
.
c_str
(),
H5P_DEFAULT
);
hid_t
dataspace
=
H5Dget_space
(
dataset
);
hssize_t
numVals
=
H5Sget_simple_extent_npoints
(
dataspace
);
hid_t
datatype
=
H5Dget_type
(
dataset
);
...
...
core/XdmfHDF5Controller.hpp
View file @
63a0aff0
...
...
@@ -24,23 +24,16 @@ public:
/**
* Create a new controller for an hdf5 data set on disk.
*/
static
boost
::
shared_ptr
<
XdmfHDF5Controller
>
New
(
const
std
::
string
&
dataSetPath
,
const
unsigned
int
size
,
const
boost
::
shared_ptr
<
const
XdmfArrayType
>
type
)
static
boost
::
shared_ptr
<
XdmfHDF5Controller
>
New
(
const
std
::
string
&
hdf5FilePath
,
const
std
::
string
&
dataSetPath
,
const
unsigned
int
size
,
const
boost
::
shared_ptr
<
const
XdmfArrayType
>
type
)
{
boost
::
shared_ptr
<
XdmfHDF5Controller
>
p
(
new
XdmfHDF5Controller
(
dataSetPath
,
size
,
type
));
boost
::
shared_ptr
<
XdmfHDF5Controller
>
p
(
new
XdmfHDF5Controller
(
hdf5FilePath
,
dataSetPath
,
size
,
type
));
return
p
;
}
/**
* Get the
name
of the data set owned by this controller. For "/home/output.h5:/foo/data" this is "/foo/data"
* Get the
path
of the data set
within the hdf5 file
owned by this controller. For "/home/output.h5:/foo/data" this is "/foo/data"
*
* @return a std::string containing the name of the data set.
*/
std
::
string
getDataSetName
()
const
;
/**
* Get the absolute path to the hdf5 data set on disk owned by this controller. For "/home/output.h5:/foo/data" this is "/home/output.h5:/foo/data"
*
* @return a std::string to the hdf5 data set location on disk.
* @return a std::string containing the path of the data set.
*/
std
::
string
getDataSetPath
()
const
;
...
...
@@ -74,14 +67,14 @@ public:
protected:
XdmfHDF5Controller
(
const
std
::
string
&
dataSetPath
,
const
unsigned
int
size
,
const
boost
::
shared_ptr
<
const
XdmfArrayType
>
type
);
XdmfHDF5Controller
(
const
std
::
string
&
hdf5FilePath
,
const
std
::
string
&
dataSetPath
,
const
unsigned
int
size
,
const
boost
::
shared_ptr
<
const
XdmfArrayType
>
type
);
private:
XdmfHDF5Controller
(
const
XdmfHDF5Controller
&
hdf5Controller
);
// Not implemented.
void
operator
=
(
const
XdmfHDF5Controller
&
hdf5Controller
);
// Not implemented.
std
::
string
mDataSet
Name
;
std
::
string
mDataSet
Path
;
std
::
string
mFilePath
;
unsigned
int
mSize
;
boost
::
shared_ptr
<
const
XdmfArrayType
>
mType
;
...
...
core/XdmfHDF5Writer.cpp
View file @
63a0aff0
...
...
@@ -136,17 +136,17 @@ void XdmfHDF5Writer::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVi
if
(
datatype
!=
-
1
)
{
std
::
string
hdf5FilePath
=
mImpl
->
mFilePath
;
std
::
stringstream
dataSet
Name
;
std
::
stringstream
dataSet
Path
;
if
((
mImpl
->
mMode
==
Overwrite
||
mImpl
->
mMode
==
Append
)
&&
array
.
mHDF5Controller
)
{
// Write to the previous dataset
dataSet
Name
<<
array
.
mHDF5Controller
->
getDataSet
Name
();
dataSet
Path
<<
array
.
mHDF5Controller
->
getDataSet
Path
();
hdf5FilePath
=
array
.
mHDF5Controller
->
getFilePath
();
}
else
{
dataSet
Name
<<
"Data"
<<
mImpl
->
mDataSetId
;
dataSet
Path
<<
"Data"
<<
mImpl
->
mDataSetId
;
}
// Open a hdf5 dataset and write to it on disk.
...
...
@@ -168,7 +168,7 @@ void XdmfHDF5Writer::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVi
{
hdf5Handle
=
H5Fcreate
(
hdf5FilePath
.
c_str
(),
H5F_ACC_TRUNC
,
H5P_DEFAULT
,
H5P_DEFAULT
);
}
hid_t
dataset
=
H5Dopen
(
hdf5Handle
,
dataSet
Name
.
str
().
c_str
(),
H5P_DEFAULT
);
hid_t
dataset
=
H5Dopen
(
hdf5Handle
,
dataSet
Path
.
str
().
c_str
(),
H5P_DEFAULT
);
hid_t
dataspace
=
H5S_ALL
;
hid_t
memspace
=
H5S_ALL
;
...
...
@@ -180,7 +180,7 @@ void XdmfHDF5Writer::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVi
hid_t
property
=
H5Pcreate
(
H5P_DATASET_CREATE
);
hsize_t
chunkSize
=
1024
;
status
=
H5Pset_chunk
(
property
,
1
,
&
chunkSize
);
dataset
=
H5Dcreate
(
hdf5Handle
,
dataSet
Name
.
str
().
c_str
(),
datatype
,
memspace
,
H5P_DEFAULT
,
property
,
H5P_DEFAULT
);
dataset
=
H5Dcreate
(
hdf5Handle
,
dataSet
Path
.
str
().
c_str
(),
datatype
,
memspace
,
H5P_DEFAULT
,
property
,
H5P_DEFAULT
);
status
=
H5Pclose
(
property
);
}
else
...
...
@@ -223,14 +223,10 @@ void XdmfHDF5Writer::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVi
// Restore previous error handler
H5Eset_auto2
(
0
,
old_func
,
old_client_data
);
std
::
stringstream
writtenDataSet
;
writtenDataSet
<<
hdf5FilePath
<<
":"
<<
dataSetName
.
str
();
// Attach a new controller to the array if needed.
if
(
mImpl
->
mMode
==
Default
||
!
array
.
mHDF5Controller
)
{
boost
::
shared_ptr
<
XdmfHDF5Controller
>
newDataSetController
=
XdmfHDF5Controller
::
New
(
writtenDataSet
.
str
(),
array
.
getSize
(),
array
.
getType
());
boost
::
shared_ptr
<
XdmfHDF5Controller
>
newDataSetController
=
XdmfHDF5Controller
::
New
(
hdf5FilePath
,
dataSetPath
.
str
(),
array
.
getSize
(),
array
.
getType
());
array
.
setHDF5Controller
(
newDataSetController
);
mImpl
->
mDataSetId
++
;
}
...
...
core/XdmfObject.cpp
View file @
63a0aff0
...
...
@@ -15,13 +15,6 @@ XdmfObject::~XdmfObject()
{
}
std
::
string
XdmfObject
::
getCWD
()
{
char
buffer
[
256
];
getcwd
(
buffer
,
256
);
return
buffer
;
}
std
::
string
XdmfObject
::
getRealPath
(
const
std
::
string
&
path
)
{
char
realPath
[
PATH_MAX
];
...
...
core/XdmfObject.hpp
View file @
63a0aff0
...
...
@@ -23,13 +23,6 @@ public:
virtual
~
XdmfObject
();
/**
* Gets the current working directory Xdmf is running in. This is useful for reading and writing files containing relative paths to hdf5 datasets.
*
* @return the current working directory.
*/
static
std
::
string
getCWD
();
/**
* Converts a filesystem path to an absolute real path (absolute path with no symlinks)
*
...
...
core/XdmfWriter.cpp
View file @
63a0aff0
...
...
@@ -138,34 +138,19 @@ void XdmfWriter::visit(XdmfArray & array, const boost::shared_ptr<XdmfBaseVisito
if
(
array
.
getHDF5Controller
()
||
array
.
getSize
()
>
mImpl
->
mLightDataLimit
)
{
mImpl
->
mHDF5Writer
->
visit
(
array
,
mImpl
->
mHDF5Writer
);
std
::
string
contentVal
=
array
.
getHDF5Controller
()
->
getDataSetPath
();
if
(
size_t
colonLocation
=
contentVal
.
find
(
":"
)
!=
std
::
string
::
npos
)
std
::
string
hdf5Path
=
array
.
getHDF5Controller
()
->
getFilePath
();
size_t
index
=
hdf5Path
.
find_last_of
(
"/
\\
"
);
if
(
index
!=
std
::
string
::
npos
)
{
if
(
size_t
fileDir
=
contentVal
.
substr
(
0
,
colonLocation
).
find_last_of
(
"/
\\
"
)
!=
std
::
string
::
npos
)
{
// Absolute Path
std
::
string
cwd
=
XdmfObject
::
getCWD
();
if
(
size_t
relPathBegin
=
contentVal
.
find
(
cwd
)
!=
std
::
string
::
npos
)
{
// Substitute Relative Path
xmlTextValues
<<
contentVal
.
substr
(
cwd
.
size
()
+
1
,
contentVal
.
size
()
-
cwd
.
size
());
}
else
{
// Write Absolute Path
xmlTextValues
<<
contentVal
;
}
}
else
std
::
string
hdf5Dir
=
hdf5Path
.
substr
(
0
,
index
+
1
);
if
(
mImpl
->
mXMLFilePath
.
find
(
hdf5Dir
)
==
0
)
{
// Relative Path
xmlTextValues
<<
contentVal
;
hdf5Path
=
hdf5Path
.
substr
(
hdf5Dir
.
size
(),
hdf5Path
.
size
()
-
hdf5Dir
.
size
());
}
}
else
{
assert
(
false
);
}
xmlTextValues
<<
hdf5Path
<<
":"
<<
array
.
getHDF5Controller
()
->
getDataSetPath
();
}
else
{
...
...
core/tests/Cxx/TestXdmfHDF5Controller.cpp
View file @
63a0aff0
...
...
@@ -4,16 +4,9 @@
int
main
(
int
argc
,
char
*
argv
[])
{
boost
::
shared_ptr
<
XdmfHDF5Controller
>
controller
=
XdmfHDF5Controller
::
New
(
"output.h5:/foo/data1"
,
10
,
XdmfArrayType
::
Int8
());
assert
(
controller
->
getDataSetName
().
compare
(
"/foo/data1"
)
==
0
);
std
::
string
realPath
=
XdmfObject
::
getRealPath
(
"output.h5"
);
std
::
stringstream
realDataSetPath
;
realDataSetPath
<<
realPath
<<
":"
<<
"/foo/data1"
;
assert
(
controller
->
getDataSetPath
().
compare
(
realDataSetPath
.
str
())
==
0
);
assert
(
controller
->
getFilePath
().
compare
(
realPath
)
==
0
);
boost
::
shared_ptr
<
XdmfHDF5Controller
>
controller
=
XdmfHDF5Controller
::
New
(
"output.h5"
,
"/foo/data1"
,
10
,
XdmfArrayType
::
Int8
());
assert
(
controller
->
getDataSetPath
().
compare
(
"/foo/data1"
)
==
0
);
assert
(
controller
->
getFilePath
().
compare
(
XdmfObject
::
getRealPath
(
"output.h5"
))
==
0
);
assert
(
controller
->
getSize
()
==
10
);
assert
(
controller
->
getType
()
==
XdmfArrayType
::
Int8
());
return
0
;
...
...
tests/Cxx/TestXdmfWriter.cpp
View file @
63a0aff0
...
...
@@ -9,7 +9,6 @@ int main(int argc, char* argv[])
std
::
string
realPath
=
XdmfObject
::
getRealPath
(
"output.xmf"
);
std
::
cout
<<
realPath
<<
" "
<<
writer
->
getFilePath
()
<<
std
::
endl
;
assert
(
writer
->
getFilePath
().
compare
(
realPath
)
==
0
);
writer
->
setLightDataLimit
(
10
);
assert
(
writer
->
getLightDataLimit
()
==
10
);
...
...
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