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
fff3af42
Commit
fff3af42
authored
Jul 29, 2019
by
Achim Morschhauser
Browse files
Create folders for buffer_obs_file
parent
873a0ccd
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/buffer_obs_file.cpp
View file @
fff3af42
...
...
@@ -12,6 +12,10 @@
// C++ Headers
#include
<iostream>
// Standard I/O
#include
<fstream>
#include
<sys/stat.h>
#include
<libgen.h>
#include
<unistd.h>
// for close
// C headers
#include
<time.h>
...
...
@@ -66,33 +70,40 @@ int buffer_obs_file::put(data_obs* data) {
char
filename
[
smax
];
std
::
string
filename_full
;
data
->
string
(
&
datastr
,
precision
);
// Create filename
// Create filename
data
->
get_time
(
&
time
);
strftime
(
filename
,
smax
,
format
.
c_str
(),
&
time
);
filename_full
=
path
+
filename
;
filename_full
=
path
+
'/'
+
filename
;
// Check if file is already opened
if
(
file
.
is_open
(
)){
if
(
this
->
filename
.
compare
(
filename
))
{
if
(
this
->
filename
.
compare
(
filename
)){
if
(
file
.
is_open
(
))
{
file
.
close
();
file
.
open
(
filename_full
,
std
::
ios
::
out
|
std
::
ios
::
app
);
std
::
cerr
<<
"OPEN FILE: "
<<
filename
<<
std
::
endl
;
this
->
filename
=
filename
;
}
else
{
file
<<
datastr
<<
std
::
endl
;
// 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
;
}
}
else
{
// Open file
file
.
open
(
filename_full
,
std
::
ios
::
out
|
std
::
ios
::
app
);
}
// Write data to file
data
->
string
(
&
datastr
,
precision
);
file
<<
datastr
<<
std
::
endl
;
if
(
file
.
bad
())
{
std
::
cerr
<<
"Opening or writing to file "
<<
filename
std
::
cerr
<<
"Opening or writing to file "
<<
filename
_full
<<
" failed!"
<<
std
::
endl
;
}
return
(
0
);
}
...
...
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