init
This commit is contained in:
Executable
+57
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// Created by gfuse on 04/06/22.
|
||||
//
|
||||
|
||||
#ifndef P_46_TANGUNT_BUG_OBSTACLE_AVOIDANCE_READ_HPP
|
||||
#define P_46_TANGUNT_BUG_OBSTACLE_AVOIDANCE_READ_HPP
|
||||
#include <vector>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
template<typename T,int N>
|
||||
class DATA_FILE
|
||||
{
|
||||
public:
|
||||
DATA_FILE(std::string path){
|
||||
in_ =fopen(path.c_str(),"r+");
|
||||
assert(in_ && "path is empty in DATA_FILE. Please notice you need to specify the path from project directory like /data/data.txt");
|
||||
/* out_=fopen("/result.txt").c_str(),"w+");
|
||||
assert(out_ && "path is empty in DATA_FILE");
|
||||
chmod((std::string(getenv("HOME"))+"/result.txt").c_str(), ACCESSPERMS);*/
|
||||
};
|
||||
~DATA_FILE(){
|
||||
fclose(in_);
|
||||
// fclose(out_);
|
||||
};
|
||||
bool read(std::array<T,N>& in){
|
||||
double count=0;
|
||||
if(fscanf(in_,"%le",&count)<1)return false;
|
||||
for(int i=0;i<N;++i){
|
||||
T value;
|
||||
fscanf(in_,",%f",&value);
|
||||
in.at(i)=value;
|
||||
}
|
||||
fscanf(in_,"\n");
|
||||
return true;
|
||||
};
|
||||
void write(std::array<T,N>& out){
|
||||
fprintf(out_,"%ld,",count);
|
||||
for(int i=0;i<N;++i)fprintf(out_,"%f,",out[i]);
|
||||
fprintf(out_,"\n");
|
||||
++count;
|
||||
};
|
||||
void write(std::array<T,N>& out,T& error){
|
||||
fprintf(out_,"%ld,",count);
|
||||
for(int i=0;i<N;++i)fprintf(out_,"%f,",out[i]);
|
||||
fprintf(out_,", ,");
|
||||
fprintf(out_,"%f,",error);
|
||||
fprintf(out_,"\n");
|
||||
++count;
|
||||
};
|
||||
|
||||
private:
|
||||
FILE* in_;
|
||||
FILE* out_;
|
||||
size_t count=0;
|
||||
};
|
||||
|
||||
#endif //P_46_TANGUNT_BUG_OBSTACLE_AVOIDANCE_READ_HPP
|
||||
Reference in New Issue
Block a user