LAL  7.5.0.1-fe68b98
VectorFactoriesTest.c
Go to the documentation of this file.
1 /**
2  * \file
3  * \ingroup AVFactories_h
4  *
5  * \brief A program to test create/destroy vector routines.
6  *
7  * ### Usage ###
8  *
9  * \code
10  * VectorFactoriesTest [options]
11  * Options:
12  * -h print help
13  * -q quiet: run silently
14  * -v verbose: print extra information
15  * -d level set lalDebugLevel to level
16  * \endcode
17  *
18  * ### Description ###
19  *
20  *
21  * ### Exit codes ###
22  *
23  * <table><tr><th>Code</th><th>Explanation</th></tr>
24  * <tr><td>0</td><td>Success, normal exit.</td></tr>
25  * <tr><td>1</td><td>Subroutine failed.</td></tr>
26  * </table>
27  *
28  * ### Algorithm ###
29  *
30  *
31  * ### Uses ###
32  *
33  * \code
34  * lalDebugLevel
35  * <datatype>CreateVector()
36  * <datatype>ResizeVector()
37  * <datatype>DestroyVector()
38  * \endcode
39  *
40  * ### Notes ###
41  *
42  */
43 /** \cond DONT_DOXYGEN */
44 #include <config.h>
45 
46 #include <stdlib.h>
47 #include <stdio.h>
48 #include <string.h>
49 
50 #include <lal/PrintVector.h>
51 
52 #include <lal/LALStdlib.h>
53 #include <lal/LALgetopt.h>
54 #include <lal/AVFactories.h>
55 #include <lal/LALString.h>
56 
57 #define CODES_(x) #x
58 #define CODES(x) CODES_(x)
59 
60 int verbose = 0;
61 
62 static void
63 Usage (const char *program, int exitflag);
64 
65 static void
66 ParseOptions (int argc, char *argv[]);
67 
68 static void
69 TestStatus (LALStatus *status, const char *expectedCodes, int exitCode);
70 
71 #define TYPECODE Z
72 #define TYPE COMPLEX16
73 #include "VectorFactoriesTest_source.c"
74 #undef TYPECODE
75 #undef TYPE
76 
77 #define TYPECODE C
78 #define TYPE COMPLEX8
79 #include "VectorFactoriesTest_source.c"
80 #undef TYPECODE
81 #undef TYPE
82 
83 #define TYPECODE D
84 #define TYPE REAL8
85 #include "VectorFactoriesTest_source.c"
86 #undef TYPECODE
87 #undef TYPE
88 
89 #define TYPECODE S
90 #define TYPE REAL4
91 #include "VectorFactoriesTest_source.c"
92 #undef TYPECODE
93 #undef TYPE
94 
95 #define TYPECODE I2
96 #define TYPE INT2
97 #include "VectorFactoriesTest_source.c"
98 #undef TYPECODE
99 #undef TYPE
100 
101 #define TYPECODE I4
102 #define TYPE INT4
103 #include "VectorFactoriesTest_source.c"
104 #undef TYPECODE
105 #undef TYPE
106 
107 #define TYPECODE I8
108 #define TYPE INT8
109 #include "VectorFactoriesTest_source.c"
110 #undef TYPECODE
111 #undef TYPE
112 
113 #define TYPECODE U2
114 #define TYPE UINT2
115 #include "VectorFactoriesTest_source.c"
116 #undef TYPECODE
117 #undef TYPE
118 
119 #define TYPECODE U4
120 #define TYPE UINT4
121 #include "VectorFactoriesTest_source.c"
122 #undef TYPECODE
123 #undef TYPE
124 
125 #define TYPECODE U8
126 #define TYPE UINT8
127 #include "VectorFactoriesTest_source.c"
128 #undef TYPECODE
129 #undef TYPE
130 
131 #define TYPECODE CHAR
132 #define TYPE CHAR
133 #include "VectorFactoriesTest_source.c"
134 #undef TYPECODE
135 #undef TYPE
136 
137 #define TYPE REAL4
138 #include "VectorFactoriesTest_source.c"
139 #undef TYPE
140 
141 int main( int argc, char *argv[] )
142 {
143 
144  ParseOptions( argc, argv );
145 
146  VectorFactoriesTest();
147  ZVectorFactoriesTest();
148  CVectorFactoriesTest();
149  DVectorFactoriesTest();
150  SVectorFactoriesTest();
151  I2VectorFactoriesTest();
152  I4VectorFactoriesTest();
153  I8VectorFactoriesTest();
154  U2VectorFactoriesTest();
155  U4VectorFactoriesTest();
156  U8VectorFactoriesTest();
157  CHARVectorFactoriesTest();
158 
159  return 0;
160 }
161 
162 
163 /*
164  * TestStatus ()
165  *
166  * Routine to check that the status code status->statusCode agrees with one of
167  * the codes specified in the space-delimited string ignored; if not,
168  * exit to the system with code exitcode.
169  *
170  */
171 static void
172 TestStatus (LALStatus *status, const char *ignored, int exitcode)
173 {
174  char str[64];
175  char *tok;
176 
177  if (verbose)
178  {
180  }
181 
182  if (XLALStringCopy(str, ignored, sizeof(str)))
183  {
184  if ((tok = strtok (str, " ")))
185  {
186  do
187  {
188  if (status->statusCode == atoi (tok))
189  {
190  return;
191  }
192  }
193  while ((tok = strtok (NULL, " ")));
194  }
195  else
196  {
197  if (status->statusCode == atoi (str))
198  {
199  return;
200  }
201  }
202  }
203 
204  fprintf (stderr, "\nExiting to system with code %d\n", exitcode);
205  exit (exitcode);
206 }
207 
208 /*
209  * Usage ()
210  *
211  * Prints a usage message for program program and exits with code exitcode.
212  *
213  */
214 static void
215 Usage (const char *program, int exitcode)
216 {
217  fprintf (stderr, "Usage: %s [options]\n", program);
218  fprintf (stderr, "Options:\n");
219  fprintf (stderr, " -h print this message\n");
220  fprintf (stderr, " -q quiet: run silently\n");
221  fprintf (stderr, " -v verbose: print extra information\n");
222  fprintf (stderr, " -d level set lalDebugLevel to level\n");
223  exit (exitcode);
224 }
225 
226 
227 /*
228  * ParseOptions ()
229  *
230  * Parses the argc - 1 option strings in argv[].
231  *
232  */
233 static void
234 ParseOptions (int argc, char *argv[])
235 {
236  FILE *fp;
237 
238  while (1)
239  {
240  int c = -1;
241 
242  c = LALgetopt (argc, argv, "hqvd:");
243  if (c == -1)
244  {
245  break;
246  }
247 
248  switch (c)
249  {
250  case 'd': /* set debug level */
251  break;
252 
253  case 'v': /* verbose */
254  ++verbose;
255  break;
256 
257  case 'q': /* quiet: run silently (ignore error messages) */
258  fp = freopen ("/dev/null", "w", stderr);
259  if (fp == NULL)
260  {
261  fprintf(stderr, "Error: Unable to open /dev/null\n");
262  exit(1);
263  }
264  fp = freopen ("/dev/null", "w", stdout);
265  if (fp == NULL)
266  {
267  fprintf(stderr, "Error: Unable to open /dev/null\n");
268  exit(1);
269  }
270  break;
271 
272  case 'h':
273  Usage (argv[0], 0);
274  break;
275 
276  default:
277  Usage (argv[0], 1);
278  }
279 
280  }
281 
282  if (LALoptind < argc)
283  {
284  Usage (argv[0], 1);
285  }
286 
287  return;
288 }
289 
290 /** \endcond DONT_DOXYGEN */
const char * program
void REPORTSTATUS(LALStatus *status)
Definition: LALError.c:322
int LALgetopt(int argc, char *const *argv, const char *optstring)
Definition: LALgetopt.c:172
int LALoptind
Definition: LALgetopt.c:79
#define fprintf
static void Usage(const char *program, int exitcode)
Definition: XLALChisqTest.c:70
static void ParseOptions(int argc, char *argv[])
Definition: XLALChisqTest.c:88
int main(int argc, char *argv[])
Definition: cache.c:25
size_t XLALStringCopy(char *dst, const char *src, size_t size)
Copy sources string src to destination string dst.
Definition: LALString.c:104
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
int verbose
Definition: tconvert.c:103
FILE * fp
Definition: tconvert.c:105