#include "UNV2417_Structure.hxx"
#include "UNV_Utilities.hxx"
+#include <fstream>
+#include <iomanip>
+
using namespace std;
using namespace UNV;
using namespace UNV2417;
#ifdef _DEBUG_
-static int MYDEBUG = 1;
+static int MYDEBUG = 0;
#else
static int MYDEBUG = 0;
#endif
-static string _label_dataset = "2417";
+
+static string _group_labels[] = {"2417", "2429", "2430", "2432", "2435", "2452", "2467"};
+#define NBGROUP 7
+
+static string _label_dataset = "2467";
void UNV2417::Read(std::ifstream& in_stream, TDataSet& theDataSet)
{
if(!in_stream.good())
EXCEPTION(runtime_error,"ERROR: Input file not good.");
- /*
- * adjust the \p istream to our
- * position
- */
- if(!beginning_of_dataset(in_stream,_label_dataset))
- EXCEPTION(runtime_error,"WARNING: Could not find "<<_label_dataset<<" dataset!");
+ std::string olds, news;
+
+ while(true){
+ in_stream >> olds >> news;
+ /*
+ * a "-1" followed by a number means the beginning of a dataset
+ * stop combing at the end of the file
+ */
+ while( ((olds != "-1") || (news == "-1") ) && !in_stream.eof() ){
+ olds = news;
+ in_stream >> news;
+ }
+ if(in_stream.eof())
+ return;
+ for (int i = 0; i < NBGROUP; i++) {
+ if (news == _group_labels[i]) {
+ ReadGroup(news, in_stream, theDataSet);
+ }
+ }
+ }
+}
+
+
+void UNV2417::ReadGroup(const std::string& myGroupLabel, std::ifstream& in_stream, TDataSet& theDataSet)
+{
TGroupId aId;
for(; !in_stream.eof();){
in_stream >> aId ;
in_stream>>aTmp;
in_stream>>aTmp;
in_stream>>aTmp;
+ in_stream>>aTmp;
in_stream>>n_nodes;
+ std::getline(in_stream, aRec.GroupName, '\n'); // Finalise previous reading
+ std::getline(in_stream, aRec.GroupName, '\n');
+
int aElType;
int aElId;
int aNum;
for(int j=0; j < n_nodes; j++){
in_stream>>aElType;
in_stream>>aElId;
+ if ((myGroupLabel.compare("2435") == 0) || (myGroupLabel.compare("2452") == 0) || (myGroupLabel.compare("2467") == 0)) {
+ in_stream>>aTmp;
+ in_stream>>aTmp;
+ }
switch (aElType) {
case 7: // Nodes
aNum = aRec.NodeList.size();
}
}
+
+
+void UNV2417::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
+{
+ if(!out_stream.good())
+ EXCEPTION(runtime_error,"ERROR: Output file not good.");
+
+ /*
+ * Write beginning of dataset
+ */
+ out_stream<<" -1\n";
+ out_stream<<" "<<_label_dataset<<"\n";
+
+ TDataSet::const_iterator anIter = theDataSet.begin();
+ for(; anIter != theDataSet.end(); anIter++){
+ const TGroupId& aLabel = anIter->first;
+ const TRecord& aRec = anIter->second;
+ int aNbNodes = aRec.NodeList.size();
+ int aNbElements = aRec.ElementList.size();
+ int aNbRecords = aNbNodes + aNbElements;
+
+ out_stream<<std::setw(10)<<aLabel; /* group ID */
+ out_stream<<std::setw(10)<<0;
+ out_stream<<std::setw(10)<<0;
+ out_stream<<std::setw(10)<<0;
+ out_stream<<std::setw(10)<<0;
+ out_stream<<std::setw(10)<<0;
+ out_stream<<std::setw(10)<<0;
+ out_stream<<std::setw(10)<<aNbRecords<<std::endl;
+
+ out_stream<<aRec.GroupName<<std::endl;
+ int aRow = 0;
+ int i;
+ for (i = 0; i < aNbNodes; i++) {
+ if (aRow == 2) {
+ out_stream<<std::endl;
+ aRow = 0;
+ }
+ out_stream<<std::setw(10)<<7;
+ out_stream<<std::setw(10)<<aRec.NodeList[i];
+ out_stream<<std::setw(10)<<0;
+ out_stream<<std::setw(10)<<0;
+ aRow++;
+ }
+ for (i = 0; i < aNbElements; i++) {
+ if (aRow == 2) {
+ out_stream<<std::endl;
+ aRow = 0;
+ }
+ out_stream<<std::setw(10)<<8;
+ out_stream<<std::setw(10)<<aRec.ElementList[i];
+ out_stream<<std::setw(10)<<0;
+ out_stream<<std::setw(10)<<0;
+ aRow++;
+ }
+ out_stream<<std::endl;
+ }
+
+ /*
+ * Write end of dataset
+ */
+ out_stream<<" -1\n";
+}