]> Creatis software - bbtk.git/blob - packages/std/src/bbstdWriteColumnsString.cxx
#2560 BBTK Feature New Normal - bbstd package : WriteColumnsString
[bbtk.git] / packages / std / src / bbstdWriteColumnsString.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbstdWriteColumnsString.h"
5 #include "bbstdPackage.h"
6 namespace bbstd
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,WriteColumnsString)
10 BBTK_BLACK_BOX_IMPLEMENTATION(WriteColumnsString,bbtk::AtomicBlackBox);
11 //===== 
12 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
13 //===== 
14 void WriteColumnsString::Process()
15 {
16
17         std::cout << "MLER WriteColumnsString::Process Start " << std::endl;
18         
19
20         std::ofstream write_fi;
21         write_fi.open(bbGetInputFileName().c_str());
22         
23         std::vector<std::string> headers = bbGetInputHeaders(); //Headers Input
24
25         std::vector<std::vector<std::string> > values;
26
27         values.push_back(bbGetInputlstData1());
28         values.push_back(bbGetInputlstData2());
29         values.push_back(bbGetInputlstData3());
30         values.push_back(bbGetInputlstData4());
31         values.push_back(bbGetInputlstData5());
32         values.push_back(bbGetInputlstData6());
33         values.push_back(bbGetInputlstData7());
34         values.push_back(bbGetInputlstData8());
35         values.push_back(bbGetInputlstData9());
36
37         std::vector<std::vector<std::string> >::iterator it;
38
39         std::cout << "values size"<<values.size()<< std::endl;
40         for(it = values.begin() ; it != values.end() ; )
41         {
42                 if((*it).empty())
43                 {
44                         it = values.erase(it);
45                 }else
46                 {
47                         it++;
48                 }
49         }
50         std::cout << "values size"<<values.size()<< std::endl;
51         
52         if(write_fi.is_open())
53         {       
54                 //Add each header input write to file
55                 for(unsigned int i=0 ;i< headers.size(); i++ )
56                 {
57                         if(i==(headers.size()-1))
58                         {
59                                 write_fi << headers[i] << "\n";
60                         }else{
61                                 write_fi << headers[i] << "\t";
62                         }
63
64                 }//for headersSize
65
66                 unsigned int colSize = values[0].size();
67
68                 for(unsigned int j=0;j<colSize;j++)
69                 {
70                         for(unsigned int i=0;i<values.size();i++)
71                         {
72                                 if(i==(values.size()-1))
73                                 {
74                                         write_fi << values[i][j] << "\n";
75                                 }else{
76                                         write_fi << values[i][j] << "\t";
77                                 }
78
79                         }
80                         
81                 }
82                 
83                 
84         }// if write_fi.is_open()
85         else
86         {
87                 std::cout<<"No es posible abrir"<<std::endl;
88         }//else
89
90         write_fi.close();
91
92         bbSetOutputOutFileName(bbGetInputFileName().c_str());
93
94         std::cout << "MLER WriteColumnsString::End Process " << std::endl;
95   
96 }
97 //===== 
98 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
99 //===== 
100 void WriteColumnsString::bbUserSetDefaultValues()
101 {
102
103 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
104 //    Here we initialize the input 'In' to 0
105    bbSetInputFileName("");      
106   
107 }
108 //===== 
109 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
110 //===== 
111 void WriteColumnsString::bbUserInitializeProcessing()
112 {
113
114 //  THE INITIALIZATION METHOD BODY :
115 //    Here does nothing 
116 //    but this is where you should allocate the internal/output pointers 
117 //    if any 
118
119   
120 }
121 //===== 
122 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
123 //===== 
124 void WriteColumnsString::bbUserFinalizeProcessing()
125 {
126
127 //  THE FINALIZATION METHOD BODY :
128 //    Here does nothing 
129 //    but this is where you should desallocate the internal/output pointers 
130 //    if any
131   
132 }
133 }
134 // EO namespace bbstd
135
136