1 #include "UNV2417_Structure.hxx"
2 #include "UNV_Utilities.hxx"
9 using namespace UNV2417;
12 static int MYDEBUG = 1;
14 static int MYDEBUG = 0;
18 static string _group_labels[] = {"2417", "2429", "2430", "2432", "2435", "2452"};
21 static string _label_dataset = "2429";
23 void UNV2417::Read(std::ifstream& in_stream, TDataSet& theDataSet)
26 EXCEPTION(runtime_error,"ERROR: Input file not good.");
28 std::string olds, news;
31 in_stream >> olds >> news;
33 * a "-1" followed by a number means the beginning of a dataset
34 * stop combing at the end of the file
36 while( ((olds != "-1") || (news == "-1") ) && !in_stream.eof() ){
42 for (int i = 0; i < NBGROUP; i++) {
43 if (news == _group_labels[i]) {
44 ReadGroup(news, in_stream, theDataSet);
52 void UNV2417::ReadGroup(const std::string& myGroupLabel, std::ifstream& in_stream, TDataSet& theDataSet)
55 for(; !in_stream.eof();){
58 // end of dataset is reached
65 in_stream>>aTmp; // miss not necessary values
73 in_stream>>aRec.GroupName;
78 for(int j=0; j < n_nodes; j++){
81 if ((myGroupLabel.compare("2435") == 0) || (myGroupLabel.compare("2452") == 0)) {
87 aNum = aRec.NodeList.size();
88 aRec.NodeList.resize(aNum + 1);
89 aRec.NodeList[aNum] = aElId;
92 aNum = aRec.ElementList.size();
93 aRec.ElementList.resize(aNum + 1);
94 aRec.ElementList[aNum] = aElId;
98 theDataSet.insert(TDataSet::value_type(aId,aRec));
104 void UNV2417::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
106 if(!out_stream.good())
107 EXCEPTION(runtime_error,"ERROR: Output file not good.");
110 * Write beginning of dataset
113 out_stream<<" "<<_label_dataset<<"\n";
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;
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;
132 out_stream<<aRec.GroupName<<std::endl;
135 for (i = 0; i < aNbNodes; i++) {
137 out_stream<<std::endl;
140 out_stream<<std::setw(10)<<7;
141 out_stream<<std::setw(10)<<aRec.NodeList[i];
144 for (i = 0; i < aNbElements; i++) {
146 out_stream<<std::endl;
149 out_stream<<std::setw(10)<<8;
150 out_stream<<std::setw(10)<<aRec.ElementList[i];
153 out_stream<<std::endl;
157 * Write end of dataset