]> Creatis software - bbtk.git/blobdiff - packages/std/src/bbstdWriteColumnsString.cxx
#3348 BBTK Feature New Normal - VectorFilterDouble (find nearest point) WriteColumn...
[bbtk.git] / packages / std / src / bbstdWriteColumnsString.cxx
index 229601c7e93e29a9983bcfec98ad9a432603e2de..3c5d8d529fad22996977b50262ce561d00cd0421 100644 (file)
@@ -18,16 +18,19 @@ void WriteColumnsString::Process()
        std::vector<std::string> headers = bbGetInputHeaders(); //Headers Input
        bool onHeaders = bbGetInputOnHeaders();
        std::vector<std::vector<std::string> > values;
-       values.push_back(bbGetInputlstData1());
-       values.push_back(bbGetInputlstData2());
-       values.push_back(bbGetInputlstData3());
-       values.push_back(bbGetInputlstData4());
-       values.push_back(bbGetInputlstData5());
-       values.push_back(bbGetInputlstData6());
-       values.push_back(bbGetInputlstData7());
-       values.push_back(bbGetInputlstData8());
-       values.push_back(bbGetInputlstData9());
+       values.push_back( bbGetInputlstData1() );
+       values.push_back( bbGetInputlstData2() );
+       values.push_back( bbGetInputlstData3() );
+       values.push_back( bbGetInputlstData4() );
+       values.push_back( bbGetInputlstData5() );
+       values.push_back( bbGetInputlstData6() );
+       values.push_back( bbGetInputlstData7() );
+       values.push_back( bbGetInputlstData8() );
+       values.push_back( bbGetInputlstData9() );
        std::vector<std::vector<std::string> >::iterator it;
+
+       
+
        for(it = values.begin() ; it != values.end() ; )
        {
                if((*it).empty())
@@ -36,44 +39,63 @@ void WriteColumnsString::Process()
                }else
                {
                        it++;
-               }
-       }
-       if(write_fi.is_open())
-       {       
-               if(onHeaders == true) // If onHeaders is true, the file is write with Headers.
+               } // if 
+       } // for it
+
+
+       bool ok         = true;
+       int i,size      = values.size();
+       for ( i=0 ; i<size-1 ; i++ )
+       {
+               if ( values[i].size() != values[i+1].size() )
                {
-                       //Add each header input write to file
-                       for(unsigned int i=0 ;i< headers.size(); i++ )
+                       ok=false;
+               } // if
+       } // for
+
+
+       if (ok==true)
+       {
+               if(write_fi.is_open())
+               {       
+                       if(onHeaders == true) // If onHeaders is true, the file is write with Headers.
                        {
-                               if(i==(headers.size()-1))
+                               //Add each header input write to file
+                               for(unsigned int i=0 ;i< headers.size(); i++ )
                                {
-                                       write_fi << headers[i] << "\n";
-                               }else{
-                                       write_fi << headers[i] << "\t";
-                               }
-
-                       }//for headersSize
-               }
-               unsigned int colSize = values[0].size();
-               for(unsigned int j=0;j<colSize;j++)
-               {
-                       for(unsigned int i=0;i<values.size();i++)
+                                       if(i==(headers.size()-1))
+                                       {
+                                               write_fi << headers[i] << "\n";
+                                       }else{
+                                               write_fi << headers[i] << "\t";
+                                       } // if
+                               }//for headersSize
+                       }
+                       unsigned int colSize = values[0].size();
+                       for(unsigned int j=0 ; j<colSize ; j++)
                        {
-                               if(i==(values.size()-1))
+                               for(unsigned int i=0;i<values.size();i++)
                                {
-                                       write_fi << values[i][j] << "\n";
-                               }else{
-                                       write_fi << values[i][j] << "\t";
-                               }
-                       }
-               }
-       }// if write_fi.is_open()
-       else
-       {
-               std::cout<<"No es posible abrir"<<std::endl;
-       }//else
+                                       if(i==(values.size()-1))
+                                       {
+                                               write_fi << values[i][j] << "\n";
+                                       }else{
+                                               write_fi << values[i][j] << "\t";
+                                       } // if
+                               } // for
+                       } // for
+               } else { // if write_fi.is_open()
+                       std::cout<<"EED WriteColumnsString::Process   Imposible to open file."<<std::endl;
+               }//if open
+
+       } else {
+               printf("EED WriteColumnsString::Process   Warning!   The size of the vectors are not equal. \n");
+       }// if ok
+
        write_fi.close();
        bbSetOutputOutFileName(bbGetInputFileName().c_str());  
+
+
 }
 //===== 
 // 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)
@@ -85,7 +107,6 @@ void WriteColumnsString::bbUserSetDefaultValues()
 //    Here we initialize the input 'In' to 0
    bbSetInputFileName("");     
    bbSetInputFileName("true");
-  
 }
 //===== 
 // 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,8 +118,6 @@ void WriteColumnsString::bbUserInitializeProcessing()
 //    Here does nothing 
 //    but this is where you should allocate the internal/output pointers 
 //    if any 
-
-  
 }
 //===== 
 // 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)