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

buffer_obs_file bugfix

parent fff3af42
......@@ -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);
};
......
......@@ -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
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