Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
iwr
dune-gmsh4
Commits
998e75a6
Commit
998e75a6
authored
Sep 17, 2020
by
Praetorius, Simon
Browse files
add file-version utility
parent
a595e019
Pipeline
#4795
passed with stage
in 12 minutes and 37 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
dune/gmsh4/utility/version.hh
0 → 100644
View file @
998e75a6
#pragma once
#include
<iostream>
#include
<fstream>
#include
<string>
#include
<vector>
#include
<dune/common/exceptions.hh>
#include
"string.hh"
namespace
Dune
{
namespace
Gmsh4
{
/// Return a version tuple identifying the .msh file format version
inline
std
::
vector
<
int
>
fileVersion
(
std
::
string
filename
)
{
std
::
ifstream
file
(
filename
,
std
::
ios_base
::
in
);
std
::
string
section
;
file
>>
section
;
if
(
section
!=
"$MeshFormat"
)
DUNE_THROW
(
Dune
::
IOError
,
"Invalid header of msh file."
);
std
::
string
version
;
int
file_type
=
-
1
;
int
data_size
=
-
1
;
file
>>
version
>>
file_type
>>
data_size
;
if
(
std
::
stod
(
version
)
<=
0.0
)
DUNE_THROW
(
Dune
::
IOError
,
"Invalid version number in msh file."
);
if
(
file_type
!=
0
and
file_type
!=
1
)
DUNE_THROW
(
Dune
::
IOError
,
"Invalid file-type: 0 for ASCII mode, 1 for binary mode."
);
if
(
data_size
<
4
||
data_size
>
16
)
DUNE_THROW
(
Dune
::
IOError
,
"Invalid data-size range: should be in {4, 16}"
);
std
::
vector
<
int
>
version_tuple
;
split
(
version
.
begin
(),
version
.
end
(),
'.'
,
[
&
](
auto
first
,
auto
last
)
{
version_tuple
.
push_back
(
std
::
stoi
(
std
::
string
{
first
,
last
}));
});
return
version_tuple
;
}
}
}
src/gmsh4reader.cc
View file @
998e75a6
...
...
@@ -19,6 +19,7 @@
#include
<dune/gmsh4/gmsh4reader.hh>
#include
<dune/gmsh4/gridcreators/continuousgridcreator.hh>
#include
<dune/gmsh4/gridcreators/discontinuousgridcreator.hh>
#include
<dune/gmsh4/utility/version.hh>
#include
<dune/alugrid/grid.hh>
...
...
@@ -34,6 +35,10 @@ int main(int argc, char** argv)
using
GridType
=
Dune
::
ALUGrid
<
2
,
2
,
Dune
::
simplex
,
Dune
::
conforming
>
;
using
GridView
=
typename
GridType
::
LeafGridView
;
{
auto
ver
=
Gmsh4
::
fileVersion
(
GRID_PATH
"/square.msh"
);
if
(
ver
[
0
]
!=
4
)
DUNE_THROW
(
Dune
::
Exception
,
"Wrong .msh file version"
);
auto
gridPtr
=
Gmsh4Reader
<
GridType
>::
createGridFromFile
(
GRID_PATH
"/square.msh"
);
auto
&
grid
=
*
gridPtr
;
...
...
@@ -50,6 +55,10 @@ int main(int argc, char** argv)
}
{
auto
ver
=
Gmsh4
::
fileVersion
(
GRID_PATH
"/square_part2.msh"
);
if
(
ver
[
0
]
!=
4
)
DUNE_THROW
(
Dune
::
Exception
,
"Wrong .msh file version"
);
auto
gridPtr
=
Gmsh4Reader
<
GridType
>::
createGridFromFile
(
GRID_PATH
"/square_part2.msh"
);
auto
&
grid
=
*
gridPtr
;
...
...
Write
Preview
Supports
Markdown
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