]> SALOME platform Git repositories - modules/smesh.git/blob - src/DriverUNV/UNV2417_Structure.cxx
Salome HOME
4d3eac88eaaee646379efa10d72aaf5a15330940
[modules/smesh.git] / src / DriverUNV / UNV2417_Structure.cxx
1 #include "UNV2417_Structure.hxx"
2 #include "UNV_Utilities.hxx"
3
4 #include <fstream>      
5 #include <iomanip>
6
7 using namespace std;
8 using namespace UNV;
9 using namespace UNV2417;
10
11 #ifdef _DEBUG_
12 static int MYDEBUG = 1;
13 #else
14 static int MYDEBUG = 0;
15 #endif
16
17
18 static string _group_labels[] = {"2417", "2429", "2430", "2432", "2435", "2452"};
19 #define NBGROUP 6
20
21 static string _label_dataset = "2429";
22
23 void UNV2417::Read(std::ifstream& in_stream, TDataSet& theDataSet)
24 {
25   if(!in_stream.good())
26     EXCEPTION(runtime_error,"ERROR: Input file not good.");
27
28   std::string olds, news;
29   
30   while(true){
31     in_stream >> olds >> news;
32     /*
33      * a "-1" followed by a number means the beginning of a dataset
34      * stop combing at the end of the file
35      */
36     while( ((olds != "-1") || (news == "-1") ) && !in_stream.eof() ){     
37       olds = news;
38       in_stream >> news;
39     }
40     if(in_stream.eof())
41       return;
42     for (int i = 0; i < NBGROUP; i++) {
43       if (news == _group_labels[i]) {
44         ReadGroup(news, in_stream, theDataSet);
45       }
46     }
47   }
48 }
49
50
51
52 void UNV2417::ReadGroup(const std::string& myGroupLabel, std::ifstream& in_stream, TDataSet& theDataSet)
53 {
54   TGroupId aId;
55   for(; !in_stream.eof();){
56     in_stream >> aId ;
57     if(aId == -1){
58       // end of dataset is reached
59       break;
60     }
61
62     int n_nodes;
63     TRecord aRec;
64     int aTmp;
65     in_stream>>aTmp; // miss not necessary values
66     in_stream>>aTmp;
67     in_stream>>aTmp;
68     in_stream>>aTmp;
69     in_stream>>aTmp;
70     in_stream>>aTmp;
71     in_stream>>n_nodes;
72
73     in_stream>>aRec.GroupName;
74     
75     int aElType;
76     int aElId;
77     int aNum;
78     for(int j=0; j < n_nodes; j++){
79       in_stream>>aElType;
80       in_stream>>aElId;
81       if ((myGroupLabel.compare("2435") == 0) || (myGroupLabel.compare("2452") == 0)) {
82         in_stream>>aTmp;
83         in_stream>>aTmp;
84       }
85       switch (aElType) {
86       case 7: // Nodes
87         aNum = aRec.NodeList.size();
88         aRec.NodeList.resize(aNum + 1);
89         aRec.NodeList[aNum] = aElId;
90         break;
91       case 8: // Elements
92         aNum = aRec.ElementList.size();
93         aRec.ElementList.resize(aNum + 1);
94         aRec.ElementList[aNum] = aElId;
95         break;
96       }
97     }
98     theDataSet.insert(TDataSet::value_type(aId,aRec));
99   }
100
101 }
102
103
104 void UNV2417::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
105 {
106   if(!out_stream.good())
107     EXCEPTION(runtime_error,"ERROR: Output file not good.");
108   
109   /*
110    * Write beginning of dataset
111    */
112   out_stream<<"    -1\n";
113   out_stream<<"  "<<_label_dataset<<"\n";
114
115   TDataSet::const_iterator anIter = theDataSet.begin();
116   for(; anIter != theDataSet.end(); anIter++){
117     const TGroupId& aLabel = anIter->first;
118     const TRecord& aRec = anIter->second;
119     int aNbNodes = aRec.NodeList.size();
120     int aNbElements = aRec.ElementList.size();
121     int aNbRecords = aNbNodes + aNbElements;
122
123     out_stream<<std::setw(10)<<aLabel;  /* group ID */
124     out_stream<<std::setw(10)<<0;  
125     out_stream<<std::setw(10)<<0;
126     out_stream<<std::setw(10)<<0;
127     out_stream<<std::setw(10)<<0;
128     out_stream<<std::setw(10)<<0;
129     out_stream<<std::setw(10)<<0;
130     out_stream<<std::setw(10)<<aNbRecords<<std::endl; 
131
132     out_stream<<aRec.GroupName<<std::endl;
133     int aRow = 0;
134     int i;
135     for (i = 0; i < aNbNodes; i++) {
136       if (aRow == 4) {
137         out_stream<<std::endl; 
138         aRow = 0;
139       }
140       out_stream<<std::setw(10)<<7;
141       out_stream<<std::setw(10)<<aRec.NodeList[i];
142       aRow++;
143     }
144     for (i = 0; i < aNbElements; i++) {
145       if (aRow == 4) {
146         out_stream<<std::endl; 
147         aRow = 0;
148       }
149       out_stream<<std::setw(10)<<8;
150       out_stream<<std::setw(10)<<aRec.ElementList[i];
151       aRow++;
152     }
153     out_stream<<std::endl; 
154   }
155
156   /*
157    * Write end of dataset
158    */
159   out_stream<<"    -1\n";
160 }