Commit 768a6b7c authored by Thomas Edwards's avatar Thomas Edwards
Browse files

REMerge branch 'WNG' into dtu_develop

parents 90c5ea80 56194900
......@@ -12,6 +12,7 @@ PRIVATE/
CHANGELOG
DataLogger
parameters*
RSYNC
DATA
DATA/*
......
......@@ -8,8 +8,8 @@
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
#ifndef _BUFFER_OBS_file_H
#define _BUFFER_OBS_file_H
#ifndef _BUFFER_OBS_FILE_H
#define _BUFFER_OBS_FILE_H
#include <buffer_obs.hpp>
#include <data_obs.hpp>
......@@ -27,7 +27,7 @@ class buffer_obs_file : public buffer_obs
// Private class variables
//
private:
protected:
// Path to output files
std::string path;
......@@ -37,8 +37,6 @@ std::string format;
std::string filename="";
// File stream
std::fstream file;
// String Parser for data format in file
String_Parser parser;
//
......@@ -47,45 +45,33 @@ String_Parser parser;
public:
//buffer_obs_file(int precision=2);
//buffer_obs_file(int precision,std::string path);
//buffer_obs_file_ascii(int precision=2);
//buffer_obs_file_ascii(int precision,std::string path);
buffer_obs_file(std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file(int precision,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file(std::string& formatstr,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file(const String_Parser& parser,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
//
// Public Methods
//
/** Add to buffer */
public: int put(data_obs* data);
public: virtual int put(data_obs* data)=0;
/** Get last element and delete */
public: int pop(data_obs* data);
public: virtual int pop(data_obs* data)=0;
/** Get last element and delete */
public: data_obs pop();
public: virtual data_obs pop()=0;
//
// Private Methods
//
/** Initialize the buffer */
private: int init();
protected: int init();
/** Open file and create folder */
private: int open(std::string filename);
protected: int open(std::string filename);
/** Write string to file buffer */
private: int check(data_obs* data);
protected: int check(data_obs* data);
};
#endif /* _BUFFER_OBS_file_H */
#endif /* _BUFFER_OBS_FILE_H */
/********************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, July 2019 *
* mors//gfz-potsdam.de *
* *
* This class provides a buffer of observatory data that uses file input and *
* output. It can be used in combination with the SHELL file operator (|). *
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
#ifndef _BUFFER_OBS_FILE_ASCII_H
#define _BUFFER_OBS_FILE_ASCII_H
#include <buffer_obs_file.hpp>
#include <data_obs.hpp>
#include <data_obs_vector.hpp>
#include <data_obs_scalar.hpp>
#include <fstream>
#include <String_Parser.hpp>
class buffer_obs_file_ascii : public buffer_obs_file
{
//
// Private class variables
//
private:
// String Parser for data format in file
String_Parser parser;
//
// Constructors
//
public:
//buffer_obs_file(int precision=2);
//buffer_obs_file(int precision,std::string path);
buffer_obs_file_ascii(std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file_ascii(int precision,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file_ascii(std::string& formatstr,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file_ascii(const String_Parser& parser,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
//
// Public Methods
//
/** Add to buffer */
public: int put(data_obs* data);
/** Get last element and delete */
public: int pop(data_obs* data);
/** Get last element and delete */
public: data_obs pop();
//
// Private Methods
//
};
#endif /* _BUFFER_OBS_FILE_ASCII_H */
/********************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, July 2019 *
* mors//gfz-potsdam.de *
* *
* This class provides a buffer of observatory data that uses file input and *
* output. It can be used in combination with the SHELL file operator (|). *
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
#ifndef _BUFFER_OBS_FILE_BINARY_H
#define _BUFFER_OBS_FILE_BINARY_H
#include <buffer_obs_file.hpp>
#include <data_obs.hpp>
#include <data_obs_vector.hpp>
#include <data_obs_scalar.hpp>
#include <fstream>
class buffer_obs_file_binary : public buffer_obs_file
{
//
// Private class variables
//
private:
bool info_written=false;
//
// Constructors
//
public:
//buffer_obs_file_binary(int precision=2);
//buffer_obs_file_binary(int precision,std::string path);
buffer_obs_file_binary(std::string path="",
std::string file="TEST_%Y%m%d.bin");
//
// Public Methods
//
/** Add to buffer */
public: int put(data_obs* data);
/** Get last element and delete */
public: int pop(data_obs* data);
/** Get last element and delete */
public: data_obs pop();
//
// Private Methods
//
private:
int info(data_obs* data);
};
#endif /* _BUFFER_OBS_FILE_BINARY_H */
......@@ -91,6 +91,8 @@ public: int set_time(data_obs* data);
/** Get the time of the data */
public: int get_time(int* year, int* mon, int* day, int* hour, int* min, int* sec,
long* msec);
/** Get the time as std::vector */
public: int get_time(std::vector<int> &time);
/** Get time as tm */
public: int get_time(struct tm* time) const;
/** Get time as timespec */
......@@ -155,7 +157,7 @@ public: double timediff(data_obs* data) const;
/** Calculate median for odd number of data */
virtual int median_odd(std::vector <data_obs*>* data);
private: virtual int median_odd_time(std::vector <data_obs*>* data);
public: virtual int median_time(std::vector <data_obs*>* data);
private: virtual int median_odd_data(std::vector <data_obs*>* data);
/** Symmetric FIR filter */
......@@ -165,8 +167,6 @@ private: virtual int filter_fir_sym_data(std::vector <data_obs*>* data,
std::vector <double>* win);
private: virtual int filter_fir_sym_supp(std::vector <data_obs*>* data,
std::vector <double>* win);
private: virtual int filter_fir_sym_time(std::vector <data_obs*>* data,
std::vector <double>* win);
/** Calculate median of even number of data */
//public: virtual int median_even(std::vector <data_obs> data);
......
......@@ -30,7 +30,9 @@ class data_obs_vector : public data_obs
/** Standard Construtor */
public:
data_obs_vector(double MD=-99999, int Nsupp=2);
//TODO Maybe there is a better way to initialize MD with the
// standard value in data_obs
data_obs_vector(double MD=99999, int Nsupp=2);
data_obs_vector(int Nsupp);
data_obs_vector(data_obs_vector* data);
......@@ -68,7 +70,6 @@ class data_obs_vector : public data_obs
where mil: milliseconds*/
virtual int parse(std::string* string);
};
#endif /* _DATA_OBS_VECTOR_H */
This diff is collapsed.
......@@ -139,8 +139,12 @@ int String_Parser::string(std::string& string, data_obs* data){
os << buffer;
break;}
case 'D':{
// Get number of characters to write
int len = snprintf(c,1,sel.c_str(),data->get_data(1));
// Get number of characters to write:
// Append 50 characters to avoid problems when
// resulting string is larger for second number.
// TODO Easier solution would be to use static buffer length,
// and give warning in case of short buffer.
int len = snprintf(c,1,sel.c_str(),data->get_data(1)) + 50;
char buffer[len+1]="";
// Check if all data or specified data requested
int N; int i;
......@@ -159,7 +163,8 @@ int String_Parser::string(std::string& string, data_obs* data){
break;}
case 'S':{
// Get number of characters to write
int len = snprintf(c,1,sel.c_str(),data->get_supp(1));
// TODO For added 50, see comment above in treatment of 'D'
int len = snprintf(c,1,sel.c_str(),data->get_supp(1)) + 50;
char buffer[len+1]="";
// Check if all data or specified data requested
int N; int i;
......
......@@ -22,7 +22,6 @@
// Custom C++ Headers
#include <buffer_obs_file.hpp> // Buffer using File I/O
#include <String_Parser.hpp>
/********************************************************************************
*********************************************************************************
......@@ -35,12 +34,7 @@
buffer_obs_file::buffer_obs_file(std::string path,
std::string format) {
std::string formatstr = "%T(%Y %m %d %H %M) %t(%S) %V(%6.2f )";
// Create parser
parser = String_Parser(formatstr);
// Set path
// Set path
this->path = path;
// Set format
......@@ -48,60 +42,6 @@ buffer_obs_file::buffer_obs_file(std::string path,
}
buffer_obs_file::buffer_obs_file(int precision, std::string path,
std::string format) {
std::string formatstr;
// Time format
formatstr = "%T(%Y %m %d %H %M) %t(%S)";
// Data format with specified precision
formatstr += "%V(%"
+ std::to_string(7+precision)
+ "."
+ std::to_string(precision)
+ "f )";
// Create parser
parser = String_Parser(formatstr);
// Set path
this->path = path;
// Set format
this->format = format;
}
buffer_obs_file::buffer_obs_file(std::string& formatstr, std::string path,
std::string format) {
// Create parser
parser = String_Parser(formatstr);
// Set path
this->path = path;
// Set format
this->format = format;
}
buffer_obs_file::buffer_obs_file(const String_Parser& parser, std::string path,
std::string format) {
this->parser = parser;
// Set path
this->path = path;
// Set format
this->format = format;
}
/********************************************************************************
*********************************************************************************
* *
......@@ -110,53 +50,6 @@ buffer_obs_file::buffer_obs_file(const String_Parser& parser, std::string path,
*********************************************************************************
********************************************************************************/
/********************************************************************************
* *
* Add data of type data_obs to the buffer. This is done by converting the *
* data to its string representation and writing to File Output. *
* Take care to name files according to date *
* *
********************************************************************************/
int buffer_obs_file::put(data_obs* data) {
std::string datastr;
// Open new file if necessary
check(data);
// Write data to file
parser.string(datastr,data);
file << datastr << std::endl;
if (file.bad()) {
std::cerr << "Writing to file " << filename
<< " failed!" << std::endl;
}
return(0);
}
/********************************************************************************
* *
* Read data from the buffer. This is done by reading from Standard Input and *
* parsing the string. *
* *
********************************************************************************/
int buffer_obs_file::pop(data_obs* data) {
return(-1);
}
data_obs buffer_obs_file::pop(){
data_obs data;
pop(&data);
return(data);
}
/********************************************************************************
*********************************************************************************
......@@ -203,6 +96,11 @@ int buffer_obs_file::open(std::string filename) {
// Open new file
file.open(filename_full,std::ios::out | std::ios::app);
if (!file.is_open()){
std::cerr << "Opening file failed: "
<< filename_full
<< std::endl;
}
// Set filename
this->filename = filename;
......@@ -227,11 +125,6 @@ int buffer_obs_file::check(data_obs* data){
open(filename);
}
if (file.bad()) {
std::cerr << "Opening file " << filename
<< " failed!" << std::endl;
}
return(0);
return(0);
}
/*******************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, July 2019 *
* mors//gfz-potsdam.de *
* *
* This class provides a buffer of observatory data that uses file input *
* and output. *
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
// 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>
// Custom C++ Headers
#include <buffer_obs_file_ascii.hpp> // Buffer using File I/O
#include <String_Parser.hpp>
/********************************************************************************
*********************************************************************************
* *
* Constructors. *
* *
*********************************************************************************
********************************************************************************/
buffer_obs_file_ascii::buffer_obs_file_ascii(std::string path,
std::string format)
: buffer_obs_file(path, format) {
std::string formatstr = "%T(%Y %m %d %H %M) %t(%S) %V(%6.2f )";
// Create parser
parser = String_Parser(formatstr);
}
buffer_obs_file_ascii::buffer_obs_file_ascii(int precision, std::string path,
std::string format)
: buffer_obs_file(path, format) {
std::string formatstr;
// Time format
formatstr = "%T(%Y %m %d %H %M) %t(%S)";
// Data format with specified precision
formatstr += "%V(%"
+ std::to_string(7+precision)
+ "."
+ std::to_string(precision)
+ "f )";
// Create parser
parser = String_Parser(formatstr);
}
buffer_obs_file_ascii::buffer_obs_file_ascii(std::string& formatstr, std::string path,
std::string format)
: buffer_obs_file(path, format) {
// Create parser
parser = String_Parser(formatstr);
}
buffer_obs_file_ascii::buffer_obs_file_ascii(const String_Parser& parser, std::string path,
std::string format)
: buffer_obs_file(path, format) {
this->parser = parser;
}
/********************************************************************************
*********************************************************************************
* *
* Public Methods. *
* *
*********************************************************************************
********************************************************************************/
/********************************************************************************
* *
* Add data of type data_obs to the buffer. This is done by converting the *
* data to its string representation and writing to File Output. *
* Take care to name files according to date *
* *
********************************************************************************/
int buffer_obs_file_ascii::put(data_obs* data) {
std::string datastr;
// Open new file if necessary
check(data);
// Write data to file
parser.string(datastr,data);
file << datastr << std::endl;
if (file.bad()) {
std::cerr << "Writing to file " << filename
<< " failed!" << std::endl;
}
return(0);
}
/********************************************************************************
* *
* Read data from the buffer. This is done by reading from Standard Input and *
* parsing the string. *
* *
********************************************************************************/
int buffer_obs_file_ascii::pop(data_obs* data) {
return(-1);
}
data_obs buffer_obs_file_ascii::pop(){
data_obs data;
pop(&data);
return(data);
}
/********************************************************************************
*********************************************************************************
* *
* Private Methods. *
* *
*********************************************************************************
********************************************************************************/
/*******************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, July 2019 *
* mors//gfz-potsdam.de *
* *
* This class provides a buffer of observatory data that uses file input *
* and output. *
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
// C++ Headers
#include <iostream> // Standard I/O