Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "UNV2417_Structure.hxx"
00024 #include "UNV_Utilities.hxx"
00025
00026 #include <fstream>
00027 #include <iomanip>
00028
00029 using namespace std;
00030 using namespace UNV;
00031 using namespace UNV2417;
00032
00033 static string _group_labels[] = {"2417", "2429", "2430", "2432",
00034 "2435", "2452", "2467", "2477"};
00035 #define NBGROUP 8
00036
00037 static string _label_dataset = "2467";
00038
00039 void UNV2417::Read(std::ifstream& in_stream, TDataSet& theDataSet)
00040 {
00041 if(!in_stream.good())
00042 EXCEPTION(runtime_error,"ERROR: Input file not good.");
00043
00044 std::string olds, news;
00045
00046 while(true){
00047 in_stream >> olds >> news;
00048
00049
00050
00051
00052 while( ((olds != "-1") || (news == "-1") ) && !in_stream.eof() ){
00053 olds = news;
00054 in_stream >> news;
00055 }
00056 if(in_stream.eof())
00057 return;
00058 for (int i = 0; i < NBGROUP; i++) {
00059 if (news == _group_labels[i]) {
00060 ReadGroup(news, in_stream, theDataSet);
00061 }
00062 }
00063 }
00064 }
00065
00066
00067
00068 void UNV2417::ReadGroup(const std::string& myGroupLabel, std::ifstream& in_stream, TDataSet& theDataSet)
00069 {
00070 TGroupId aId;
00071 for(; !in_stream.eof();){
00072 in_stream >> aId ;
00073 if(aId == -1){
00074
00075 break;
00076 }
00077
00078 int n_nodes;
00079 TRecord aRec;
00080 int aTmp;
00081 in_stream>>aTmp;
00082 in_stream>>aTmp;
00083 in_stream>>aTmp;
00084 in_stream>>aTmp;
00085 in_stream>>aTmp;
00086 in_stream>>aTmp;
00087 in_stream>>n_nodes;
00088
00089 std::getline(in_stream, aRec.GroupName, '\n');
00090 std::getline(in_stream, aRec.GroupName, '\n');
00091
00092 int aElType;
00093 int aElId;
00094 int aNum;
00095 for(int j=0; j < n_nodes; j++){
00096 in_stream>>aElType;
00097 in_stream>>aElId;
00098 if ((myGroupLabel.compare("2435") == 0) ||
00099 (myGroupLabel.compare("2452") == 0) ||
00100 (myGroupLabel.compare("2467") == 0) ||
00101 (myGroupLabel.compare("2477") == 0)) {
00102 in_stream>>aTmp;
00103 in_stream>>aTmp;
00104 }
00105 switch (aElType) {
00106 case 7:
00107 aNum = aRec.NodeList.size();
00108 aRec.NodeList.resize(aNum + 1);
00109 aRec.NodeList[aNum] = aElId;
00110 break;
00111 case 8:
00112 aNum = aRec.ElementList.size();
00113 aRec.ElementList.resize(aNum + 1);
00114 aRec.ElementList[aNum] = aElId;
00115 break;
00116 }
00117 }
00118 theDataSet.insert(TDataSet::value_type(aId,aRec));
00119 }
00120
00121 }
00122
00123
00124 void UNV2417::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
00125 {
00126 if(!out_stream.good())
00127 EXCEPTION(runtime_error,"ERROR: Output file not good.");
00128
00129
00130
00131
00132 out_stream<<" -1\n";
00133 out_stream<<" "<<_label_dataset<<"\n";
00134
00135 TDataSet::const_iterator anIter = theDataSet.begin();
00136 for(; anIter != theDataSet.end(); anIter++){
00137 const TGroupId& aLabel = anIter->first;
00138 const TRecord& aRec = anIter->second;
00139 int aNbNodes = aRec.NodeList.size();
00140 int aNbElements = aRec.ElementList.size();
00141 int aNbRecords = aNbNodes + aNbElements;
00142
00143 out_stream<<std::setw(10)<<aLabel;
00144 out_stream<<std::setw(10)<<0;
00145 out_stream<<std::setw(10)<<0;
00146 out_stream<<std::setw(10)<<0;
00147 out_stream<<std::setw(10)<<0;
00148 out_stream<<std::setw(10)<<0;
00149 out_stream<<std::setw(10)<<0;
00150 out_stream<<std::setw(10)<<aNbRecords<<std::endl;
00151
00152 out_stream<<aRec.GroupName<<std::endl;
00153 int aRow = 0;
00154 int i;
00155 for (i = 0; i < aNbNodes; i++) {
00156 if (aRow == 2) {
00157 out_stream<<std::endl;
00158 aRow = 0;
00159 }
00160 out_stream<<std::setw(10)<<7;
00161 out_stream<<std::setw(10)<<aRec.NodeList[i];
00162 out_stream<<std::setw(10)<<0;
00163 out_stream<<std::setw(10)<<0;
00164 aRow++;
00165 }
00166 for (i = 0; i < aNbElements; i++) {
00167 if (aRow == 2) {
00168 out_stream<<std::endl;
00169 aRow = 0;
00170 }
00171 out_stream<<std::setw(10)<<8;
00172 out_stream<<std::setw(10)<<aRec.ElementList[i];
00173 out_stream<<std::setw(10)<<0;
00174 out_stream<<std::setw(10)<<0;
00175 aRow++;
00176 }
00177 out_stream<<std::endl;
00178 }
00179
00180
00181
00182
00183 out_stream<<" -1\n";
00184 }