HARM
harm and utilities
 All Data Structures Files Functions Variables Typedefs Macros Pages
mpi_fprintfs.c
Go to the documentation of this file.
1 
8 #include "decs.h"
9 
11 void myfprintf(FILE* fileptr, char *format, ...)
12 {
13  va_list arglist;
14 
15  if (myid==0) {
16  va_start (arglist, format);
17 
18  if(fileptr==NULL){
19  stderrfprintf("tried to print to null file pointer: %s\n",format);
20  fflush(stderr);
21  }
22  else{
23  vfprintf (fileptr, format, arglist);
24  fflush(fileptr);
25  }
26  va_end(arglist);
27  }
28 }
29 
30 #ifdef WIN32
31 #define va_copy(a,b) (a=b)
32 #endif
33 
35 void dualfprintf(FILE* fileptr, char *format, ...)
36 {
37  va_list arglist,arglistcopy;
38 
39 
40  va_start (arglist, format);
41 
42  if(PRODUCTION<=2 && myid==0 || PRODUCTION<=1){
43  if(fileptr==NULL){
44  stderrfprintf("tried to print to null file pointer: %s\n",format);
45  fflush(stderr);
46  }
47  else{
48  va_copy(arglistcopy,arglist);
49  vfprintf (fileptr, format, arglistcopy);
50  fflush(fileptr);
51  va_end(arglistcopy);
52  }
53  }
54  if(myid==0){
55  va_copy(arglistcopy,arglist);
56  vfprintf (stderr, format, arglistcopy);
57  fflush(stderr);
58  va_end(arglistcopy);
59  }
60  va_end(arglist);
61 }
62 
64 void logsfprintf(char *format, ...)
65 {
66  va_list arglist,arglistcopy;
67 
68 
69 
70 
71  va_start (arglist, format);
72 
73  if(PRODUCTION<=2 && myid==0 || PRODUCTION<=1){
74  if(log_file){
75  va_copy(arglistcopy,arglist);
76  vfprintf (log_file, format, arglistcopy);
77  fflush(log_file);
78  va_end(arglistcopy);
79  }
80  }
81  if ((myid==0)&&(logfull_file)){
82  va_copy(arglistcopy,arglist);
83  vfprintf (logfull_file, format, arglistcopy);
84  fflush(logfull_file);
85  va_end(arglistcopy);
86  }
87  va_end(arglist);
88 }
89 
90 
91 
93 void logfprintf(char *format, ...)
94 {
95  va_list arglist,arglistcopy;
96 
97 
98 
99 
100  va_start (arglist, format);
101 
102  if(PRODUCTION<=2 && myid==0 || PRODUCTION<=1){
103  if(log_file){
104  va_copy(arglistcopy,arglist);
105  vfprintf (log_file, format, arglistcopy);
106  fflush(log_file);
107  va_end(arglistcopy);
108  }
109  }
110  va_end(arglist);
111 }
112 
114 void logdtfprintf(char *format, ...)
115 {
116  va_list arglist,arglistcopy;
117 
118 
119  va_start (arglist, format);
120 
121  if(PRODUCTION<=2 && myid==0 || PRODUCTION<=1){
122  if(logdt_file){
123  va_copy(arglistcopy,arglist);
124  vfprintf (logdt_file, format, arglistcopy);
125  fflush(logdt_file);
126  va_end(arglistcopy);
127  }
128  }
129  va_end(arglist);
130 }
131 
133 void stderrfprintf(char *format, ...)
134 {
135  va_list arglist,arglistcopy;
136 
137 
138 
139  va_start (arglist, format);
140 
141  if(PRODUCTION<=2 && myid==0 || PRODUCTION<=1){
142  if(stderr){
143  va_copy(arglistcopy,arglist);
144  vfprintf (stderr, format, arglistcopy);
145  fflush(stderr);
146  va_end(arglistcopy);
147  }
148  }
149  va_end(arglist);
150 }
151 
153 void trifprintf(char *format, ...)
154 {
155  va_list arglist, arglistcopy;
156 
157 
158  va_start (arglist, format);
159 
160  if(PRODUCTION<=2 && myid==0 || PRODUCTION<=1){
161  if(log_file){
162  va_copy(arglistcopy,arglist);
163  vfprintf (log_file, format, arglistcopy);
164  fflush(log_file);
165  va_end(arglistcopy);
166  }
167  }
168  if(myid==0){
169  if(logfull_file){
170  va_copy(arglistcopy,arglist);
171  vfprintf (logfull_file, format, arglistcopy);
172  fflush(logfull_file);
173  va_end(arglistcopy);
174  }
175  va_copy(arglistcopy,arglist);
176  vfprintf (stderr, format, arglistcopy);
177  fflush(stderr);
178  va_end(arglistcopy);
179  }
180  va_end(arglist);
181 }
182 
183 
185 void myfopen(char*fname, char*fmt,char*message,FILE**fileptrptr)
186 {
187  if(myid==0){
188  *fileptrptr = fopen(fname, fmt);
189  if (*fileptrptr == NULL) {
190  dualfprintf(fail_file, message);
191  myexit(10100);
192  }
193  }
194 }
195 
197 void myfclose(FILE ** fileptrptr,char*message)
198 {
199  int reterror;
200 
201  if(myid==0){
202  if(*fileptrptr!=NULL){
203  reterror = fclose(*fileptrptr);
204  if (reterror == EOF) {
205  dualfprintf(fail_file, message);
206  myexit(10101);
207  }
208  }
209  else{
210  dualfprintf(fail_file,"file already closed: %s\n",message);
211  myexit(10102);
212  }
213  }
214 }