]> 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         bool onHeaders = bbGetInputOnHeaders();
25
26
27         std::vector<std::vector<std::string> > values;
28
29         values.push_back(bbGetInputlstData1());
30         values.push_back(bbGetInputlstData2());
31         values.push_back(bbGetInputlstData3());
32         values.push_back(bbGetInputlstData4());
33         values.push_back(bbGetInputlstData5());
34         values.push_back(bbGetInputlstData6());
35         values.push_back(bbGetInputlstData7());
36         values.push_back(bbGetInputlstData8());
37         values.push_back(bbGetInputlstData9());
38
39         std::vector<std::vector<std::string> >::iterator it;
40
41         std::cout << "values size"<<values.size()<< std::endl;
42         for(it = values.begin() ; it != values.end() ; )
43         {
44                 if((*it).empty())
45                 {
46                         it = values.erase(it);
47                 }else
48                 {
49                         it++;
50                 }
51         }
52         std::cout << "values size"<<values.size()<< std::endl;
53         
54         if(write_fi.is_open())
55         {       
56                 if(onHeaders == true) // If onHeaders is true, the file is write with Headers.
57                 {
58                         //Add each header input write to file
59                         for(unsigned int i=0 ;i< headers.size(); i++ )
60                         {
61                                 if(i==(headers.size()-1))
62                                 {
63                                         write_fi << headers[i] << "\n";
64                                 }else{
65                                         write_fi << headers[i] << "\t";
66                                 }
67
68                         }//for headersSize
69                 }
70
71                 unsigned int colSize = values[0].size();
72
73                 for(unsigned int j=0;j<colSize;j++)
74                 {
75                         for(unsigned int i=0;i<values.size();i++)
76                         {
77                                 if(i==(values.size()-1))
78                                 {
79                                         write_fi << values[i][j] << "\n";
80                                 }else{
81                                         write_fi << values[i][j] << "\t";
82                                 }
83
84                         }
85                         
86                 }
87                 
88                 
89         }// if write_fi.is_open()
90         else
91         {
92                 std::cout<<"No es posible abrir"<<std::endl;
93         }//else
94
95         write_fi.close();
96
97         bbSetOutputOutFileName(bbGetInputFileName().c_str());
98
99         std::cout << "MLER WriteColumnsString::End Process " << std::endl;
100   
101 }
102 //===== 
103 // 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)
104 //===== 
105 void WriteColumnsString::bbUserSetDefaultValues()
106 {
107
108 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
109 //    Here we initialize the input 'In' to 0
110    bbSetInputFileName("");      
111    bbSetInputFileName("true");
112   
113 }
114 //===== 
115 // 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)
116 //===== 
117 void WriteColumnsString::bbUserInitializeProcessing()
118 {
119
120 //  THE INITIALIZATION METHOD BODY :
121 //    Here does nothing 
122 //    but this is where you should allocate the internal/output pointers 
123 //    if any 
124
125   
126 }
127 //===== 
128 // 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)
129 //===== 
130 void WriteColumnsString::bbUserFinalizeProcessing()
131 {
132
133 //  THE FINALIZATION METHOD BODY :
134 //    Here does nothing 
135 //    but this is where you should desallocate the internal/output pointers 
136 //    if any
137   
138 }
139 }
140 // EO namespace bbstd
141
142