1 /*****************************************************************************
2  * Copyright (c) 2019 FrontISTR Commons
3  * This software is released under the MIT License, see LICENSE.txt
4  *****************************************************************************/
5 
6 #ifndef HECMW_UTIL_INCLUDED
7 #define HECMW_UTIL_INCLUDED
8 
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <assert.h>
12 #include <stdarg.h>
13 #include "hecmw_config.h"
14 #include "hecmw_init.h"
15 #include "hecmw_finalize.h"
16 #include "hecmw_malloc.h"
17 #include "hecmw_log.h"
18 #include "hecmw_msg.h"
19 #include "hecmw_lib_fc.h"
20 #include "hecmw_comm.h"
21 #include "hecmw_control.h"
22 #include "hecmw_error.h"
23 #include "hecmw_time.h"
24 
25 #ifndef HECMW_SERIAL
26 #include "mpi.h"
27 #endif
28 
29 #ifdef DEBUG
30 #define HECMW_DEBUG(args) \
31   (HECMW_printerr("DEBUG: "), HECMW_printerr args, HECMW_printerr("\n"))
32 #ifdef HECMW_SERIAL
33 #define HECMW_assert(cond) assert(cond)
34 #else
35 #define HECMW_assert(cond) \
36   HECMW_assert_((cond) ? 1 : 0, #cond, __FILE__, __LINE__)
37 #endif
38 #else
39 #define HECMW_DEBUG(args) ((void)0)
40 #define HECMW_assert(cond) ((void)0)
41 #endif
42 
43 #define HECMW_check_condition(cond, isabort) \
44   HECMW_check_condition_((cond) ? 1 : 0, #cond, isabort, __FILE__, __LINE__);
45 
46 extern void HECMW_fprintf(FILE *fp, char *fmt, ...);
47 
48 extern void HECMW_printerr(char *fmt, ...);
49 
50 extern char *HECMW_get_date(void);
51 
52 extern char *HECMW_get_date_r(char *buf, int len);
53 
54 extern void HECMW_assert_(int cond, char *cond_str, char *file, int line);
55 
56 extern int HECMW_check_condition_(int cond, char *cond_str, int isabort,
57                                   char *file, int line);
58 
59 extern void HECMW_abort(HECMW_Comm comm);
60 
61 extern char *HECMW_toupper(char *s);
62 
63 extern char *HECMW_tolower(char *s);
64 
65 extern void HECMW_print_error(void);
66 
67 extern void HECMW_print_msg(int loglv, int msgno, const char *fmt, ...);
68 
69 extern void HECMW_print_vmsg(int loglv, int msgno, const char *fmt, va_list ap);
70 
71 extern int HECMW_snprintf(char *msg, size_t size, const char *format, ...);
72 
73 extern int HECMW_vsnprintf(char *msg, size_t size, const char *format,
74                            va_list ap);
75 #endif
76