19 #include "TextFileOperatorCLP.h" 43 std::cerr <<
"Only one type of operation is allowed!" << std::endl;
53 main (
int argc,
char const* argv[])
59 if ( _InfoArg.isSet() )
61 if ( _TransposeArg.isSet() )
63 if (_FileConnectRowArg.isSet())
65 if (_FileConnectColumnArg.isSet())
67 if ( _FileIndexRowsArg.isSet() )
69 if ( _ExtractSubMatrixArg.isSet() )
71 if ( _ScaleArg.isSet() )
78 std::vector<std::vector<std::string> > input, input2, output;
81 int NumberRows = input.size();
84 int NumberColumns=input[0].size();
85 bool isSameColumn=
true;
86 for (
int i = 1; i < input.size(); i += 1 )
88 if (NumberColumns!=input[i].size())
90 if (NumberColumns<input[i].size())
91 NumberColumns = input[i].size();
93 for (
int i = 0; i < input.size(); i += 1 )
95 int numberPush=NumberColumns-input[i].size();
96 for (
int j = 0; j < numberPush; j += 1 )
97 input[i].push_back(
" ");
102 if (_OutputfileArg.isSet())
104 out.open ( _Outputfile.c_str() );
105 utlException (!out,
"ERROR : failed to open output file " << _Outputfile);
112 std::cout <<
"File information" << std::endl << std::flush;
113 std::cout <<
"Row: " << NumberRows <<
", Column: " << NumberColumns << std::endl << std::flush;
115 std::cout <<
"all rows have the same number of columns" << std::endl << std::flush;
117 std::cout <<
"not all rows have the same number of columns" << std::endl << std::flush;
122 std::cout <<
"File transpose" << std::endl << std::flush;
124 for (
int i = 0; i < NumberColumns; i += 1 )
126 int NumberColumns = input[i].size();
127 for (
int j = 0; j < NumberRows-1; j += 1 )
128 out << input[j][i] <<
" ";
129 out << input[NumberRows-1][i] <<
"\n";
135 std::cout <<
"Connect columns" << std::endl << std::flush;
138 for (
int i = 0; i < input.size(); i += 1 )
140 std::vector<std::string> element1 = input[i];
143 std::vector<std::string> element2 = input2[i];
144 for (
int j = 0; j < element2.size(); j += 1 )
145 element1.push_back(element2[j]);
154 std::cout <<
"Connect rows" << std::endl << std::flush;
163 std::cout <<
"select rows" << std::endl << std::flush;
165 std::vector<int> index;
173 std::cout <<
"Extract sub-matrix" << std::endl << std::flush;
174 _ExtractSubMatrix[0] =
utl::max(_ExtractSubMatrix[0], 0);
175 _ExtractSubMatrix[1] =
utl::min(_ExtractSubMatrix[1], NumberRows-1);
176 _ExtractSubMatrix[2] =
utl::max(_ExtractSubMatrix[2], 0);
177 _ExtractSubMatrix[3] =
utl::min(_ExtractSubMatrix[3], NumberColumns-1);
180 for (
int i = _ExtractSubMatrix[0]; i <= _ExtractSubMatrix[1]; i += 1 )
182 std::vector<std::string> tmp;
183 for (
int j = _ExtractSubMatrix[2]; j <= _ExtractSubMatrix[3]; j += 1 )
184 tmp.push_back(input[i][j]);
185 output.push_back(tmp);
193 for (
int i = 0; i < NumberRows; i += 1 )
195 std::vector<std::string> tmp;
196 for (
int j = 0; j < NumberColumns; j += 1 )
198 std::string strTemp = input[i][j];
201 double floatTemp = utl::ConvertStringToNumber<double>(strTemp);
205 tmp.push_back(strTemp);
207 output.push_back(tmp);
217 if (_OutputfileArg.isSet())
219 std::cout <<
"save to " << _Outputfile << std::endl << std::flush;
void SetOperationWithChecking(int &operation, int value)
bool IsNumber(const std::string &input)
std::string ConvertNumberToString(const T value, const int precision=6)
#define utlException(cond, expout)
const T & max(const T &a, const T &b)
Return the maximum between a and b.
void Save2DVector(const Vector2D &vv, std::ostream &out=std::cout)
const T & min(const T &a, const T &b)
Return the minimum between a and b.
int main(int argc, char const *argv[])
operators for text file
void ReadVector(const std::string &vectorStr, std::vector< T > &vec, const char *cc=" ")
std::vector< T > SelectVector(const std::vector< T > &vec, const std::vector< int > &index)
void ReadLines(const std::string &filename, std::vector< std::vector< std::string > > &strVec, const char *cc=" ")