Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ArrayFactoriesTest.c
Go to the documentation of this file.
1/**
2 * \file
3 * \ingroup AVFactories_h
4 *
5 * \brief A program to test create/destroy array routines.
6 *
7 * ### Usage ###
8 *
9 * \code
10 * ArrayFactoriesTest [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>CreateArray()
36 * <datatype>DestroyArray()
37 * \endcode
38 *
39 * ### Notes ###
40 *
41 */
42/** \cond DONT_DOXYGEN */
43#include <config.h>
44
45#include <stdlib.h>
46#include <stdio.h>
47#include <string.h>
48
49#include <lal/LALStdlib.h>
50#include <lal/LALgetopt.h>
51#include <lal/AVFactories.h>
52#include <lal/LALString.h>
53
54#define CODES_(x) #x
55#define CODES(x) CODES_(x)
56
57int verbose = 0;
58
59static void
60Usage (const char *program, int exitflag);
61
62static void
63ParseOptions (int argc, char *argv[]);
64
65static void
66TestStatus (LALStatus *status, const char *expectedCodes, int exitCode);
67
68static void
69ClearStatus (LALStatus *status);
70
71#define TYPECODE Z
72#define TYPE COMPLEX16
73#include "ArrayFactoriesTest_source.c"
74#undef TYPECODE
75#undef TYPE
76
77#define TYPECODE C
78#define TYPE COMPLEX8
79#include "ArrayFactoriesTest_source.c"
80#undef TYPECODE
81#undef TYPE
82
83#define TYPECODE D
84#define TYPE REAL8
85#include "ArrayFactoriesTest_source.c"
86#undef TYPECODE
87#undef TYPE
88
89#define TYPECODE S
90#define TYPE REAL4
91#include "ArrayFactoriesTest_source.c"
92#undef TYPECODE
93#undef TYPE
94
95#define TYPECODE I2
96#define TYPE INT2
97#include "ArrayFactoriesTest_source.c"
98#undef TYPECODE
99#undef TYPE
100
101#define TYPECODE I4
102#define TYPE INT4
103#include "ArrayFactoriesTest_source.c"
104#undef TYPECODE
105#undef TYPE
106
107#define TYPECODE I8
108#define TYPE INT8
109#include "ArrayFactoriesTest_source.c"
110#undef TYPECODE
111#undef TYPE
112
113#define TYPECODE U2
114#define TYPE UINT2
115#include "ArrayFactoriesTest_source.c"
116#undef TYPECODE
117#undef TYPE
118
119#define TYPECODE U4
120#define TYPE UINT4
121#include "ArrayFactoriesTest_source.c"
122#undef TYPECODE
123#undef TYPE
124
125#define TYPECODE U8
126#define TYPE UINT8
127#include "ArrayFactoriesTest_source.c"
128#undef TYPECODE
129#undef TYPE
130
131#define TYPE REAL4
132#include "ArrayFactoriesTest_source.c"
133#undef TYPE
134
135int main( int argc, char *argv[] )
136{
137
138 ParseOptions( argc, argv );
139
140 ArrayFactoriesTest();
141 ZArrayFactoriesTest();
142 CArrayFactoriesTest();
143 DArrayFactoriesTest();
144 SArrayFactoriesTest();
145 I2ArrayFactoriesTest();
146 I4ArrayFactoriesTest();
147 I8ArrayFactoriesTest();
148 U2ArrayFactoriesTest();
149 U4ArrayFactoriesTest();
150 U8ArrayFactoriesTest();
151
152 return 0;
153}
154
155
156/*
157 * TestStatus ()
158 *
159 * Routine to check that the status code status->statusCode agrees with one of
160 * the codes specified in the space-delimited string ignored; if not,
161 * exit to the system with code exitcode.
162 *
163 */
164static void
165TestStatus (LALStatus *status, const char *ignored, int exitcode)
166{
167 char str[64];
168 char *tok;
169
170 if (verbose)
171 {
173 }
174
175 if (XLALStringCopy(str, ignored, sizeof(str)))
176 {
177 if ((tok = strtok (str, " ")))
178 {
179 do
180 {
181 if (status->statusCode == atoi (tok))
182 {
183 return;
184 }
185 }
186 while ((tok = strtok (NULL, " ")));
187 }
188 else
189 {
190 if (status->statusCode == atoi (str))
191 {
192 return;
193 }
194 }
195 }
196
197 fprintf (stderr, "\nExiting to system with code %d\n", exitcode);
198 exit (exitcode);
199}
200
201
202/*
203 *
204 * ClearStatus ()
205 *
206 * Recursively applies DETATCHSTATUSPTR() to status structure to destroy
207 * linked list of statuses.
208 *
209 */
210static void
211ClearStatus (LALStatus *status)
212{
213 if (status->statusPtr)
214 {
215 ClearStatus (status->statusPtr);
217 }
218}
219
220/*
221 * Usage ()
222 *
223 * Prints a usage message for program program and exits with code exitcode.
224 *
225 */
226static void
227Usage (const char *program, int exitcode)
228{
229 fprintf (stderr, "Usage: %s [options]\n", program);
230 fprintf (stderr, "Options:\n");
231 fprintf (stderr, " -h print this message\n");
232 fprintf (stderr, " -q quiet: run silently\n");
233 fprintf (stderr, " -v verbose: print extra information\n");
234 fprintf (stderr, " -d level set lalDebugLevel to level\n");
235 exit (exitcode);
236}
237
238
239/*
240 * ParseOptions ()
241 *
242 * Parses the argc - 1 option strings in argv[].
243 *
244 */
245static void
246ParseOptions (int argc, char *argv[])
247{
248 FILE *fp;
249
250 while (1)
251 {
252 int c = -1;
253
254 c = LALgetopt (argc, argv, "hqvd:");
255 if (c == -1)
256 {
257 break;
258 }
259
260 switch (c)
261 {
262 case 'd': /* set debug level */
263 break;
264
265 case 'v': /* verbose */
266 ++verbose;
267 break;
268
269 case 'q': /* quiet: run silently (ignore error messages) */
270 fp = freopen ("/dev/null", "w", stderr);
271 if (fp == NULL)
272 {
273 fprintf(stderr, "Error: Unable to open /dev/null\n");
274 exit(1);
275 }
276 fp = freopen ("/dev/null", "w", stdout);
277 if (fp == NULL)
278 {
279 fprintf(stderr, "Error: Unable to open /dev/null\n");
280 exit(1);
281 }
282 break;
283
284 case 'h':
285 Usage (argv[0], 0);
286 break;
287
288 default:
289 Usage (argv[0], 1);
290 }
291
292 }
293
294 if (LALoptind < argc)
295 {
296 Usage (argv[0], 1);
297 }
298
299 return;
300}
301
302/** \endcond DONT_DOXYGEN */
const char * program
void REPORTSTATUS(LALStatus *status)
Definition: LALError.c:322
#define DETATCHSTATUSPTR(statusptr)
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