#include "ATOOLS/Org/Data_Writer.H" #include "ATOOLS/Org/Message.H" #include "ATOOLS/Org/MyStrStream.H" #ifdef DEBUG__Data_Writer #include #endif using namespace ATOOLS; Data_Writer::Data_Writer(): Read_Write_Base(0,1) { SetOutFileMode(fom::permanent); } Data_Writer::~Data_Writer() { CloseOutFile(0,true); } Data_Writer::Data_Writer(const std::string &wordsep,const std::string &linesep, const std::string &comment,const std::string &ignore): Read_Write_Base(0,1,wordsep,linesep,comment,ignore) { SetOutFileMode(fom::permanent); } bool Data_Writer::WriteComment(std::string comment, unsigned int tagreference, bool endline,std::string tempfname) { std::string tag; if (tagreference>=Comment().size()) tag=defaultcom; else tag=Comment()[tagreference]; if (tempfname!=nullstring) SetOutputFile(tempfname); if (!OpenOutFile()) return false; if (tag!=nullstring) *OutFile()<0) *OutFile()< comments, unsigned int tagreference, bool endline,std::string tempfname) { for (unsigned int i=0;i bool Data_Writer::WriteToFile(const Write_Type &value,std::string tag, bool endline,std::string tempfname, int precision) { if (tempfname!=nullstring) SetOutputFile(tempfname); if (!OpenOutFile()) return false; const std::ios_base::fmtflags defaultflags=OutFile()->flags(); OutFile()->precision(precision); if (tag!=nullstring) *OutFile()<0) *OutFile()<flags(defaultflags); CloseOutFile(); return true; } template bool Data_Writer::VectorToFile(const std::vector &values, std::string tag, bool endline,std::string tempfname, vtc::code tempvtype,int precision) { if (tempfname!=nullstring) SetOutputFile(tempfname); if (!OpenOutFile()) return false; if (tempvtype==vtc::unknown) tempvtype=VectorType(); switch (tempvtype) { case vtc::horizontal: if (values.size()>0) { WriteToFile(values[0],tag,false,tempfname,precision); if (WordSeparator().size()>0) *OutFile()<(values[i],"",false,tempfname,precision); if (WordSeparator().size()>0) *OutFile()<(values[i],tag,true,tempfname,precision); break; } CloseOutFile(); return true; } template bool Data_Writer::MatrixToFile(const std::vector > &values,std::string tag, bool endline,std::string tempfname, mtc::code tempmtype,int precision) { std::vector > tempvalues; if (tempfname!=nullstring) SetOutputFile(tempfname); if (!OpenOutFile()) return false; if (tempmtype==mtc::unknown) tempmtype=MatrixType(); switch (tempmtype) { case mtc::transposed: for (unsigned int i=0;i(values[i],tag,true,tempfname, vtc::horizontal,precision); } break; case mtc::normal: default: if (values.size()!=0) { for (unsigned int i=0;i(values.size())); } } for (unsigned int j=0;j(tempvalues[i],tag,true,tempfname, vtc::horizontal,precision); } break; } CloseOutFile(); return true; } namespace ATOOLS { template bool Data_Writer::WriteToFile (const int&,std::string,bool,std::string,int); template bool Data_Writer::WriteToFile (const unsigned int&,std::string,bool,std::string,int); template bool Data_Writer::WriteToFile (const long int&,std::string,bool,std::string,int); template bool Data_Writer::WriteToFile (const float&,std::string,bool,std::string,int); template bool Data_Writer::WriteToFile (const double&,std::string,bool,std::string,int); template bool Data_Writer::WriteToFile (const std::string&,std::string,bool,std::string,int); template bool Data_Writer::VectorToFile (const std::vector&,std::string,bool,std::string,vtc::code,int); template bool Data_Writer::VectorToFile (const std::vector&,std::string,bool,std::string,vtc::code,int); template bool Data_Writer::VectorToFile (const std::vector&,std::string,bool,std::string,vtc::code,int); template bool Data_Writer::VectorToFile (const std::vector&,std::string,bool,std::string,vtc::code,int); template bool Data_Writer::VectorToFile (const std::vector&,std::string,bool,std::string,vtc::code,int); template bool Data_Writer::VectorToFile (const std::vector&,std::string,bool,std::string,vtc::code,int); template bool Data_Writer::MatrixToFile (const std::vector >&,std::string,bool, std::string,mtc::code,int); template bool Data_Writer::MatrixToFile (const std::vector >&,std::string,bool, std::string,mtc::code,int); template bool Data_Writer::MatrixToFile (const std::vector >&,std::string,bool, std::string,mtc::code,int); template bool Data_Writer::MatrixToFile (const std::vector >&,std::string,bool, std::string,mtc::code,int); template bool Data_Writer::MatrixToFile (const std::vector >&,std::string,bool, std::string,mtc::code,int); template bool Data_Writer::MatrixToFile (const std::vector >&,std::string,bool, std::string,mtc::code,int); }