Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-6c6b863
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
SWIGLALAlpha.i
Go to the documentation of this file.
1//
2// Copyright (C) 2011--2014, 2022 Karl Wette
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation; either version 2 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with with program; see the file COPYING. If not, write to the
16// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17// MA 02110-1301 USA
18//
19
20///
21/// \defgroup SWIGLALAlpha_i Interface SWIGLALAlpha.i
22/// \ingroup lal_swig
23/// \brief SWIG code which must appear \e before the LAL headers.
24/// \author Karl Wette
25///
26
27///
28/// # Standard output/error redirection
29///
30/// The \b swig_redirect_standard_output_error() function turns on/off standard output/error
31/// redirection for all LAL libraries. It returns whether redirection was previously turned
32/// on/off. The \c swig_lal_do_redirect_stdouterr variable is defined in
33/// <tt>SWIGSharedVars.c</tt>. See <tt>SWIGCommon.i</tt> for further information.
34///
35
36%inline %{
37BOOLEAN swig_redirect_standard_output_error(BOOLEAN redirect) {
38 BOOLEAN old_swig_lal_do_redirect_stdouterr = swig_lal_do_redirect_stdouterr;
39 swig_lal_do_redirect_stdouterr = redirect ? 1 : 0;
40 return old_swig_lal_do_redirect_stdouterr;
41}
42%}
43
44///
45/// # Error handling
46///
47
48///
49/// Custom LAL/GSL error handlers which raise XLAL errors, so that they will be caught by the SWIG
50/// <tt>%exception</tt> handler (instead of aborting, which will crash the user's scripting language
51/// session).
52%header %{
53/// <ul><li>
54
55/// Print the supplied error message, then raise an XLAL error.
56static int swig_lal_raise_hook(int sig, const char *fmt, ...) {
57 va_list ap;
58 va_start(ap, fmt);
59 (void) vfprintf(stderr, fmt, ap);
60 va_end(ap);
61 (void) fprintf(stderr, "LALRaise: %s\n", strsignal(sig));
63 return 0;
64}
65
66/// </li><li>
67
68/// Print the supplied error message, then raise an XLAL error.
69static void swig_lal_abort_hook(const char *fmt, ...) {
70 va_list ap;
71 va_start(ap, fmt);
72 (void) vfprintf(stderr, fmt, ap);
73 va_end(ap);
75}
76
77/// </li><li>
78
79/// Print the supplied error message, then raise an XLAL error.
80static void swig_lal_gsl_error_handler(const char *reason, const char *file, int line, int errnum) {
81 XLALPrintError("GSL function failed: %s (errnum=%i)\n", reason, errnum);
82 XLALError("<GSL function>", file, line, XLAL_EFAILED);
83}
84
85/// </li></ul>
86%}
87///
88
89///
90/// Use nice custom error handlers by default.
91///
92%header %{
93static int swig_set_error_handler_messages = 0;
94%}
95%init %{
96swig_set_nice_error_handlers();
97swig_set_error_handler_messages = 1;
98%}
99
100///
101/// Set nice custom error handlers: replace default XLAL/LAL/GSL error handler with nice custom
102/// handlers, and ensure default XLAL error handler is used.
103///
104%inline %{
105void swig_set_nice_error_handlers(void) {
106 if (swig_set_error_handler_messages) {
107 fprintf(stderr, "*** WARNING: XLAL/LAL/GSL functions will now raise XLAL errors ***\n");
108 }
109 gsl_set_error_handler(swig_lal_gsl_error_handler);
110 lalRaiseHook = swig_lal_raise_hook;
111 lalAbortHook = swig_lal_abort_hook;
113}
114%}
115
116///
117/// Set nasty custom error handlers: use <tt>abort()</tt> error handlers in XLAL/LAL/GSL, which can be
118/// useful when running scripting language interpreter under a debugger.
119///
120%inline %{
121void swig_set_nasty_error_handlers(void) {
122 if (swig_set_error_handler_messages) {
123 fprintf(stderr, "*** WARNING: XLAL/LAL/GSL functions will now abort() on error ***\n");
124 }
125 gsl_set_error_handler(NULL);
129}
130%}
131
132///
133/// # GSL vectors and matrices
134///
135
136///
137/// This macro create wrapping structs for GSL vectors and matrices.
138%define %swig_lal_gsl_vector_matrix(BASETYPE, TYPE, NAME)
139/// <ul><li>
140
141/// GSL vector of type <tt>NAME</tt>.
142typedef struct {
143 %extend {
144 gsl_vector##NAME(const size_t n) {
145 return gsl_vector##NAME##_calloc(n);
146 }
147 gsl_vector##NAME(gsl_vector##NAME *v0) {
148 gsl_vector##NAME *v = gsl_vector##NAME##_alloc(v0->size);
149 gsl_vector##NAME##_memcpy(v, v0);
150 return v;
151 }
152 ~gsl_vector##NAME() {
153 %swiglal_struct_call_dtor(gsl_vector##NAME##_free, $self);
154 }
155 }
156 %swiglal_array_dynamic_size(size_t, size);
157 %swiglal_array_dynamic_1D(gsl_vector##NAME, TYPE, size_t, data, arg1->size, arg1->stride);
158} gsl_vector##NAME;
159
160/// </li><li>
161
162/// Typemap which attempts to view pointers to <tt>const</tt> GSL vector.
163%typemap(in, noblock=1) const gsl_vector##NAME* (void *argp = 0, int res = 0, gsl_vector##NAME##_view temp, void *temp_data = 0, size_t dims[1] = {0}, int elemalloc = 0) %{
164 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
165 if (!SWIG_IsOK(res)) {
166 if (!($disown)) {
167 void *data = NULL;
168 /* swiglal_array_typeid input type: TYPE* */
169 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&data),
170 sizeof(TYPE), 1, dims,
171 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
172 $disown | %convertptr_flags);
173 if (!SWIG_IsOK(res)) {
174 temp_data = data = %swiglal_new_array(dims[0], TYPE);
175 size_t strides[1] = {1};
176 res = %swiglal_array_copyin(TYPE*)(swiglal_no_self(), $input, %as_voidptr(data), &elemalloc,
177 sizeof(TYPE), 1, dims, strides,
178 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
179 $disown | %convertptr_flags);
180 if (!SWIG_IsOK(res)) {
181 %argument_fail(res, "$type", $symname, $argnum);
182 } else {
183 temp = gsl_vector##NAME##_view_array(%reinterpret_cast(data, BASETYPE*), dims[0]);
184 argp = &temp.vector;
185 }
186 } else {
187 temp = gsl_vector##NAME##_view_array(%reinterpret_cast(data, BASETYPE*), dims[0]);
188 argp = &temp.vector;
189 }
190 } else {
191 %argument_fail(res, "$type", $symname, $argnum);
192 }
193 }
194 $1 = %reinterpret_cast(argp, $ltype);
195%}
196%typemap(freearg, match="in", noblock=1) const gsl_vector##NAME* %{
197 if (temp_data$argnum) {
198 XLALFree(temp_data$argnum);
199 }
200%}
201
202/// </li><li>
203
204/// Typemap which attempts to view pointers to non-<tt>const</tt> GSL vector.
205%typemap(in, noblock=1) gsl_vector##NAME* SWIGLAL_VIEWIN_ARRAY (void *argp = 0, int res = 0, gsl_vector##NAME##_view temp) %{
206 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
207 if (!SWIG_IsOK(res)) {
208 if (!($disown)) {
209 size_t dims[1] = {0};
210 void *data = NULL;
211 /* swiglal_array_typeid input type: TYPE* */
212 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&data),
213 sizeof(TYPE), 1, dims,
214 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
215 $disown | %convertptr_flags);
216 if (!SWIG_IsOK(res)) {
217 %argument_fail(res, "$type", $symname, $argnum);
218 } else {
219 temp = gsl_vector##NAME##_view_array(%reinterpret_cast(data, BASETYPE*), dims[0]);
220 argp = &temp.vector;
221 }
222 } else {
223 %argument_fail(res, "$type", $symname, $argnum);
224 }
225 }
226 $1 = %reinterpret_cast(argp, $ltype);
227%}
228
229/// </li><li>
230
231/// Typemap which treats pointers to non-<tt>const</tt> GSL vector as input-output arguments.
232/// The type of the output argument should always match that of the input argument, so:
233/// - If the input argument is a SWIG-wrapped <tt>NAME*</tt>, just unwrap it and return a reference.
234/// - If the input argument is a native scripting-language array, make an internal copy of it,
235/// use the copy, and return a native scripting-language array copy of the internal copy.
236%typemap(in, noblock=1) gsl_vector##NAME* SWIGLAL_COPYINOUT_ARRAY (void *argp = 0, int res = 0, gsl_vector##NAME##_view temp, SWIG_Object input_ref, void *temp_data = 0, size_t dims[1] = {0}, int elemalloc = 0) %{
237 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
238 if (!SWIG_IsOK(res)) {
239 if (!($disown)) {
240 /* swiglal_array_typeid input type: TYPE* */
241 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&temp_data),
242 sizeof(TYPE), 1, dims,
243 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
244 $disown | %convertptr_flags);
245 if (dims[0] > 0) {
246 temp_data = %swiglal_new_array(dims[0], TYPE);
247 size_t strides[1] = {1};
248 res = %swiglal_array_copyin(TYPE*)(swiglal_no_self(), $input, %as_voidptr(temp_data), &elemalloc,
249 sizeof(TYPE), 1, dims, strides,
250 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
251 $disown | %convertptr_flags);
252 if (!SWIG_IsOK(res)) {
253 %argument_fail(res, "$type", $symname, $argnum);
254 } else {
255 temp = gsl_vector##NAME##_view_array(%reinterpret_cast(temp_data, BASETYPE*), dims[0]);
256 argp = &temp.vector;
257 }
258 } else {
259 %argument_fail(res, "$type", $symname, $argnum);
260 }
261 }
262 } else {
263 input_ref = $input;
264 }
265 $1 = %reinterpret_cast(argp, $ltype);
266%}
267%typemap(argout, match="in", noblock=1) gsl_vector##NAME* SWIGLAL_COPYINOUT_ARRAY %{
268 if (temp_data$argnum) {
269 const size_t dims[1] = {temp$argnum.vector.size};
270 const size_t strides[1] = {1};
271 /* swiglal_array_typeid input type: TYPE* */
272 %append_output(%swiglal_array_copyout(TYPE*)(swiglal_no_self(), %as_voidptr(temp_data$argnum),
273 sizeof(TYPE), 1, dims, strides,
274 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
275 SWIG_POINTER_OWN | %newpointer_flags));
276 } else {
277 %append_output(swiglal_get_reference(input_ref$argnum));
278 }
279%}
280%typemap(freearg, match="in", noblock=1) gsl_vector##NAME* SWIGLAL_COPYINOUT_ARRAY %{
281 if (temp_data$argnum) {
282 XLALFree(temp_data$argnum);
283 }
284%}
285
286/// </li><li>
287
288/// GSL matrix of type <tt>NAME</tt>.
289typedef struct {
290 %extend {
291 gsl_matrix##NAME(const size_t n1, const size_t n2) {
292 return gsl_matrix##NAME##_calloc(n1, n2);
293 }
294 gsl_matrix##NAME(gsl_matrix##NAME *m0) {
295 gsl_matrix##NAME *m = gsl_matrix##NAME##_alloc(m0->size1, m0->size2);
296 gsl_matrix##NAME##_memcpy(m, m0);
297 return m;
298 }
299 ~gsl_matrix##NAME() {
300 %swiglal_struct_call_dtor(gsl_matrix##NAME##_free, $self);
301 }
302 }
303 %swiglal_array_dynamic_size(size_t, size1);
304 %swiglal_array_dynamic_size(size_t, size2);
305 %swiglal_array_dynamic_2D(gsl_matrix##NAME, TYPE, size_t, data, arg1->size1, arg1->size2, arg1->tda, 1);
306} gsl_matrix##NAME;
307
308/// </li><li>
309
310/// Typemap which attempts to view pointers to <tt>const</tt> GSL matrix.
311%typemap(in, noblock=1) const gsl_matrix##NAME* (void *argp = 0, int res = 0, gsl_matrix##NAME##_view temp, void *temp_data = 0, size_t dims[2] = {0, 0}, int elemalloc = 0) %{
312 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
313 if (!SWIG_IsOK(res)) {
314 if (!($disown)) {
315 void *data = NULL;
316 /* swiglal_array_typeid input type: TYPE* */
317 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&data),
318 sizeof(TYPE), 2, dims,
319 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
320 $disown | %convertptr_flags);
321 if (!SWIG_IsOK(res)) {
322 temp_data = data = %swiglal_new_array(dims[0] * dims[1], TYPE);
323 size_t strides[2] = {dims[1], 1};
324 res = %swiglal_array_copyin(TYPE*)(swiglal_no_self(), $input, %as_voidptr(data), &elemalloc,
325 sizeof(TYPE), 2, dims, strides,
326 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
327 $disown | %convertptr_flags);
328 if (!SWIG_IsOK(res)) {
329 %argument_fail(res, "$type", $symname, $argnum);
330 } else {
331 temp = gsl_matrix##NAME##_view_array(%reinterpret_cast(data, BASETYPE*), dims[0], dims[1]);
332 argp = &temp.matrix;
333 }
334 } else {
335 temp = gsl_matrix##NAME##_view_array(%reinterpret_cast(data, BASETYPE*), dims[0], dims[1]);
336 argp = &temp.matrix;
337 }
338 } else {
339 %argument_fail(res, "$type", $symname, $argnum);
340 }
341 }
342 $1 = %reinterpret_cast(argp, $ltype);
343%}
344%typemap(freearg, match="in", noblock=1) const gsl_matrix##NAME* %{
345 if (temp_data$argnum) {
346 XLALFree(temp_data$argnum);
347 }
348%}
349
350/// </li><li>
351
352/// Typemap which attempts to view pointers to non-<tt>const</tt> GSL matrix.
353%typemap(in, noblock=1) gsl_matrix##NAME* SWIGLAL_VIEWIN_ARRAY (void *argp = 0, int res = 0, gsl_matrix##NAME##_view temp) %{
354 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
355 if (!SWIG_IsOK(res)) {
356 if (!($disown)) {
357 size_t dims[2] = {0, 0};
358 void *data = NULL;
359 /* swiglal_array_typeid input type: TYPE* */
360 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&data),
361 sizeof(TYPE), 2, dims,
362 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
363 $disown | %convertptr_flags);
364 if (!SWIG_IsOK(res)) {
365 %argument_fail(res, "$type", $symname, $argnum);
366 } else {
367 temp = gsl_matrix##NAME##_view_array(%reinterpret_cast(data, BASETYPE*), dims[0], dims[1]);
368 argp = &temp.matrix;
369 }
370 } else {
371 %argument_fail(res, "$type", $symname, $argnum);
372 }
373 }
374 $1 = %reinterpret_cast(argp, $ltype);
375%}
376
377/// </li><li>
378
379/// Typemap which treats pointers to non-<tt>const</tt> GSL matrix as input-output arguments.
380/// The type of the output argument should always match that of the input argument, so:
381/// - If the input argument is a SWIG-wrapped <tt>NAME*</tt>, just unwrap it and return a reference.
382/// - If the input argument is a native scripting-language array, make an internal copy of it,
383/// use the copy, and return a native scripting-language array copy of the internal copy.
384%typemap(in, noblock=1) gsl_matrix##NAME* SWIGLAL_COPYINOUT_ARRAY (void *argp = 0, int res = 0, gsl_matrix##NAME##_view temp, SWIG_Object input_ref, void *temp_data = 0, size_t dims[2] = {0, 0}, int elemalloc = 0) %{
385 res = SWIG_ConvertPtr($input, &argp, $descriptor, 0 /*$disown*/ | %convertptr_flags);
386 if (!SWIG_IsOK(res)) {
387 if (!($disown)) {
388 /* swiglal_array_typeid input type: TYPE* */
389 res = %swiglal_array_viewin(TYPE*)(swiglal_no_self(), $input, %as_voidptrptr(&temp_data),
390 sizeof(TYPE), 2, dims,
391 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
392 $disown | %convertptr_flags);
393 if (dims[0] * dims[1] > 0) {
394 temp_data = %swiglal_new_array(dims[0] * dims[1], TYPE);
395 size_t strides[2] = {dims[1], 1};
396 res = %swiglal_array_copyin(TYPE*)(swiglal_no_self(), $input, %as_voidptr(temp_data), &elemalloc,
397 sizeof(TYPE), 2, dims, strides,
398 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
399 $disown | %convertptr_flags);
400 if (!SWIG_IsOK(res)) {
401 %argument_fail(res, "$type", $symname, $argnum);
402 } else {
403 temp = gsl_matrix##NAME##_view_array(%reinterpret_cast(temp_data, BASETYPE*), dims[0], dims[1]);
404 argp = &temp.matrix;
405 }
406 } else {
407 %argument_fail(res, "$type", $symname, $argnum);
408 }
409 }
410 } else {
411 input_ref = $input;
412 }
413 $1 = %reinterpret_cast(argp, $ltype);
414%}
415%typemap(argout, match="in", noblock=1) gsl_matrix##NAME* SWIGLAL_COPYINOUT_ARRAY %{
416 if (temp_data$argnum) {
417 const size_t dims[2] = {temp$argnum.matrix.size1, temp$argnum.matrix.size2};
418 const size_t strides[2] = {dims[1], 1};
419 /* swiglal_array_typeid input type: TYPE* */
420 %append_output(%swiglal_array_copyout(TYPE*)(swiglal_no_self(), %as_voidptr(temp_data$argnum),
421 sizeof(TYPE), 2, dims, strides,
422 $typemap(swiglal_dynarr_isptr, TYPE), $typemap(swiglal_dynarr_tinfo, TYPE),
423 SWIG_POINTER_OWN | %newpointer_flags));
424 } else {
425 %append_output(swiglal_get_reference(input_ref$argnum));
426 }
427%}
428%typemap(freearg, match="in", noblock=1) gsl_matrix##NAME* SWIGLAL_COPYINOUT_ARRAY %{
429 if (temp_data$argnum) {
430 XLALFree(temp_data$argnum);
431 }
432%}
433
434/// </li></ul>
435%enddef
436///
437
438///
439/// GSL integer vectors and matrices.
440///
441%swig_lal_gsl_vector_matrix(short, short, _short);
442%swig_lal_gsl_vector_matrix(unsigned short, unsigned short, _ushort);
443%swig_lal_gsl_vector_matrix(int, int, _int);
444%swig_lal_gsl_vector_matrix(unsigned int, unsigned int, _uint);
445%swig_lal_gsl_vector_matrix(long, long, _long);
446%swig_lal_gsl_vector_matrix(unsigned long, unsigned long, _ulong);
447
448///
449/// GSL real and complex vectors and matrices.
450///
451%swig_lal_gsl_vector_matrix(float, float, _float);
452%swig_lal_gsl_vector_matrix(double, double, ); // GSL double vector/matrix has no typename suffix.
453%swig_lal_gsl_vector_matrix(float, gsl_complex_float, _complex_float);
454%swig_lal_gsl_vector_matrix(double, gsl_complex, _complex);
455
456///
457/// # Specialised typemaps for <tt>LIGOTimeGPS</tt>
458///
459
460/// Allow arbitrary attributes to be attached to the <tt>LIGOTimeGPS</tt> class in Python.
461#if defined(SWIGPYTHON)
462%pythondynamic tagLIGOTimeGPS;
463#endif
464
465///
466/// Specialised input typemaps for <tt>LIGOTimeGPS</tt> structs. Accepts a SWIG-wrapped <tt>LIGOTimeGPS</tt> or a
467/// double as input; in Python, also accepts any object with .gpsSeconds and .gpsNanoSeconds attributes.
468///
469%fragment("swiglal_specialised_tagLIGOTimeGPS", "header", fragment=SWIG_AsVal_frag(double), fragment=SWIG_AsVal_frag(int32_t)) {
470 int swiglal_specialised_tagLIGOTimeGPS(SWIG_Object in, LIGOTimeGPS *out) {
471 double val = 0;
472 int res = SWIG_AsVal(double)(in, &val);
473 if (!SWIG_IsOK(res)) {
474#ifdef SWIGPYTHON
475 if (PyObject_HasAttrString(in, "gpsSeconds") && PyObject_HasAttrString(in, "gpsNanoSeconds")) {
476 int32_t gpsSeconds = 0, gpsNanoSeconds = 0;
477 res = SWIG_AsVal(int32_t)(PyObject_GetAttrString(in, "gpsSeconds"), &gpsSeconds);
478 if (!SWIG_IsOK(res)) {
479 return res;
480 }
481 res = SWIG_AsVal(int32_t)(PyObject_GetAttrString(in, "gpsNanoSeconds"), &gpsNanoSeconds);
482 if (!SWIG_IsOK(res)) {
483 return res;
484 }
486 return SWIG_OK;
487 }
488#endif
489 return res;
490 }
491 XLALGPSSetREAL8(out, val);
492 return SWIG_OK;
493 }
494}
495%swiglal_specialised_typemaps(tagLIGOTimeGPS, "swiglal_specialised_tagLIGOTimeGPS");
496
497///
498/// # Specialised typemaps for <tt>LALUnit</tt>
499///
500
501///
502/// Specialised input typemaps for <tt>LALUnit</tt> structs. Accepts a SWIG-wrapped <tt>LALUnit</tt>,
503/// a unit string, or a dimensionless power-of-10 double as input.
504///
505%fragment("swiglal_specialised_tagLALUnit", "header",
506 fragment="SWIG_AsCharPtr",
507 fragment=SWIG_AsVal_frag(double)
508 )
509{
510 int swiglal_specialised_tagLALUnit(SWIG_Object in, LALUnit *out) {
511 char *str = 0;
512 int alloc = 0;
513 int res = SWIG_AsCharPtr(in, &str, &alloc);
514 if (SWIG_IsOK(res)) {
515 if (XLALParseUnitString(out, str) == NULL) {
516 res = SWIG_ValueError;
517 }
518 }
519 if (alloc == SWIG_NEWOBJ) {
520 %delete_array(str);
521 }
522 if (SWIG_IsOK(res)) {
523 return res;
524 }
525 double val = 0;
526 res = SWIG_AsVal(double)(in, &val);
527 if (!SWIG_IsOK(res)) {
528 return res;
529 }
530 if (val <= 0) {
531 return SWIG_ValueError;
532 }
533 double pow10 = 0;
534 if (modf(log10(val), &pow10) != 0) {
535 return SWIG_ValueError;
536 }
537 if (pow10 < INT16_MIN || INT16_MAX < pow10) {
538 return SWIG_ValueError;
539 }
541 out->powerOfTen = (INT2)pow10;
542 return SWIG_OK;
543 }
544}
545%swiglal_specialised_typemaps(tagLALUnit, "swiglal_specialised_tagLALUnit");
546
547///
548/// # Specialised typemaps for <tt>LALDict</tt>
549///
550
551///
552/// Specialised input typemaps for <tt>LALDict</tt>. Accepts a SWIG-wrapped <tt>LALDict</tt>, or:
553///
554/// - For Python, a native dictionary with keys of the form <tt>"key[:type]"</tt>, where
555/// <tt>"type"</tt> specifies the type of the <tt>LALDict</tt> entry:
556// <tt>"[U]INT{2,4,8}"</tt> for integer values,
557/// <tt>"REAL{4,8}"</tt> for real values, and
558/// <tt>"COMPLEX{8,16}"</tt> for complex values.
559/// If <tt>"type"</tt> is absent, the entry is assumed to be a string.
560///
561%fragment("swiglal_specialised_ptr_tagLALDict", "header",
562 fragment="SWIG_AsCharPtr",
563 fragment=SWIG_AsVal_frag(uint16_t),
564 fragment=SWIG_AsVal_frag(int16_t),
565 fragment=SWIG_AsVal_frag(uint32_t),
566 fragment=SWIG_AsVal_frag(int32_t),
567 fragment=SWIG_AsVal_frag(uint64_t),
568 fragment=SWIG_AsVal_frag(int64_t),
569 fragment=SWIG_AsVal_frag(float),
570 fragment=SWIG_AsVal_frag(double),
571 fragment=SWIG_AsVal_frag(COMPLEX8),
572 fragment=SWIG_AsVal_frag(COMPLEX16)
573 )
574{
575 int swiglal_specialised_ptr_tagLALDict(SWIG_Object in, LALDict **out) {
576 int res = SWIG_ValueError;
577 char *keyname, *valuestr = 0;
578 int keyalloc, valuealloc = 0;
579 *out = XLALCreateDict();
580 if (*out == NULL) {
581 goto fail;
582 }
583#ifdef SWIGPYTHON
584 if (!PyDict_Check(in)) {
585 return SWIG_ValueError;
586 }
587 PyObject *key, *value;
588 Py_ssize_t pos = 0;
589 while (PyDict_Next(in, &pos, &key, &value)) {
590 if (!SWIG_IsOK(SWIG_AsCharPtr(key, &keyname, &keyalloc))) {
591 break;
592 }
593 char *keytype = strrchr(keyname, ':');
594 if (keytype == NULL) {
595 keytype = keyname + strlen(keyname);
596 } else {
597 *keytype = 0;
598 ++keytype;
599 }
600 do {
601#define SWIGLAL_LALDICT_HANDLE_TYPE(LALTYPESTR, LALTYPE, CTYPE, FMT, ...) \
602 if (XLALStringCaseCompare(keytype, LALTYPESTR) == 0) { \
603 CTYPE v = 0; \
604 if (SWIG_IsOK(SWIG_AsVal(CTYPE)(value, &v))) { \
605 if (XLALDictInsert##LALTYPE##Value(*out, keyname, v) != XLAL_SUCCESS) { \
606 goto fail; \
607 } \
608 XLALPrintInfo("%s: dict=%p, key=%s, type=%s, value=" FMT "\n", __func__, in, keyname, keytype, __VA_ARGS__); \
609 break; \
610 } \
611 }
612 SWIGLAL_LALDICT_HANDLE_TYPE("UINT2", UINT2, uint16_t, "%" LAL_UINT2_FORMAT, v);
613 SWIGLAL_LALDICT_HANDLE_TYPE("INT2", INT2, int16_t, "%" LAL_INT2_FORMAT, v);
614 SWIGLAL_LALDICT_HANDLE_TYPE("UINT4", UINT4, uint32_t, "%" LAL_UINT4_FORMAT, v);
615 SWIGLAL_LALDICT_HANDLE_TYPE("INT4", INT4, int32_t, "%" LAL_INT4_FORMAT, v);
616 SWIGLAL_LALDICT_HANDLE_TYPE("UINT8", UINT8, uint64_t, "%" LAL_UINT8_FORMAT, v);
617 SWIGLAL_LALDICT_HANDLE_TYPE("INT8", INT8, int64_t, "%" LAL_INT8_FORMAT, v);
618 SWIGLAL_LALDICT_HANDLE_TYPE("REAL4", REAL4, float, "%" LAL_REAL4_FORMAT, v);
619 SWIGLAL_LALDICT_HANDLE_TYPE("REAL8", REAL8, double, "%" LAL_REAL8_FORMAT, v);
620 SWIGLAL_LALDICT_HANDLE_TYPE("COMPLEX8", COMPLEX8, COMPLEX8, "(%" LAL_REAL4_FORMAT ",%" LAL_REAL4_FORMAT ")", crealf(v), cimagf(v));
621 SWIGLAL_LALDICT_HANDLE_TYPE("COMPLEX16", COMPLEX16, COMPLEX16, "(%" LAL_REAL8_FORMAT ",%" LAL_REAL8_FORMAT ")", creal (v), cimag (v));
622#undef SWIGLAL_LALDICT_GIVEN_TYPE
623 if (SWIG_IsOK(SWIG_AsCharPtr(value, &valuestr, &valuealloc))) {
624 if (XLALDictInsertStringValue(*out, keyname, valuestr) != XLAL_SUCCESS) {
625 goto fail;
626 }
627 XLALPrintInfo("%s: dict=%p, key=%s, type=string, value='%s'\n", __func__, in, keyname, valuestr);
628 if (valuealloc == SWIG_NEWOBJ) {
629 %delete_array(valuestr);
630 valuealloc = 0;
631 }
632 } else {
633 XLALPrintInfo("%s: dict=%p, key=%s, type=unknown\n", __func__, in, keyname);
634 goto fail;
635 }
636 } while(0);
637 if (keyalloc == SWIG_NEWOBJ) {
638 %delete_array(keyname);
639 keyalloc = 0;
640 }
641 }
642 res = SWIG_OK;
643#endif
644 fail:
645 if (!SWIG_IsOK(res)) {
646 XLALDestroyDict(*out);
647 *out = NULL;
648 }
649 if (keyalloc == SWIG_NEWOBJ) {
650 %delete_array(keyname);
651 }
652 if (valuealloc == SWIG_NEWOBJ) {
653 %delete_array(valuestr);
654 }
655 return res;
656 }
657 void swiglal_specialised_ptr_tagLALDict_destroy(LALDict *tmp) {
658 XLALDestroyDict(tmp);
659 }
660}
661%swiglal_specialised_ptr_typemaps(tagLALDict, "swiglal_specialised_ptr_tagLALDict");
662
663// Local Variables:
664// mode: c
665// End:
#define TYPE
void XLALDestroyDict(LALDict *dict)
Definition: LALDict.c:137
LALDict * XLALCreateDict(void)
Definition: LALDict.c:148
int XLALDictInsertStringValue(LALDict *dict, const char *key, const char *string)
Definition: LALDict.c:411
int(* lalRaiseHook)(int, const char *,...)
Definition: LALError.c:57
void(* lalAbortHook)(const char *,...)
Definition: LALError.c:75
#define BASETYPE
#define fprintf
int XLALPrintInfo(const char *fmt,...)
Definition: XLALError.c:90
int XLALPrintError(const char *fmt,...)
Definition: XLALError.c:68
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
uint64_t UINT8
Eight-byte unsigned integer; on some platforms this is equivalent to unsigned long int instead.
double complex COMPLEX16
Double-precision floating-point complex number (16 bytes total)
double REAL8
Double precision real floating-point number (8 bytes).
int16_t INT2
Two-byte signed integer.
int64_t INT8
Eight-byte signed integer; on some platforms this is equivalent to long int instead.
uint16_t UINT2
Two-byte unsigned integer.
uint32_t UINT4
Four-byte unsigned integer.
float complex COMPLEX8
Single-precision floating-point complex number (8 bytes total)
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
int LALRaise(int sig, const char *fmt,...)
Definition: LALError.c:58
void LALAbort(const char *fmt,...)
Definition: LALError.c:76
#define XLALFree(p)
Definition: LALMalloc.h:47
#define LAL_REAL8_FORMAT
Definition: LALStdio.h:133
#define LAL_INT2_FORMAT
Definition: LALStdio.h:126
#define LAL_INT8_FORMAT
Definition: LALStdio.h:128
#define LAL_INT4_FORMAT
Definition: LALStdio.h:127
#define LAL_REAL4_FORMAT
Definition: LALStdio.h:132
#define LAL_UINT8_FORMAT
Definition: LALStdio.h:131
#define LAL_UINT4_FORMAT
Definition: LALStdio.h:130
#define LAL_UINT2_FORMAT
Definition: LALStdio.h:129
static const INT4 m
Definition: Random.c:80
int swig_lal_do_redirect_stdouterr
The swig_lal_do_redirect_stdouterr variable turns on standard output/error redirection for all LAL li...
LALUnit * XLALParseUnitString(LALUnit *output, const char *string)
Returns the pointer output upon return or a pointer to newly allocated memory if output was NULL; on ...
Definition: UnitDefs.c:354
const LALUnit lalDimensionlessUnit
dimensionless units
Definition: UnitDefs.c:156
void XLALError(const char *func, const char *file, int line, int errnum)
Routine to set the XLAL error number and invoke the XLAL error handler.
Definition: XLALError.c:582
void XLALAbortErrorHandler(const char *func, const char *file, int line, int errnum)
The XLAL error handler that raises SIGABRT.
Definition: XLALError.c:599
XLALErrorHandlerType * XLALSetErrorHandler(XLALErrorHandlerType *newHandler)
Sets the error handler to a new handler and returns the old handler.
Definition: XLALError.c:372
int XLALSetErrno(int errnum)
Sets the XLAL error number to errnum, returns the new value.
Definition: XLALError.c:327
void XLALDefaultErrorHandler(const char *func, const char *file, int line, int errnum)
The default XLAL error handler.
Definition: XLALError.c:561
@ XLAL_SUCCESS
Success return value (not an error number)
Definition: XLALError.h:401
@ XLAL_EFAILED
Generic failure.
Definition: XLALError.h:418
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
Sets GPS time given GPS seconds as a REAL8.
Definition: XLALTime.c:73
LIGOTimeGPS * XLALGPSSet(LIGOTimeGPS *epoch, INT4 gpssec, INT8 gpsnan)
Sets GPS time given GPS integer seconds and residual nanoseconds.
Definition: XLALTime.c:63
This structure stores units in the mksA system (plus Kelvin, Strain, and ADC Count).
Definition: LALDatatypes.h:498
INT2 powerOfTen
Overall power-of-ten scaling is 10^powerOfTen.
Definition: LALDatatypes.h:499
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
Definition: LALDatatypes.h:458