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
Achim Morschhauser
GeomagLogger
Commits
a96c0a42
Commit
a96c0a42
authored
Jul 29, 2019
by
Achim Morschhauser
Browse files
buffer_obs_file bugfix
parent
fff3af42
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/buffer_obs_file.hpp
View file @
a96c0a42
...
...
@@ -65,6 +65,8 @@ public: data_obs pop();
/** Initialize the buffer */
private:
int
init
();
/** Open file and create folder */
private:
int
open
(
std
::
string
filename
);
};
...
...
src/buffer_obs_file.cpp
View file @
a96c0a42
...
...
@@ -73,26 +73,10 @@ int buffer_obs_file::put(data_obs* data) {
// Create filename
data
->
get_time
(
&
time
);
strftime
(
filename
,
smax
,
format
.
c_str
(),
&
time
);
filename_full
=
path
+
'/'
+
filename
;
// Check if file is already opened
if
(
this
->
filename
.
compare
(
filename
)){
if
(
file
.
is_open
())
{
file
.
close
();
file
.
open
(
filename_full
,
std
::
ios
::
out
|
std
::
ios
::
app
);
this
->
filename
=
filename
;
}
else
{
// Create directory
int
pos
=
filename_full
.
find
(
'/'
,
1
);
while
(
pos
!=
std
::
string
::
npos
){
mkdir
(
filename_full
.
substr
(
0
,
pos
).
c_str
(),
0777
);
pos
=
filename_full
.
find
(
'/'
,
pos
+
1
);
}
// Open file
file
.
open
(
filename_full
,
std
::
ios
::
out
|
std
::
ios
::
app
);
std
::
cout
<<
"OPENING FILE FIRST TIME"
<<
std
::
endl
;
this
->
filename
=
filename
;
}
open
(
filename
);
}
// Write data to file
...
...
@@ -159,3 +143,38 @@ int buffer_obs_file::init() {
return
(
0
);
}
/********************************************************************************
* *
* Create directories and open file *
* *
********************************************************************************/
int
buffer_obs_file
::
open
(
std
::
string
filename
)
{
std
::
string
filename_full
;
// Create full path
filename_full
=
path
+
'/'
+
filename
;
// Create directory
int
pos
=
filename_full
.
find
(
'/'
,
1
);
while
(
pos
!=
std
::
string
::
npos
){
mkdir
(
filename_full
.
substr
(
0
,
pos
).
c_str
(),
0777
);
pos
=
filename_full
.
find
(
'/'
,
pos
+
1
);
}
// Close old file, if necessary
if
(
file
.
is_open
())
{
file
.
close
();
}
// Open new file
file
.
open
(
filename_full
,
std
::
ios
::
out
|
std
::
ios
::
app
);
std
::
cout
<<
"OPENING FILE FIRST TIME"
<<
std
::
endl
;
// Set filename
this
->
filename
=
filename
;
return
(
0
);
}
\ No newline at end of file
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