Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
solverstack
ScalFMM
Commits
f2ee844e
Commit
f2ee844e
authored
Jul 15, 2015
by
Quentin Khan
Browse files
FFmaGenericLoader: refactored file opening and added details about open errors
parent
6ecb938d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Src/Files/FFmaGenericLoader.hpp
View file @
f2ee844e
...
...
@@ -213,6 +213,22 @@ private:
FReal
*
tmpVal
;
///< Temporary array to read data
/// Count of other data pieces to read in a particle record after the 4 first ones.
unsigned
int
otherDataToRead
;
void
open_file
(
const
std
::
string
filename
,
const
bool
binary
)
{
if
(
binary
)
{
this
->
file
=
new
std
::
fstream
(
filename
.
c_str
(),
std
::
ifstream
::
in
|
std
::
ios
::
binary
);
}
else
{
this
->
file
=
new
std
::
fstream
(
filename
.
c_str
(),
std
::
ifstream
::
in
)
;
}
// test if open
if
(
!
this
->
file
->
is_open
()){
std
::
cerr
<<
"File "
<<
filename
<<
" not opened! Error: "
<<
strerror
(
errno
)
<<
std
::
endl
;
std
::
exit
(
EXIT_FAILURE
);
}
std
::
cout
<<
"Opened file "
<<
filename
<<
std
::
endl
;
}
public:
/**
* This constructor opens a file using the given mode and reads its
...
...
@@ -228,18 +244,7 @@ public:
file
(
nullptr
),
binaryFile
(
binary
),
centerOfBox
(
0.0
,
0.0
,
0.0
),
boxWidth
(
0.0
),
nbParticles
(
0
),
tmpVal
(
nullptr
),
otherDataToRead
(
0
)
{
if
(
binary
)
{
this
->
file
=
new
std
::
fstream
(
filename
.
c_str
(),
std
::
ifstream
::
in
|
std
::
ios
::
binary
);
}
else
{
this
->
file
=
new
std
::
fstream
(
filename
.
c_str
(),
std
::
ifstream
::
in
)
;
}
// test if open
if
(
!
this
->
file
->
is_open
()){
std
::
cerr
<<
"File "
<<
filename
<<
" not opened! "
<<
std
::
endl
;
std
::
exit
(
EXIT_FAILURE
);
}
std
::
cout
<<
"Open file "
<<
filename
<<
std
::
endl
;
this
->
open_file
(
filename
,
binary
);
this
->
readHeader
();
}
...
...
@@ -256,29 +261,20 @@ public:
*/
FFmaGenericLoader
(
const
std
::
string
&
filename
)
:
file
(
nullptr
),
binaryFile
(
false
),
centerOfBox
(
0.0
,
0.0
,
0.0
),
boxWidth
(
0.0
),
nbParticles
(
0
),
tmpVal
(
nullptr
),
otherDataToRead
(
0
)
{
std
::
string
ext
(
".bfma"
);
// open particle file
if
(
filename
.
find
(
ext
)
!=
std
::
string
::
npos
)
{
if
(
filename
.
find
(
".bfma"
)
!=
std
::
string
::
npos
)
{
binaryFile
=
true
;
this
->
file
=
new
std
::
fstream
(
filename
.
c_str
(),
std
::
ifstream
::
in
|
std
::
ios
::
binary
);
}
else
if
(
filename
.
find
(
".fma"
)
!=
std
::
string
::
npos
)
{
this
->
file
=
new
std
::
fstream
(
filename
.
c_str
(),
std
::
ifstream
::
in
)
;
}
else
{
}
else
if
(
filename
.
find
(
".fma"
)
!=
std
::
string
::
npos
)
{
binaryFile
=
false
;
}
else
{
std
::
cout
<<
"FFmaGenericLoader: "
<<
"Only .fma or .bfma input file are allowed. Got "
<<
filename
<<
"."
<<
std
::
endl
;
std
::
exit
(
EXIT_FAILURE
)
;
}
// test if open
if
(
!
this
->
file
->
is_open
()){
std
::
cerr
<<
"File "
<<
filename
<<
" not opened! "
<<
std
::
endl
;
std
::
exit
(
EXIT_FAILURE
);
}
std
::
cout
<<
"Open file "
<<
filename
<<
std
::
endl
;
this
->
open_file
(
filename
,
binaryFile
);
this
->
readHeader
();
}
...
...
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