Salome HOME
*** empty log message ***
[modules/multipr.git] / src / MULTIPR / MULTIPR_Profil.cxx
1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
3
4 /**
5  * \file    MULTIPR_Profil.cxx
6  *
7  * \brief   see MULTIPR_Profil.hxx
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  * 
11  * \date    01/2007
12  */
13
14 //*****************************************************************************
15 // Includes section
16 //*****************************************************************************
17
18 #include "MULTIPR_Profil.hxx"
19 #include "MULTIPR_Exceptions.hxx"
20
21 #include <iostream>
22
23 using namespace std;
24
25
26 namespace multipr
27 {
28
29
30 //*****************************************************************************
31 // Class Profil implementation
32 //*****************************************************************************
33
34 Profil::Profil() 
35 {
36     reset(); 
37 }
38
39
40 Profil::~Profil()  
41
42     reset();  
43 }
44
45
46 void Profil::reset() 
47
48     mName[0] = '\0'; 
49     mTable.clear(); 
50 }
51
52
53 void Profil::create(const char* pName)
54 {
55     if (pName == NULL) throw NullArgumentException("", __FILE__, __LINE__);
56     
57     reset();
58     strcpy(mName, pName);
59 }
60
61
62
63 const char* Profil::getName() const
64 {
65     return mName;
66 }
67
68
69 med_int Profil::get(med_int pIndex) const 
70
71     if ((pIndex < 0) || (pIndex >= med_int(mTable.size()))) throw IndexOutOfBoundsException("", __FILE__, __LINE__);
72     
73     return mTable[pIndex]; 
74 }
75
76
77 void Profil::add(med_int pElt) 
78 {
79     mTable.push_back(pElt); 
80 }
81
82
83 void Profil::readMED(med_idt pMEDfile, med_int pIndexProfil)
84 {
85     if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__);
86     if (pIndexProfil < 1) throw IllegalArgumentException("", __FILE__, __LINE__);
87     
88     reset();
89
90     med_int numData;
91     med_err ret = MEDprofilInfo(
92         pMEDfile, 
93         pIndexProfil, 
94         mName, 
95         &numData);
96         
97     if (ret != 0) throw IOException("", __FILE__, __LINE__);
98     
99     med_int* dataTmp = new med_int[numData];
100     
101     ret = MEDprofilLire(
102         pMEDfile, 
103         dataTmp, 
104         mName);
105     
106     if (ret != 0) throw IOException("", __FILE__, __LINE__);
107     
108     for (int itData = 0 ; itData < numData ; itData++)
109     {
110         mTable.push_back(dataTmp[itData]);
111     }
112     
113     delete[] dataTmp;
114 }
115
116
117 void Profil::writeMED(med_idt pMEDfile)
118 {
119     if (pMEDfile == 0) throw IOException("", __FILE__, __LINE__);
120     if (strlen(mName) > MED_TAILLE_NOM) throw IllegalStateException("", __FILE__, __LINE__);
121     if (mTable.size() == 0) throw IllegalStateException("", __FILE__, __LINE__);
122     
123     med_int* dataTmp = new med_int[mTable.size()];
124     for (unsigned itData = 0 ; itData < mTable.size() ; itData++)
125     {
126         dataTmp[itData] = mTable[itData];
127     }
128     
129     med_err ret = MEDprofilEcr(
130         pMEDfile,
131         dataTmp,
132         mTable.size(),
133         mName);
134         
135     if (ret != 0) throw IOException("", __FILE__, __LINE__);
136     
137     delete[] dataTmp;
138 }
139
140
141 ostream& operator<<(ostream& pOs, Profil& pP)
142 {
143     pOs << "Profil:" << endl;
144     pOs << "    Name=|" << pP.mName << "|" << endl;
145     pOs << "    Size=" << pP.mTable.size() << endl;
146     
147     pOs << "    Entities=[";
148     for (unsigned itElt = 0; itElt < pP.mTable.size() ; itElt++)
149     {
150         pOs << pP.mTable[itElt] << " ";
151     }
152     pOs << "]";
153     
154     return pOs;
155 }
156
157
158 } // namespace  multipr
159
160 // EOF