Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/med.git] / src / MULTIPR / MULTIPR_Utils.hxx
1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
3
4 /**
5  * \file    MULTIPR_Utils.hxx
6  *
7  * \brief   Some useful miscellaneous tools.
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  * 
11  * \date    01/2007
12  */
13
14 #ifndef MULTIPR_UTILS_HXX
15 #define MULTIPR_UTILS_HXX
16
17 extern "C"
18 {
19     #include "med.h"
20 }
21
22 #include <string>
23 #include <vector>
24
25
26 namespace multipr
27 {
28
29
30 /**
31  * Removes all the pChar at the end of the string.
32  * \param  pStr  any valid C string ending with the char '\0'.
33  * \param  pChar any char; SPACE by default.
34  * \return the same string where the ending spaces have been removed.
35  */
36 void trim(char* pStr, char pChar=' ');
37
38
39 /**
40  * Returns true iff the given string starts by prefix.
41  * \param  pStr       any valid C string ending with the char '\0'.
42  * \param  pStrPrefix any valid C string ending with the char '\0'.
43  * \return true iff the given string starts by prefix.
44  */
45 bool startsWith(const char* pStr, const char* pStrPrefix);
46
47  
48 /**
49  * Removes the extension (suffix) of a filename.
50  * Example: removeExtension("agregat100grains_12pas.med", ".med") -> "agregat100grains_12pas"
51  * \param  pPilename  any valid C string ending with the char '\0'.
52  * \param  pExtension any valid C string ending with the char '\0'.
53  * \return the filename without extension.
54  */
55 std::string removeExtension(const char* pFilename, const char* pExtension);
56
57
58 /**
59  * Returns the name of the file, excluding the path.
60  * Example: getFilenameWithoutPath("/home/data/agregat100grains_12pas.med") -> "agregat100grains_12pas.med"
61  * \param  pPilename  any valid C string ending with the char '\0'.
62  * \return the name of the file, excluding the path.
63  */
64 std::string getFilenameWithoutPath(const char* pFilename);
65
66
67 /**
68  * Returns the path of the filename (which may be relative or absolute).
69  * Example: getPath("/home/data/agregat100grains_12pas.med") -> "/home/data/"
70  * \param  pPilename  any valid C string ending with the char '\0'.
71  * \return the path of the filename (which may be relative or absolute).
72  */
73 std::string getPath(const char* pFilename);
74
75
76 /**
77  * Copies the given file into a directory.
78  * \param  pFilename  name of any file to be copied.
79  * \param  pDestDir   destination directory.
80  */
81 void copyFile(const char* pFilename, const char* pDestDir);
82  
83  
84 /**
85  * Prints all the elements of a 2D array.
86  * \param  pData   all the data (should contain pNumberOfElements * pDimOfElements values)
87  * \param  pNumElt number of elements to display.
88  * \param  pDimElt Dimension of elements.
89  * \param  pPrefix string to display before each element.
90  */
91 void printArray2D(
92     const med_float* pData, 
93     const int        pNumElt,
94     const int        pDimElt,
95     const char*      pPrefix);
96     
97
98 /**
99  * Converts any float value to a string (remove unecessary 0).
100  * \param  mV any float value.
101  */
102 std::string realToString(med_float mV);
103
104
105 /**
106  * Returns the name of all meshes contained in a sequential MED file.
107  * \param  pMEDfilename name of any valid sequential MED file; must not be NULL.
108  * \return a list of mesh names.
109  * \throw  NullArgumentException if pMEDfilename is NULL.
110  * \throw  IOException if any other error occurs while reading MED file.
111  */
112  std::vector<std::string> getListMeshes(const char* pMEDfilename);
113
114  
115  /**
116   * For each scalar field in a sequential MED file, returns its name and the related number of time stamps.
117   * Do not returns info about vectorial fields (because, currently, decimation can only be performed on scalar fields).
118   * \param  pMEDfilename name of any valid sequential MED file; must not be NULL.
119   * \param  pFields The information on the fields.
120   * \param  pAddNbGaussPoint If set to true, the number of gauss point of each field is added.
121   * \param  pMeshName Mesh name used if pAddNbGaussPoint is true.
122   * \throw  NullArgumentException if pMEDfilename is NULL.
123   * \throw  IOException if any other error occurs while reading MED file.
124   */
125  void   getListScalarFields(const char* pMEDfilename, std::vector<std::pair<std::string, int> >& pFields, bool pAddNbGaussPoint = false, const char *pMeshName = NULL);
126
127 } // namespace MULTIPR
128
129
130 #endif // MULTIPR_UTILS_HXX
131
132 // EOF