]> Creatis software - bbtk.git/blob - packages/std/src/bbstdReadVectorFromFile.cxx
32e5cde93bf6f51d6da1be089c41a31a944094c9
[bbtk.git] / packages / std / src / bbstdReadVectorFromFile.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 "bbstdReadVectorFromFile.h"
5 #include "bbstdPackage.h"
6 #include  <vector>
7 namespace bbstd
8 {
9
10 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,ReadVectorFromFile)
11 BBTK_BLACK_BOX_IMPLEMENTATION(ReadVectorFromFile,bbtk::AtomicBlackBox);
12 //===== 
13 // 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)
14 //===== 
15 void ReadVectorFromFile::Process()
16 {
17     std::vector< std::vector< double > > Data;
18     std::ifstream openfile( bbGetInputFileName().c_str() );
19     std::string Input;
20     unsigned int LineLength=bbGetInputLineLength();
21     int skip = 0;
22     while ( getline( openfile, Input ) )
23     {
24        std::stringstream Parse;
25        Parse << Input;
26        double Value;
27        std::vector<double> Line;
28        // -------- une ligne sur 10!
29        skip++;
30        if(skip%10 != 0)
31           continue;
32        else
33           skip=1;
34        //--------       
35        while ( Parse >> Value )
36             Line.push_back( Value );
37        if ( Line.size() != LineLength )
38         {
39             std::cout << "Line " << Data.size() + 1 << " expected " <<
40             LineLength << " values, received " << Line.size() << " values, aborting." <<std::endl;
41             Data.clear();
42         }
43        Data.push_back( Line );
44     }
45     openfile.close();
46     
47     bbSetOutputOut(Data);
48     printf("ReadVectorFromFile::Process end \n");       
49         
50 }
51 //===== 
52 // 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)
53 //===== 
54 void ReadVectorFromFile::bbUserSetDefaultValues()
55 {
56
57 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
58 //    Here we initialize the input 'In' to 0
59         bbSetInputFileName("");
60         bbSetInputLineLength(1);          
61 }
62 //===== 
63 // 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)
64 //===== 
65 void ReadVectorFromFile::bbUserInitializeProcessing()
66 {
67
68 //  THE INITIALIZATION METHOD BODY :
69 //    Here does nothing 
70 //    but this is where you should allocate the internal/output pointers 
71 //    if any 
72     //Data = new vector< vector< double > >;
73   
74 }
75 //===== 
76 // 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)
77 //===== 
78 void ReadVectorFromFile::bbUserFinalizeProcessing()
79 {
80
81 //  THE FINALIZATION METHOD BODY :
82 //    Here does nothing 
83 //    but this is where you should desallocate the internal/output pointers 
84 //    if any
85    //delete Data;
86      
87 }
88 }
89 // EO namespace bbstd
90
91