Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MULTIPR / MULTIPR_Utils.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Partitioning/decimation module for the SALOME v3.2 platform
20 //
21 /**
22  * \file    MULTIPR_Utils.hxx
23  *
24  * \brief   Some useful miscellaneous tools.
25  *
26  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
27  * 
28  * \date    01/2007
29  */
30
31 #ifndef MULTIPR_UTILS_HXX
32 #define MULTIPR_UTILS_HXX
33
34 extern "C"
35 {
36     #include "med.h"
37 }
38
39 #include <string>
40 #include <vector>
41
42
43 namespace multipr
44 {
45
46
47 /**
48  * Removes all the pChar at the end of the string.
49  * \param  pStr  any valid C string ending with the char '\0'.
50  * \param  pChar any char; SPACE by default.
51  * \return the same string where the ending spaces have been removed.
52  */
53 void trim(char* pStr, char pChar=' ');
54
55
56 /**
57  * Returns true iff the given string starts by prefix.
58  * \param  pStr       any valid C string ending with the char '\0'.
59  * \param  pStrPrefix any valid C string ending with the char '\0'.
60  * \return true iff the given string starts by prefix.
61  */
62 bool startsWith(const char* pStr, const char* pStrPrefix);
63
64  
65 /**
66  * Removes the extension (suffix) of a filename.
67  * Example: removeExtension("agregat100grains_12pas.med", ".med") -> "agregat100grains_12pas"
68  * \param  pPilename  any valid C string ending with the char '\0'.
69  * \param  pExtension any valid C string ending with the char '\0'.
70  * \return the filename without extension.
71  */
72 std::string removeExtension(const char* pFilename, const char* pExtension);
73
74
75 /**
76  * Returns the name of the file, excluding the path.
77  * Example: getFilenameWithoutPath("/home/data/agregat100grains_12pas.med") -> "agregat100grains_12pas.med"
78  * \param  pPilename  any valid C string ending with the char '\0'.
79  * \return the name of the file, excluding the path.
80  */
81 std::string getFilenameWithoutPath(const char* pFilename);
82
83
84 /**
85  * Returns the path of the filename (which may be relative or absolute).
86  * Example: getPath("/home/data/agregat100grains_12pas.med") -> "/home/data/"
87  * \param  pPilename  any valid C string ending with the char '\0'.
88  * \return the path of the filename (which may be relative or absolute).
89  */
90 std::string getPath(const char* pFilename);
91
92
93 /**
94  * Copies the given file into a directory.
95  * \param  pFilename  name of any file to be copied.
96  * \param  pDestDir   destination directory.
97  */
98 void copyFile(const char* pFilename, const char* pDestDir);
99  
100  
101 /**
102  * Prints all the elements of a 2D array.
103  * \param  pData   all the data (should contain pNumberOfElements * pDimOfElements values)
104  * \param  pNumElt number of elements to display.
105  * \param  pDimElt Dimension of elements.
106  * \param  pPrefix string to display before each element.
107  */
108 void printArray2D(
109     const med_float* pData, 
110     const int        pNumElt,
111     const int        pDimElt,
112     const char*      pPrefix);
113     
114
115 /**
116  * Converts any float value to a string (remove unecessary 0).
117  * \param  mV any float value.
118  */
119 std::string realToString(med_float mV);
120
121
122 /**
123  * Returns the name of all meshes contained in a sequential MED file.
124  * \param  pMEDfilename name of any valid sequential MED file; must not be NULL.
125  * \return a list of mesh names.
126  * \throw  NullArgumentException if pMEDfilename is NULL.
127  * \throw  IOException if any other error occurs while reading MED file.
128  */
129  std::vector<std::string> getListMeshes(const char* pMEDfilename);
130
131  
132  /**
133   * For each scalar field in a sequential MED file, returns its name and the related number of time stamps.
134   * Do not returns info about vectorial fields (because, currently, decimation can only be performed on scalar fields).
135   * \param  pMEDfilename name of any valid sequential MED file; must not be NULL.
136   * \param  pFields The information on the fields.
137   * \param  pAddNbGaussPoint If set to true, the number of gauss point of each field is added.
138   * \param  pMeshName Mesh name used if pAddNbGaussPoint is true.
139   * \throw  NullArgumentException if pMEDfilename is NULL.
140   * \throw  IOException if any other error occurs while reading MED file.
141   */
142  void   getListScalarFields(const char* pMEDfilename, std::vector<std::pair<std::string, int> >& pFields, bool pAddNbGaussPoint = false, const char *pMeshName = NULL);
143
144 } // namespace MULTIPR
145
146
147 #endif // MULTIPR_UTILS_HXX
148
149 // EOF