Debian Codegraph @

dune/uggrid/parallel/ddd/basic/io.cc

raw
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LGPL-2.1-or-later
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 /****************************************************************************/
6 /* */
7 /* File: io.c */
8 /* */
9 /* Purpose: routines for I/O used by DDD */
10 /* */
11 /* Author: Klaus Birken */
12 /* */
13 /* History: 92/01/29 PrintErrorMessage by Peter Bastian */
14 /* 95/03/21 kb added PrintString() */
15 /* */
16 /* Remarks: */
17 /* */
18 /****************************************************************************/
19
20 /****************************************************************************/
21 /* */
22 /* include files */
23 /* system include files */
24 /* application include files */
25 /* */
26 /****************************************************************************/
27
28 #include <config.h>
29 #include <cstdio>
30 #include <cstring>
31 #include <cmath>
32
33 #include <dune/uggrid/parallel/ddd/dddcontext.hh>
34
35 #include <dune/uggrid/low/ugtypes.h>
36 #include <dune/uggrid/parallel/ppif/ppif.h>
37 #include <dune/uggrid/parallel/ddd/include/dddio.h>
38 #include <dune/uggrid/parallel/ddd/dddi.h>
39
40 /* PPIF namespace: */
41 using namespace PPIF;
42
43 namespace DDD {
44
45 void (*DDD_UserLineOutFunction)(const char *s);
46
47
48
49 /****************************************************************************/
50 /* */
51 /* definition of static variables */
52 /* */
53 /****************************************************************************/
54
55
56
57
58 /****************************************************************************/
59 /* */
60 /* Function: DDD_PrintLine */
61 /* */
62 /* Purpose: print interface, all output lines will be routed to here */
63 /* */
64 /* Input: char *s: string to be printed */
65 /* */
66 /* Output: none */
67 /* */
68 /****************************************************************************/
69
70 void DDD_PrintLine (const char *s)
71 {
72 /* newline character will be included in s */
73
74 if (DDD_UserLineOutFunction!=NULL)
75 {
76 DDD_UserLineOutFunction(s);
77 }
78 else
79 {
80 printf("%s", s);
81 }
82 }
83
84
85
86 /****************************************************************************/
87 /* */
88 /* Function: DDD_Flush */
89 /* */
90 /* Purpose: flush output device */
91 /* */
92 /* Input: none */
93 /* */
94 /* Output: none */
95 /* */
96 /****************************************************************************/
97
98 void DDD_Flush (void)
99 {
100 fflush(stdout);
101 }
102
103
104
105 /****************************************************************************/
106 /* */
107 /* Function: DDD_SyncAll */
108 /* */
109 /* Purpose: flush output devices and synchronize */
110 /* */
111 /* Input: none */
112 /* */
113 /* Output: none */
114 /* */
115 /****************************************************************************/
116
117 void DDD_SyncAll(const DDD::DDDContext& context)
118 {
119 DDD_Flush();
120 Synchronize(context.ppifContext());
121 }
122
123
124 /****************************************************************************/
125 /* */
126 /* Function: DDD_PrintDebug */
127 /* */
128 /* Purpose: print interface for debug output */
129 /* */
130 /* Input: char *s: string to be printed */
131 /* */
132 /* Output: none */
133 /* */
134 /****************************************************************************/
135
136 void DDD_PrintDebug (const char *s)
137 {
138 /* newline character will be included in s */
139
140 DDD_PrintLine(s);
141
142 DDD_Flush();
143 }
144
145
146 /****************************************************************************/
147 /* */
148 /* Function: DDD_PrintError */
149 /* */
150 /* Purpose: print formatted error message on user screen */
151 /* */
152 /* Input: char class: 'W' Warning, 'E' Error, 'F' Fatal */
153 /* int errno: error number */
154 /* char *text: error message text */
155 /* */
156 /* Output: none */
157 /* */
158 /****************************************************************************/
159
160 void DDD_PrintError (char error_class, int error_no, const char *text)
161 {
162 char buffer[256];
163 const char* classText;
164
165 switch (error_class)
166 {
167 case 'W' :
168 classText = "WARNING";
169 break;
170
171 case 'E' :
172 classText = "ERROR";
173 break;
174
175 case 'F' :
176 classText = "FATAL";
177 break;
178
179 default :
180 classText = "USER";
181 break;
182 }
183 snprintf(buffer,256,"DDD %s %05d: %s\n",classText,error_no,text);
184 DDD_PrintLine(buffer);
185 }
186
187 } /* namespace DDD */