1 #include "UNV2417_Structure.hxx"
2 #include "UNV_Utilities.hxx"
9 using namespace UNV2417;
12 static int MYDEBUG = 0;
14 static int MYDEBUG = 0;
18 static string _group_labels[] = {"2417", "2429", "2430", "2432", "2435", "2452", "2467"};
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 std::getline(in_stream, aRec.GroupName, '\n'); // Finalise previous reading
74 std::getline(in_stream, aRec.GroupName, '\n');
79 for(int j=0; j < n_nodes; j++){
82 if ((myGroupLabel.compare("2435") == 0) || (myGroupLabel.compare("2452") == 0) || (myGroupLabel.compare("2467") == 0)) {
88 aNum = aRec.NodeList.size();
89 aRec.NodeList.resize(aNum + 1);
90 aRec.NodeList[aNum] = aElId;
93 aNum = aRec.ElementList.size();
94 aRec.ElementList.resize(aNum + 1);
95 aRec.ElementList[aNum] = aElId;
99 theDataSet.insert(TDataSet::value_type(aId,aRec));
105 void UNV2417::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
107 if(!out_stream.good())
108 EXCEPTION(runtime_error,"ERROR: Output file not good.");
111 * Write beginning of dataset
114 out_stream<<" "<<_label_dataset<<"\n";
116 TDataSet::const_iterator anIter = theDataSet.begin();
117 for(; anIter != theDataSet.end(); anIter++){
118 const TGroupId& aLabel = anIter->first;
119 const TRecord& aRec = anIter->second;
120 int aNbNodes = aRec.NodeList.size();
121 int aNbElements = aRec.ElementList.size();
122 int aNbRecords = aNbNodes + aNbElements;
124 out_stream<<std::setw(10)<<aLabel; /* group ID */
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)<<0;
131 out_stream<<std::setw(10)<<aNbRecords<<std::endl;
133 out_stream<<aRec.GroupName<<std::endl;
136 for (i = 0; i < aNbNodes; i++) {
138 out_stream<<std::endl;
141 out_stream<<std::setw(10)<<7;
142 out_stream<<std::setw(10)<<aRec.NodeList[i];
145 for (i = 0; i < aNbElements; i++) {
147 out_stream<<std::endl;
150 out_stream<<std::setw(10)<<8;
151 out_stream<<std::setw(10)<<aRec.ElementList[i];
154 out_stream<<std::endl;
158 * Write end of dataset