Salome HOME
*** empty log message ***
[modules/smesh.git] / src / DriverUNV / UNV2411_Structure.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19
20 #include <fstream>      
21 #include <stdio.h>      
22
23 #include "UNV2411_Structure.hxx"
24 #include "UNV_Utilities.hxx"
25
26 using namespace std;
27 using namespace UNV;
28 using namespace UNV2411;
29
30 #ifdef _DEBUG_
31 static int MYDEBUG = 1;
32 #else
33 static int MYDEBUG = 0;
34 #endif
35
36 static string _label_dataset = "2411";
37
38 UNV2411::TRecord::TRecord():
39   exp_coord_sys_num(0),
40   disp_coord_sys_num(0),
41   color(0)
42 {}
43
44 void UNV2411::Read(std::ifstream& in_stream, TDataSet& theDataSet)
45 {
46   if(!in_stream.good())
47     EXCEPTION(runtime_error,"ERROR: Input file not good.");
48
49   /*
50    * adjust the \p istream to our
51    * position
52    */
53   if(!beginning_of_dataset(in_stream,_label_dataset))
54     EXCEPTION(runtime_error,"ERROR: Could not find "<<_label_dataset<<" dataset!");
55
56   /**
57    * always 3 coordinates in the UNV file, no matter
58    * which dimensionality libMesh is in
59    */
60   TNodeLab aLabel;
61   std::string num_buf;
62   for(; !in_stream.eof();){
63     in_stream >> aLabel ;
64     if(aLabel == -1){
65       // end of dataset is reached
66       break;
67     }
68
69     TRecord aRec;
70     in_stream>>aRec.exp_coord_sys_num;
71     in_stream>>aRec.disp_coord_sys_num;
72     in_stream>>aRec.color;
73
74     /*
75      * take care of the
76      * floating-point data
77      */
78     for(int d = 0; d < 3; d++){
79       in_stream>>num_buf;
80       aRec.coord[d] = D_to_e(num_buf);
81     }
82
83     theDataSet.insert(TDataSet::value_type(aLabel,aRec));
84   }
85 }
86
87
88 void UNV2411::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
89 {
90   if(!out_stream.good())
91     EXCEPTION(runtime_error,"ERROR: Output file not good.");
92   
93   /*
94    * Write beginning of dataset
95    */
96   out_stream<<"    -1\n";
97   out_stream<<"  "<<_label_dataset<<"\n";
98
99   TDataSet::const_iterator anIter = theDataSet.begin();
100   for(; anIter != theDataSet.end(); anIter++){
101     const TNodeLab& aLabel = anIter->first;
102     const TRecord& aRec = anIter->second;
103     char buf[78];
104     sprintf(buf, "%10d%10d%10d%10d\n", 
105             aLabel,
106             aRec.exp_coord_sys_num,
107             aRec.disp_coord_sys_num,
108             aRec.color);
109     out_stream<<buf;
110
111     // the coordinates
112     sprintf(buf, "%25.16E%25.16E%25.16E\n", 
113             aRec.coord[0],
114             aRec.coord[1],
115             aRec.coord[2]);
116     out_stream<<buf;
117   }
118   
119   
120   /*
121    * Write end of dataset
122    */
123   out_stream<<"    -1\n";
124 }