source: trunk/LMDZ.TITAN/libf/muphytitan/csystem.h @ 3026

Last change on this file since 3026 was 1897, checked in by jvatant, 7 years ago

Making Titan's hazy again - part II
+ Major updates of J.Burgalat YAMMS library and optical coupling, including :
++ Added the routines for haze optics inside YAMMS
++ Calling rad. transf. with interactive haze is plugged
in but should stay unactive as long as the microphysics is
in test phase : cf "uncoupl_optic_haze" flag : true for now !
++ Also some sanity checks for negative tendencies and
some others upkeep of YAMMS model
+ Also added a temporary CPP key USE_QTEST in physiq_mod
that enables to have microphysical tendencies separated
from dynamics for debugging and test phases
-- JVO and JB

File size: 10.1 KB
Line 
1/* Copyright Jérémie Burgalat (2010-2015,2017)
2 *
3 * jeremie.burgalat@univ-reims.fr
4 *
5 * This software is a computer program whose purpose is to provide configuration
6 * file and command line arguments parsing features to Fortran programs.
7 *
8 * This software is governed by the CeCILL-B license under French law and
9 * abiding by the rules of distribution of free software.  You can  use,
10 * modify and/ or redistribute the software under the terms of the CeCILL-B
11 * license as circulated by CEA, CNRS and INRIA at the following URL
12 * "http://www.cecill.info".
13 *
14 * As a counterpart to the access to the source code and  rights to copy,
15 * modify and redistribute granted by the license, users are provided only
16 * with a limited warranty  and the software's author,  the holder of the
17 * economic rights,  and the successive licensors  have only  limited
18 * liability.
19 *
20 * In this respect, the user's attention is drawn to the risks associated
21 * with loading,  using,  modifying and/or developing or reproducing the
22 * software by the user in light of its specific status of free software,
23 * that may mean  that it is complicated to manipulate,  and  that  also
24 * therefore means  that it is reserved for developers  and  experienced
25 * professionals having in-depth computer knowledge. Users are therefore
26 * encouraged to load and test the software's suitability as regards their
27 * requirements in conditions enabling the security of their systems and/or
28 * data to be ensured and,  more generally, to use and operate it in the
29 * same conditions as regards security.
30 *
31 * The fact that you are presently reading this means that you have had
32 * knowledge of the CeCILL-B license and that you accept its terms.
33 */
34
35
36
37/* ------------------ WRAPPERS METHODS FOR FORTRAN BINDINGS ------------------ */
38
39/**
40 * Gets the current umask (in decimal system)
41 * @return An int with the current umask set for the current session
42 */
43int c_umask();
44
45/**
46 * Get directory name of input path
47 * @param[in] in A C string with the input path
48 * @return A pointer to a char array with the directory name of @bti{input} path.
49 * @note On error, a NULL pointer is returned.
50 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
51 * (using fsystem::free_c).
52 */
53char * c_dirname(const char *in);
54
55/**
56 * Get base name of input path
57 * @param[in] in A C string with the input path
58 * @return A pointer to a char array with the base name of @bti{input} path.
59 * @note On error, a NULL pointer is returned.
60 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
61 * (using fsystem::free_c).
62 */
63char* c_basename(const char *in);
64
65/**
66 * Get the current working directory.
67 * @return A pointer to a char array with the current workind directory.
68 * @note On error, a NULL pointer is returned.
69 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
70 * (using fsystem::free_c).
71 */
72char* c_getcwd();
73
74
75/**
76 * Get the realpath of input path.
77 * @param[in] input A C string with the input path
78 * @return A pointer to a char array with the realpath of @bti{input} path.
79 * @note On error, a NULL pointer is returned.
80 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
81 * (using fsystem::free_c).
82 */
83char* c_realpath(const char *input);
84
85/**
86 * Get the relative path of two file paths
87 * @details The method computes the relative path of can_fname to can_reldir if
88 * possible.
89 * @param path string with the path to compute in relative representation
90 * @param reldir a directory path from which output should be relative to
91 * @return A pointer to a char array with the relative path.
92 * @note On error, a NULL pointer is returned.
93 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
94 * (using fsystem::free_c).
95 */
96char* c_relpath(const char *path, const char *reldir) ;
97
98/**
99 * Get the corresponding name of the given user id
100 * @param[in] uid An integer with a user id
101 * @return A pointer to a char array with the user name.
102 * @note On error, a NULL pointer is returned.
103 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
104 * (using fsystem::free_c).
105 */
106char* c_uname(int uid);
107
108/**
109 * Get the corresponding name of the given group id
110 * @param[in] gid An integer with a group id
111 * @return A pointer to a char array with the group name.
112 * @note On error, a NULL pointer is returned.
113 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
114 * (using fsystem::free_c).
115 */
116char* c_gname(int gid);
117
118/**
119 * Get last errno from C library
120 * @return An int with last errno saved in C library.
121 */
122int c_get_errno();
123
124/**
125 * Get the error message of the given error id
126 * @param err An integer with the error id
127 * @return A pointer to a char array with the group name.
128 * @note On error, the hard-coded message "Unknown error" is returned.
129 * @warning In any case, the returned pointer must be freed in the Fortran counterpart
130 * (using fsystem::free_c).
131 */
132char* c_strerror(int err);
133
134/**
135 * Creates directories recursively
136 * @note The method is simple stripped copy of mkdir tool source code.
137 * @param[in] path A C string with the path of the directory to create
138 * @param[in] mode A mode_t structure with the permission of the directory
139 * @return An integer with 0 on success, last errno on failure
140 */
141int c_mkdirp(const char *path, mode_t mode); 
142
143/**
144 * Rename a path
145 * @param old A string with the (valid) path to rename
146 * @param new A string with the new name of the path
147 * @return An integer with 0 on success, last errno on failure
148 */
149int c_rename(const char *old, const char *new);
150
151/**
152 * Change path permissions
153 * @param path A string with the path
154 * @param mode A integer with the new permissions to set
155 * @return An integer with 0 on success, last errno on failure
156 */
157int c_chmod(const char *path, mode_t mode);
158
159/**
160 * Change current working directory
161 * @param path A C string with the new path
162 * @return An integer with 0 on success, last errno on failure
163 */
164int c_chdir(const char *path);
165
166/**
167 * Create directory
168 * @param[in] path A C string with the path of the directory to create
169 * @param[in] mode A mode_t structure with the permission of the directory
170 *                 (as well as all the parent directorie created, if any).
171 * @return An integer with 0 on success, last errno on failure
172 */ 
173int c_mkdir(const char *path, mode_t mode);
174
175
176/**
177 * Copy file to another.
178 * @param to A C string with the new filepath
179 * @param from A C string with the filepath to copy
180 * @return An integer with 0 on success, 1 on failure.
181 */
182int c_copy(const char *to, const char *from);
183
184/**
185 * Remove file from filesytem
186 * @note Also works for directory (if empty)
187 * @param path A C string with the filepath to remove
188 * @return An integer with 0 on success, last errno on failure
189 */
190int c_remove(const char *path);
191
192/**
193 * Remove a directory
194 * @param path A C string with the path of the directory to remove.
195 * @return An integer with 0 on success, last errno on failure
196 */
197int c_rmdir(const char *path);
198
199/**
200 * Remove a directory and its contents recursively
201 *
202 * This method mimics 'rm -rf' command.
203 * @param path A C string with the path of the directory to remove.
204 * @return An integer with 0 on success, last errno on failure
205 */
206int c_rmdir_f(const char *path) ;
207
208/**
209 * Get some file informations
210 * @note If the path cannot be "stat", most of the output parameters are set
211 * to -1.
212 * @param[in] p A C string with the path of a file (or directory)
213 * @param[out] pe An int with the permissions of the path
214 * @param[out] nl An int with the inumber of links
215 * @param[out] ty An int with the type of the file :
216 *    - 0 -> file
217 *    - 1 -> link to a file
218 *    - 2 -> directory
219 *    - 3 -> link to a directory
220 *    - 4 -> Other (fifo, socket, block special, char special ...)
221 * @param[out] ui An int with the user id of the path
222 * @param[out] gi An int with the group id of the path
223 * @param[out] si An int with the size of the path
224 * @param[out] a A C string (20 chars wide, including NULL character) with the
225 * last access date
226 * @param[out] m A C string (20 chars wide, including NULL character) with the
227 * last modification date
228 * @param[out] c A C string (20 chars wide, including NULL character) with the
229 * creation date
230 * @return An integer with 0 on success, last errno on failure
231 */
232int c_fstat(const char *p, int *pe, int *nl, int *ty, int *ui, int *gi, 
233            long *si, char a[20], char m[20], char c[20]);
234
235/**
236 * Check if path is accessible
237 * @param[in] path A C string with the path to check
238 * @param[in] perm An integer with the user's permission to check :
239 *   - 0 do not check for permissions
240 *   - 1 check for execute permission
241 *   - 2 check for write permission
242 *   - 4 check for read permission
243 * @return An int with 0 on success, errno on failure
244 */
245int c_access(const char *path, int perm) ;
246
247/**
248 * Create a directory or a file in given path
249 * @param[in] path Path to be created
250 * @param[in] mode Permission of the path
251 * @param[in] astype A boolean with False to create a directory, True to create a file.
252 * @param[in] forced A boolean with True to force creation of intermediate directory
253 * @return 0 on success, -9 on allocation failure, last errno otherwise
254 */
255int c_create(const char* path, mode_t mode, int astype, int forced);
256
257/**
258 * Create a directory or a file in given path
259 * @param[out] rows Number of rows of the current terminal window
260 * @param[out] cols Number of columns of the current terminal window
261 * @return An int with 0 on success, errno on failure. On failure, rows is set
262 * to 80 and cols to 20.
263 */
264int c_termsize(int *rows,int *cols);
265
266/**
267 * Get the current resident set size memory used by the program.
268 */
269size_t c_getCurrentRSS();
270
271/**
272 * Get the peak resident set size memory used by the program.
273 */
274size_t c_getPeakRSS();
275
276/**
277 * Get global memory usage informations.
278 *
279 * Note: The method attempts to read /proc/meminfo. If the file does not exists, all the given output arguments are
280 * set to zero.
281 */
282int c_getSystemMemory(long long int *m_total,long long int *m_available,long long int *m_free);
Note: See TracBrowser for help on using the repository browser.