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