Commit fff3af42 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Create folders for buffer_obs_file

parent 873a0ccd
......@@ -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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment