source: PSPA/madxPSPA/src/mad_err.c @ 430

Last change on this file since 430 was 430, checked in by touze, 11 years ago

import madx-5.01.00

File size: 3.4 KB
Line 
1#include <stdarg.h>
2#include "madx.h"
3
4// private globals
5
6static int warn_numb  = 0;           /* Number of warnings */
7static int warn_numbf = 0;           /* Number of warnings from fortran */
8static int errorflag = 0;
9
10// public interface
11
12void
13mad_err_getwarn(int* cwarn, int* fwarn)
14{
15  if (cwarn) *cwarn = warn_numb; 
16  if (fwarn) *fwarn = warn_numbf; 
17}
18
19void
20seterrorflagfort(int* errcode, const char* from, int *lf, const char* descr, int *ld)
21{
22/*Sets error flag - Used to comunicate occurance of an error.
23  Mainly between c and fortran parts
24  This one is called from Fortran
25*/
26  static const int maxlength = 200;
27  char f[200];
28  char d[200];
29  int n = *lf , m = *ld;
30  if (n >= maxlength ) n = maxlength - 1;
31  if (m >= maxlength ) m = maxlength - 1;
32  strncpy(f,from,n);
33  strncpy(d,descr,m);
34  f[n]=0;
35  d[m]=0;
36  seterrorflag(*errcode,f,d);
37}
38
39void
40seterrorflag(int errcode, const char* from, const char* descr)
41{
42/*Sets error flag - Used to comunicate occurance of an error.
43  Mainly between c and fortran parts*/
44  errorflag = errcode;
45  error("seterrorflag","Errorcode: %d   Reported from %s:",errorflag,from);
46  error("seterrorflag","Description: %s",descr);
47}
48
49int
50geterrorflag(void)
51{
52  /*returns errorflag status - used by fortran code to check if error occured*/
53  return errorflag;
54}
55
56void
57clearerrorflag(void)
58{
59  errorflag = 0;
60}
61
62#if 0 // not used...
63char*
64geterrrormessage()
65{
66  return errormessage;
67}
68#endif
69
70void
71warningnew(const char* t1, const char* fmt, ...)
72{
73/*prints warning on the standard error and accepts parameters printout with std C formatting*/
74/*Piotr Skowronski CERN*/
75  va_list         list;
76
77  warn_numb++; /*I think that warnings should be counted even if the user does not want to see them*/
78  fflush(0); /*flushes all the buffers -> so the warning appears in a correct place*/
79
80  if (get_option("warn") == 0)
81  {
82    return;
83  }
84
85  va_start( list, fmt );
86
87  fprintf(stdout,"++++++ warning: %s : ",t1); /*prints first part to the STDERR and +++....*/
88  vfprintf(stdout, fmt, list); /*prints the second part and variables*/
89  fprintf(stdout,"\n"); /*prints end of line*/
90  fflush(stdout); /*flushes STDERR*/
91  va_end(list);
92}
93
94void
95error(const char* t1, const char* fmt, ...)
96{
97/*prints warning on the standard error and accepts parameters printout with std C formatting*/
98/*Piotr Skowronski CERN*/
99  va_list         list;
100
101  warn_numb++; /*I think that warnings should be counted even if the user does not want to see them*/
102  fflush(0); /*flushes all the buffers -> so the warning appears in a correct place*/
103
104  va_start( list, fmt );
105
106  fprintf(stderr,"++++++ Error: %s : ",t1); /*prints first part to the STDERR and +++....*/
107  vfprintf(stderr, fmt, list); /*prints the second part and variables*/
108  fprintf(stderr,"\n"); /*prints end of line*/
109  fflush(stderr); /*flushes STDERR*/
110  va_end(list);
111}
112
113void
114fatal_error(const char* t1, const char* t2)
115  /*prints fatal error message, halts program */
116{
117  fprintf(stderr, "+=+=+= fatal: %s %s\n",t1,t2);
118  if (get_option("no_fatal_stop ")==0) exit(1);
119}
120
121void
122warning(const char* t1, const char* t2)
123{
124  if (get_option("warn")) {
125    printf("++++++ warning: %s %s\n",t1,t2);
126    warn_numb++;
127  }
128}
129
130void
131augmentfwarn(void)
132{
133/*increases counter of the fortran warnings*/
134  warn_numbf++;
135}
136
137void
138put_info(const char* t1, const char* t2)
139{
140  if (get_option("info") && get_option("warn"))
141    printf("++++++ info: %s %s\n",t1,t2);
142}
143
Note: See TracBrowser for help on using the repository browser.