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
LALRunningMedianTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Bernd Machenschalk, David Chin, Jolien Creighton
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#include <math.h>
21#include <stdlib.h>
22#include <lal/LALStdlib.h>
23#include <lal/LALConstants.h>
24#include <lal/LALMalloc.h>
25#include <lal/SeqFactories.h>
26#include <lal/PrintVector.h>
27#include <lal/LALRunningMedian.h>
28
29
30/**
31 * \file
32 * \ingroup LALRunningMedian_h
33 * \author B. Machenschalk
34 *
35 * \brief Program to test running median function
36 *
37 * ### Usage ###
38 *
39 * \code
40 * LALRunningMedianTest [length blocksize [lalDebugLevel]]
41 * \endcode
42 *
43 * ### Description ###
44 *
45 * This program test the LALRunningMedian functions
46 * First the proper function of the input checks is tested.
47 * Then it reads an array size and a block size from the command
48 * line, fills an array of the given size with random numbers,
49 * computes medians of all blocks with blocksize using the
50 * LALRunningMedian functions and compares the results against
51 * inividually calculated medians. The test is repeated with
52 * blocksize - 1 (to check for even/odd errors).
53 * The default values for array length and window
54 * width are 1024 and 512.
55 * If a value for lalDebugLevel is given, the program
56 * outputs the values of the input and median arrays
57 * to files, using the PrintVector functions
58 * from the support package.
59 *
60 */
61
62/**\name Error Codes */
63/** @{ */
64#define LALRUNNINGMEDIANTESTC_ENOM 0 /**< Nominal exit */
65#define LALRUNNINGMEDIANTESTC_EARG 1 /**< Error parsing command-line arguments */
66#define LALRUNNINGMEDIANTESTC_ESUB 2 /**< Subroutine returned error */
67#define LALRUNNINGMEDIANTESTC_EALOC 3 /**< Could not allocate data space */
68#define LALRUNNINGMEDIANTESTC_EFALSE 4 /**< Medians mismatch */
69#define LALRUNNINGMEDIANTESTC_EERR 5 /**< Subroutine returned wrong or no error */
70/** @} */
71
72/** \cond DONT_DOXYGEN */
73#define LALRUNNINGMEDIANTESTC_MSGENOM "Nominal exit"
74#define LALRUNNINGMEDIANTESTC_MSGEARG "Error parsing command-line arguments"
75#define LALRUNNINGMEDIANTESTC_MSGESUB "Subroutine returned error"
76#define LALRUNNINGMEDIANTESTC_MSGEALOC "Could not allocate data space"
77#define LALRUNNINGMEDIANTESTC_MSGEFALSE "Medians mismatch"
78#define LALRUNNINGMEDIANTESTC_MSGEERR "Subroutine returned wrong or no error"
79
80
81/* Declare lalDebugLevel */
82
83/* global program name */
84char*argv0;
85
86/* A local macro for printing error messages */
87#define EXIT( code, program, message ) \
88 if ( 1 ) { \
89 if (( lalDebugLevel & LALERROR ) && (code)) \
90 LALPrintError( "Error[0] %d: program %s, file %s, line %d, %s\n"\
91 " %s\n", (code), (program), __FILE__, \
92 __LINE__, "$Id$", (message) ); \
93 else if ( lalDebugLevel & LALINFO ) \
94 LALPrintError( "Info[0]: program %s, file %s, line %d, %s\n" \
95 " %s\n", (program), __FILE__, __LINE__, \
96 "$Id$", (message) ); \
97 return (code); \
98 } else (void)(0)
99
100#if 0
101#define TOLERANCE ( 10.0 * LAL_REAL8_EPS )
102#define compare_double( x, y ) \
103( ( y == 0 ? ( x == 0 ? 0 : fabs((x-y)/x) ) : fabs((x-y)/y) ) > TOLERANCE )
104#endif
105
106
107/* prototypes */
108
109int compare_double( double x, double y );
110int compare_single( float x, float y );
111static int rngmed_sortindex(const void *elem1, const void *elem2);
112int testDRunningMedian(LALStatus *stat, REAL8Sequence *input, UINT4 length,
114int testSRunningMedian(LALStatus *stat, REAL4Sequence *input, UINT4 length,
116
117
118struct rngmed_val_index {
119 REAL8 data;
120 UINT8 index;
121};
122
123
124int compare_double( double x, double y )
125{
126 double diff;
127 double denom;
128 if ( x < LAL_REAL8_MIN )
129 {
130 if ( y < LAL_REAL8_MIN )
131 return 0;
132 else
133 denom = fabs( y );
134 }
135 else
136 {
137 denom = fabs( x );
138 }
139 diff = fabs( x - y );
140 if ( diff / denom > 10.0 * LAL_REAL8_EPS )
141 {
142 return 1;
143 }
144 return 0;
145}
146
147
148int compare_single( float x, float y )
149{
150 float diff;
151 float denom;
152 if ( x < LAL_REAL4_MIN )
153 {
154 if ( y < LAL_REAL4_MIN )
155 return 0;
156 else
157 denom = fabs( y );
158 }
159 else
160 {
161 denom = fabs( x );
162 }
163 diff = fabs( x - y );
164 if ( diff / denom > 10.0 * LAL_REAL4_EPS )
165 {
166 return 1;
167 }
168 return 0;
169}
170
171static int rngmed_sortindex(const void *elem1, const void *elem2){
172 /*Used in running qsort*/
173
174 const struct rngmed_val_index *A = elem1;
175 const struct rngmed_val_index *B = elem2;
176 double data1, data2;
177
178 data1=A->data;
179 data2=B->data;
180 if (data1 < data2)
181 return -1;
182 else if (data1==data2)
183 return 0;
184 else
185 return 1;
186}
187
188
189int testDRunningMedian(LALStatus *stat, REAL8Sequence *input, UINT4 length,
191/* Test the LALDRunningMedian (REAL8Sequence) function by
192 comparing the reults to individually calculated medians */
193
194 REAL8 median;
195 REAL8Sequence *medians=NULL;
196 struct rngmed_val_index *index_block;
197 UINT4 i,k;
198
199 /* create medians vector */
200 LALDCreateVector( stat, &medians, input->length - param.blocksize + 1 );
201 if( stat->statusCode){
202 printf("ERROR: LALDCreateVector returned status %d\n",stat->statusCode);
203 EXIT( LALRUNNINGMEDIANTESTC_ESUB, argv0, LALRUNNINGMEDIANTESTC_MSGESUB );
204 }
205
206 /* call running median */
207 if (bmimpl)
208 LALDRunningMedian2( stat, medians, input, param );
209 else
210 LALDRunningMedian( stat, medians, input, param );
211 if ( stat->statusCode ) {
212 printf("ERROR: LALDRunningMedian returned status %d\n",stat->statusCode);
213 EXIT( LALRUNNINGMEDIANTESTC_ESUB, argv0, LALRUNNINGMEDIANTESTC_MSGESUB );
214 }
215
216 /* write the vectors if verbose */
217 if ( verbose ) {
218 LALDPrintVector(input);
219 LALDPrintVector(input);
220 }
221
222 /* allocate memory for calculating single medians */
223 index_block = (struct rngmed_val_index *)LALCalloc(param.blocksize, sizeof(struct rngmed_val_index));
224 if(!index_block) {
225 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
226 }
227
228 /* compare all medians */
229 for(i=0;i<length-param.blocksize+1;i++) {
230
231 /* prepare array for sort */
232 for(k=0;k<param.blocksize;k++){
233 index_block[k].data=input->data[k+i];
234 index_block[k].index=k;
235 }
236
237 /* sort */
238 qsort(index_block, param.blocksize, sizeof(struct rngmed_val_index),rngmed_sortindex);
239
240 /* find median */
241 if(param.blocksize%2==1)
242 median = index_block[(param.blocksize-1)/2].data;
243 else
244 median = (index_block[param.blocksize/2-1].data+index_block[param.blocksize/2].data)/2;
245
246 /* compare results */
247 if(compare_double(median,medians->data[i])) {
248 printf("ERROR: index:%d median:% 22.15e running median:% 22.15e mismatch:% 22.15e\n",
249 i, median, medians->data[i], median - medians->data[i]);
250 LALFree(index_block);
251 LALFree(medians);
252 LALFree(input);
253 EXIT( LALRUNNINGMEDIANTESTC_EFALSE, argv0, LALRUNNINGMEDIANTESTC_MSGEFALSE );
254 }
255 }
256
257 LALFree(index_block);
258 LALDDestroyVector(stat,&medians);
259 if ( stat->statusCode ) {
260 printf("ERROR: LALDestroyVector returned status %d\n",stat->statusCode);
261 EXIT( LALRUNNINGMEDIANTESTC_ESUB, argv0, LALRUNNINGMEDIANTESTC_MSGESUB );
262 }
263 return(0);
264}
265
266
267
268
269int testSRunningMedian(LALStatus *stat, REAL4Sequence *input, UINT4 length,
271/* Test the LALSRunningMedian (REAL4Sequence) function by
272 comparing the reults to individually calculated medians */
273
274 REAL4 median;
275 REAL4Sequence *medians=NULL;
276 struct rngmed_val_index *index_block;
277 UINT4 i,k;
278
279 /* create medians vector */
280 LALSCreateVector( stat, &medians, input->length - param.blocksize + 1 );
281 if( stat->statusCode){
282 printf("ERROR: LALDCreateVector returned status %d\n",stat->statusCode);
283 EXIT( LALRUNNINGMEDIANTESTC_ESUB, argv0, LALRUNNINGMEDIANTESTC_MSGESUB );
284 }
285
286 /* call running median */
287 if (bmimpl)
288 LALSRunningMedian2( stat, medians, input, param );
289 else
290 LALSRunningMedian( stat, medians, input, param );
291 if ( stat->statusCode ) {
292 printf("ERROR: LALRunningMedian returned status %d\n",stat->statusCode);
293 EXIT( LALRUNNINGMEDIANTESTC_ESUB, argv0, LALRUNNINGMEDIANTESTC_MSGESUB );
294 }
295
296 /* write the vectors if verbose */
297 if ( verbose ) {
298 LALSPrintVector(input);
299 LALSPrintVector(input);
300 }
301
302 /* allocate memory for calculating single medians */
303 index_block = (struct rngmed_val_index *)LALCalloc(param.blocksize, sizeof(struct rngmed_val_index));
304 if(!index_block) {
305 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
306 }
307
308 /* compare all medians */
309 for(i=0;i<length-param.blocksize+1;i++) {
310
311 /* prepare array for sort */
312 for(k=0;k<param.blocksize;k++){
313 index_block[k].data=input->data[k+i];
314 index_block[k].index=k;
315 }
316
317 /* sort */
318 qsort(index_block, param.blocksize, sizeof(struct rngmed_val_index),rngmed_sortindex);
319
320 /* find median */
321 if(param.blocksize%2==1)
322 median = index_block[(param.blocksize-1)/2].data;
323 else
324 median = (index_block[param.blocksize/2-1].data+index_block[param.blocksize/2].data)/2;
325
326 /* compare results */
327 if(compare_single(median,medians->data[i])) {
328 printf("ERROR: index:%d median:%f running median:%f mismatch\n", i, median, medians->data[i]);
329 LALFree(index_block);
330 LALFree(medians);
331 LALFree(input);
332 EXIT( LALRUNNINGMEDIANTESTC_EFALSE, argv0, LALRUNNINGMEDIANTESTC_MSGEFALSE );
333 }
334 }
335
336 LALFree(index_block);
337 LALSDestroyVector(stat,&medians);
338 if ( stat->statusCode ) {
339 printf("ERROR: LALDestroyVector returned status %d\n",stat->statusCode);
340 EXIT( LALRUNNINGMEDIANTESTC_ESUB, argv0, LALRUNNINGMEDIANTESTC_MSGESUB );
341 }
342 return(0);
343}
344
345
346
347
348
349/**************
350 **** MAIN ****
351 **************/
352
353
354int main( int argc, char **argv )
355{
356 LALStatus stat;
357 UINT4 blocksize = 512, length = 1024;
358 REAL4Sequence *input4=NULL;
359 REAL8Sequence *input8=NULL;
361 UINT4 i;
362 BOOLEAN verbose = 0;
363
364
365 /* set global program name */
366 argv0 = argv[0];
367
368 /* init status pointer */
369 memset(&stat, 0, sizeof(LALStatus));
370
371 /* init param structure */
372 memset(&param, 0, sizeof(param));
373
374
375 /* Parse input line. */
376 if ( argc >= 3 ) {
377 length = atoi(argv[1]);
378 blocksize = atoi(argv[2]);
379 }
380 if ( argc == 4 ) {
381 verbose = 1;
382 }
383 if (blocksize <= 3){
384 fprintf(stderr,"blocksize must be >3\n");
385 EXIT( LALRUNNINGMEDIANTESTC_EARG, argv0, LALRUNNINGMEDIANTESTC_MSGEARG );
386 }
387 if (blocksize > length){
388 fprintf(stderr,"blocksize must be <= length\n");
389 EXIT( LALRUNNINGMEDIANTESTC_EARG, argv0, LALRUNNINGMEDIANTESTC_MSGEARG );
390 }
391
392 /* create test input */
393 LALSCreateVector( &stat, &input4, length );
394 if( stat.statusCode ) {
395 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
396 }
397 LALDCreateVector( &stat, &input8, length );
398 if( stat.statusCode ) {
399 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
400 }
401 for(i=0;i<length;i++)
402 input4->data[i] = (input8->data[i] = (double)rand()/(double)RAND_MAX);
403
404
405 /* test error conditions */
406
407 REAL4Sequence *medians4=NULL;
408 REAL8Sequence *medians8=NULL;
409
410
411 /* create median vectors */
412 LALDCreateVector( &stat, &medians8, length - blocksize + 1 );
413 if( stat.statusCode ) {
414 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
415 }
416 LALSCreateVector( &stat, &medians4, length - blocksize + 1 );
417 if( stat.statusCode ) {
418 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
419 }
420
421 /* blocksize = 0 checks */
422
423 memset(&stat, 0, sizeof(LALStatus));
424 LALSRunningMedian(&stat,medians4,input4,param);
426 printf(" PASS: LALSRunningMedian blocksize =0 results in error\n");
427 } else {
428 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
429 }
430
431 memset(&stat, 0, sizeof(LALStatus));
432 LALDRunningMedian(&stat,medians8,input8,param);
434 printf(" PASS: LALDRunningMedian blocksize =0 results in error\n");
435 } else {
436 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
437 }
438
439
440 /* blocksize = 2 checks */
441
442 param.blocksize = 2;
443
444 memset(&stat, 0, sizeof(LALStatus));
445 LALSRunningMedian(&stat,medians4,input4,param);
447 printf(" PASS: LALSRunningMedian blocksize =2 results in error\n");
448 } else {
449 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
450 }
451
452 memset(&stat, 0, sizeof(LALStatus));
453 LALDRunningMedian(&stat,medians8,input8,param);
455 printf(" PASS: LALDRunningMedian blocksize =2 results in error\n");
456 } else {
457 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
458 }
459
460
461 /* blocksize too large checks */
462
463 param.blocksize = length+1;
464
465 memset(&stat, 0, sizeof(LALStatus));
466 LALSRunningMedian(&stat,medians4,input4,param);
468 printf(" PASS: LALSRunningMedian blocksize > input length results in error\n");
469 } else {
470 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
471 }
472
473 memset(&stat, 0, sizeof(LALStatus));
474 LALDRunningMedian(&stat,medians8,input8,param);
476 printf(" PASS: LALDRunningMedian blocksize > input length results in error\n");
477 } else {
478 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
479 }
480
481
482
483 /* now set the blocksize corretly for the rest of the program */
484 param.blocksize = blocksize;
485
486
487 /* NULL pointer input check */
488
489 memset(&stat, 0, sizeof(LALStatus));
490 LALSRunningMedian(&stat,medians4,NULL,param);
492 printf(" PASS: LALSRunningMedian NULL input results in error\n");
493 } else {
494 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
495 }
496
497 memset(&stat, 0, sizeof(LALStatus));
498 LALDRunningMedian(&stat,medians8,NULL,param);
500 printf(" PASS: LALDRunningMedian NULL input results in error\n");
501 } else {
502 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
503 }
504
505 /* median array size checks */
506 memset(&stat, 0, sizeof(LALStatus));
507 LALSRunningMedian(&stat,NULL,input4,param);
509 printf(" PASS: LALSRunningMedian NULL medians results in error\n");
510 } else {
511 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
512 }
513
514 memset(&stat, 0, sizeof(LALStatus));
515 LALDRunningMedian(&stat,NULL,input8,param);
517 printf(" PASS: LALDRunningMedian NULL medians results in error\n");
518 } else {
519 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
520 }
521
522 /* destroy median test vectors */
523 LALDDestroyVector(&stat,&medians8);
524 if( stat.statusCode ) {
525 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
526 }
527 LALSDestroyVector(&stat,&medians4);
528 if( stat.statusCode ) {
529 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
530 }
531
532 /* test median vectors with wrong size */
533
534
535 /* too small by one */
536
537 LALSCreateVector( &stat, &medians4, length - blocksize );
538 if( stat.statusCode ) {
539 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
540 }
541
542 memset(&stat, 0, sizeof(LALStatus));
543 LALSRunningMedian(&stat,medians4,input4,param);
545 printf(" PASS: LALSRunningMedian with too small median array results in error\n");
546 } else {
547 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
548 }
549
550 LALSDestroyVector(&stat,&medians4);
551 if( stat.statusCode ) {
552 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
553 }
554
555 LALDCreateVector( &stat, &medians8, length - blocksize );
556 if( stat.statusCode ) {
557 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
558 }
559
560 memset(&stat, 0, sizeof(LALStatus));
561 LALDRunningMedian(&stat,medians8,input8,param);
563 printf(" PASS: LALDRunningMedian with too small median array results in error\n");
564 } else {
565 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
566 }
567
568 LALDDestroyVector(&stat,&medians8);
569 if( stat.statusCode ) {
570 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
571 }
572
573
574 /* too large by one */
575
576 LALSCreateVector( &stat, &medians4, length - blocksize + 2);
577 if( stat.statusCode ) {
578 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
579 }
580
581 memset(&stat, 0, sizeof(LALStatus));
582 LALSRunningMedian(&stat,medians4,input4,param);
584 printf(" PASS: LALSRunningMedian with too large median array results in error\n");
585 } else {
586 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
587 }
588
589 LALSDestroyVector(&stat,&medians4);
590 if( stat.statusCode ) {
591 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
592 }
593
594 LALDCreateVector( &stat, &medians8, length - blocksize + 2);
595 if( stat.statusCode ) {
596 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
597 }
598
599 memset(&stat, 0, sizeof(LALStatus));
600 LALDRunningMedian(&stat,medians8,input8,param);
602 printf(" PASS: LALDRunningMedian with too large median array results in error\n");
603 } else {
604 EXIT( LALRUNNINGMEDIANTESTC_EERR, argv0, LALRUNNINGMEDIANTESTC_MSGEERR );
605 }
606
607 LALDDestroyVector(&stat,&medians8);
608 if( stat.statusCode ) {
609 EXIT( LALRUNNINGMEDIANTESTC_EALOC, argv0, LALRUNNINGMEDIANTESTC_MSGEALOC );
610 }
611
612
613 /* finaly restore status after checking error conditions */
614 memset(&stat, 0, sizeof(LALStatus));
615
616
617 /* test normal operation */
618
619 if(testDRunningMedian(&stat,input8,length,param,verbose,0)) {
620 EXIT( LALRUNNINGMEDIANTESTC_EFALSE, argv0, LALRUNNINGMEDIANTESTC_MSGEFALSE );
621 } else {
622 printf(" PASS: LALDRunningMedian(%d,%d)\n",length,param.blocksize);
623 }
624
625 if(testSRunningMedian(&stat,input4,length,param,verbose,0)) {
626 EXIT( LALRUNNINGMEDIANTESTC_EFALSE, argv0, LALRUNNINGMEDIANTESTC_MSGEFALSE );
627 } else {
628 printf(" PASS: LALSRunningMedian(%d,%d)\n",length,param.blocksize);
629 }
630
631 /* decrement the blocksize for the next two test to check for even/odd errors */
632 param.blocksize--;
633
634 if(testDRunningMedian(&stat,input8,length,param,verbose,0)) {
635 EXIT( LALRUNNINGMEDIANTESTC_EFALSE, argv0, LALRUNNINGMEDIANTESTC_MSGEFALSE );
636 } else {
637 printf(" PASS: LALDRunningMedian(%d,%d)\n",length,param.blocksize);
638 }
639
640 if(testSRunningMedian(&stat,input4,length,param,verbose,0)) {
641 EXIT( LALRUNNINGMEDIANTESTC_EFALSE, argv0, LALRUNNINGMEDIANTESTC_MSGEFALSE );
642 } else {
643 printf(" PASS: LALSRunningMedian(%d,%d)\n",length,param.blocksize);
644 }
645
646 if(testDRunningMedian(&stat,input8,length,param,verbose,1)) {
647 EXIT( LALRUNNINGMEDIANTESTC_EFALSE, argv0, LALRUNNINGMEDIANTESTC_MSGEFALSE );
648 } else {
649 printf(" PASS: LALDRunningMedian2(%d,%d)\n",length,param.blocksize);
650 }
651
652 if(testSRunningMedian(&stat,input4,length,param,verbose,1)) {
653 EXIT( LALRUNNINGMEDIANTESTC_EFALSE, argv0, LALRUNNINGMEDIANTESTC_MSGEFALSE );
654 } else {
655 printf(" PASS: LALSRunningMedian2(%d,%d)\n",length,param.blocksize);
656 }
657
658 /* decrement the blocksize for the next two test to check for even/odd errors */
659 param.blocksize--;
660
661 if(testDRunningMedian(&stat,input8,length,param,verbose,1)) {
662 EXIT( LALRUNNINGMEDIANTESTC_EFALSE, argv0, LALRUNNINGMEDIANTESTC_MSGEFALSE );
663 } else {
664 printf(" PASS: LALDRunningMedian2(%d,%d)\n",length,param.blocksize);
665 }
666
667 if(testSRunningMedian(&stat,input4,length,param,verbose,1)) {
668 EXIT( LALRUNNINGMEDIANTESTC_EFALSE, argv0, LALRUNNINGMEDIANTESTC_MSGEFALSE );
669 } else {
670 printf(" PASS: LALSRunningMedian2(%d,%d)\n",length,param.blocksize);
671 }
672
673
674 /* free dummy input memory */
675 LALDDestroyVector(&stat,&input8);
676 LALSDestroyVector(&stat,&input4);
677
678 /* check for memory leaks */
680
681 /* report status if wanted */
682 if(lalDebugLevel)
683 REPORTSTATUS(&stat);
684
685 /* nominal exit */
686 EXIT( LALRUNNINGMEDIANTESTC_ENOM, argv0, LALRUNNINGMEDIANTESTC_MSGENOM );
687}
688/** \endcond */
void REPORTSTATUS(LALStatus *status)
Definition: LALError.c:322
void LALCheckMemoryLeaks(void)
Definition: LALMalloc.c:784
#define LALCalloc(m, n)
Definition: LALMalloc.h:94
#define LALFree(p)
Definition: LALMalloc.h:96
#define LALRUNNINGMEDIANTESTC_ENOM
Nominal exit.
#define LALRUNNINGMEDIANTESTC_EARG
Error parsing command-line arguments.
#define LALRUNNINGMEDIANTESTC_EERR
Subroutine returned wrong or no error.
#define LALRUNNINGMEDIANTESTC_EFALSE
Medians mismatch.
#define LALRUNNINGMEDIANTESTC_ESUB
Subroutine returned error.
#define LALRUNNINGMEDIANTESTC_EALOC
Could not allocate data space.
#define fprintf
int main(int argc, char *argv[])
Definition: cache.c:25
#define LAL_REAL8_EPS
Difference between 1 and the next resolvable REAL8 2^-52.
Definition: LALConstants.h:61
#define LAL_REAL4_MIN
Smallest normalized REAL4 number 2^-126.
Definition: LALConstants.h:56
#define LAL_REAL8_MIN
Smallest normalized REAL8 number 2^-1022.
Definition: LALConstants.h:60
#define LAL_REAL4_EPS
Difference between 1 and the next resolvable REAL4 2^-23.
Definition: LALConstants.h:57
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 REAL8
Double precision real floating-point number (8 bytes).
uint32_t UINT4
Four-byte unsigned integer.
float REAL4
Single precision real floating-point number (4 bytes).
#define lalDebugLevel
Definition: LALDebugLevel.h:58
void LALSRunningMedian(LALStatus *status, REAL4Sequence *medians, const REAL4Sequence *input, LALRunningMedianPar param)
See LALRunningMedian_h for documentation.
void LALDRunningMedian(LALStatus *status, REAL8Sequence *medians, const REAL8Sequence *input, LALRunningMedianPar param)
See LALRunningMedian_h for documentation.
#define LALRUNNINGMEDIANH_ENULL
Invalid input: NULL pointer.
void LALDRunningMedian2(LALStatus *status, REAL8Sequence *medians, const REAL8Sequence *input, LALRunningMedianPar param)
See LALRunningMedian_h for documentation.
#define LALRUNNINGMEDIANH_ELARGE
Invalid input: block length larger than imput length.
#define LALRUNNINGMEDIANH_EZERO
Invalid input: block length must be >2.
void LALSRunningMedian2(LALStatus *status, REAL4Sequence *medians, const REAL4Sequence *input, LALRunningMedianPar param)
See LALRunningMedian_h for documentation.
#define LALRUNNINGMEDIANH_EIMED
Invalid input: wrong size of median array.
void LALDPrintVector(REAL8Vector *vector)
void LALSPrintVector(REAL4Vector *vector)
void LALDCreateVector(LALStatus *, REAL8Vector **, UINT4)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void LALSDestroyVector(LALStatus *, REAL4Vector **)
void LALSCreateVector(LALStatus *, REAL4Vector **, UINT4)
This is the parameter structure for the LALRunningMedian functions.
UINT4 blocksize
the number of elements a single median is calculated from
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
INT4 statusCode
A numerical code identifying the type of error, or 0 for nominal status; Negative values are reserved...
Definition: LALDatatypes.h:948
Vector of type REAL4, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:145
REAL4 * data
Pointer to the data array.
Definition: LALDatatypes.h:150
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:149
Vector of type REAL8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:154
REAL8 * data
Pointer to the data array.
Definition: LALDatatypes.h:159
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:158
int verbose
Definition: tconvert.c:103