Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
StatisticsTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Badri Krishnan, Jolien Creighton, Alicia Sintes Olives
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 *
22 * File Name: TestStatistics.c
23 *
24 * Authors: Krishnan, B., Sintes, A.M.,
25 *
26 *
27 * History: Created by Badri Krishnan May 24, 2003
28 *
29 *
30 *-----------------------------------------------------------------------
31 */
32
33/**
34 * \author Krishnan, B., Sintes, A.M.
35 * \file
36 * \ingroup Statistics_h
37 * \brief Tests the statistics and the histogram number count of a given total Hough map.
38 *
39 * ### Program TestStatistics.c ###
40 *
41 *
42 * ### Usage ###
43 *
44 * \code
45 * TestStatistics [-d debuglevel] [-o outfile]
46 * \endcode
47 *
48 * ### Description ###
49 *
50 * This program creates a Hough map and ...
51 *
52 * The <b>-d</b> option sets the debug level to the specified value
53 * \c debuglevel. The <b>-o</b> flag tells the program to print the histogram
54 * of the Hough number counts to the specified data file \c outfile.
55 *
56 * ### Uses ###
57 *
58 * \code
59 * LALHoughStatistics()
60 * LALHoughHistogram()
61 * LALPrintError()
62 * LALMalloc()
63 * LALFree()
64 * LALCheckMemoryLeaks()
65 * \endcode
66 *
67 */
68
69#include <lal/LALStdio.h>
70#include <lal/Statistics.h>
71
72
73/**\name Error Codes */ /** @{ */
74#define TESTSTATISTICSC_ENORM 0
75#define TESTSTATISTICSC_ESUB 1
76#define TESTSTATISTICSC_EARG 2
77#define TESTSTATISTICSC_EBAD 3
78#define TESTSTATISTICSC_EFILE 4
79
80#define TESTSTATISTICSC_MSGENORM "Normal exit"
81#define TESTSTATISTICSC_MSGESUB "Subroutine failed"
82#define TESTSTATISTICSC_MSGEARG "Error parsing arguments"
83#define TESTSTATISTICSC_MSGEBAD "Bad argument values"
84#define TESTSTATISTICSC_MSGEFILE "Could not create output file"
85/** @} */
86
87/** \cond DONT_DOXYGEN */
88
89/* Default parameters. */
90
91#define FILEOUT "OutHistogram.asc" /* file output */
92
93/* Usage format string. */
94#define USAGE "Usage: %s [-d debuglevel] [-o outfile]\n"
95
96/*********************************************************************/
97/* Macros for printing errors & testing subroutines (from Creighton) */
98/*********************************************************************/
99
100#define ERROR( code, msg, statement ) \
101do { \
102 if ( lalDebugLevel & LALERROR ) \
103 XLALPrintError( "Error[0] %d: program %s, file %s, line %d, %s\n" \
104 " %s %s\n", (code), *argv, __FILE__, \
105 __LINE__, "$Id$", statement ? statement : \
106 "", (msg) ); \
107} while (0)
108
109#define INFO( statement ) \
110do { \
111 if ( lalDebugLevel & LALINFO ) \
112 XLALPrintError( "Info[0]: program %s, file %s, line %d, %s\n" \
113 " %s\n", *argv, __FILE__, __LINE__, \
114 "$Id$", (statement) ); \
115} while (0)
116
117#define SUB( func, statusptr ) \
118do { \
119 if ( (func), (statusptr)->statusCode ) { \
120 ERROR( TESTSTATISTICSC_ESUB, TESTSTATISTICSC_MSGESUB, \
121 "Function call \"" #func "\" failed:" ); \
122 return TESTSTATISTICSC_ESUB; \
123 } \
124} while (0)
125/******************************************************************/
126
127/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
128/* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv------------------------------------ */
129int main( int argc, char *argv[] )
130{
131
132 static LALStatus status;
133 static HOUGHMapTotal ht;
134 static HoughStats stats;
135 static UINT8Vector hist;
136
137 const CHAR *fname = NULL; /* The output filename */
138 INT4 arg; /* Argument counter */
139 INT4 i;
140 FILE *fp = NULL; /* Output file */
141
142 fname = FILEOUT;
143 /********************************************************/
144 /* Parse argument list. i stores the current position. */
145 /********************************************************/
146 arg = 1;
147 while ( arg < argc ) {
148 /* Parse debuglevel option. */
149 if ( !strcmp( argv[arg], "-d" ) ) {
150 if ( argc > arg + 1 ) {
151 arg++;
152 } else {
154 XLALPrintError( USAGE, *argv );
156 }
157 }
158 /* Parse output file option. */
159 else if ( !strcmp( argv[arg], "-o" ) ) {
160 if ( argc > arg + 1 ) {
161 arg++;
162 fname = argv[arg++];
163 } else {
165 XLALPrintError( USAGE, *argv );
167 }
168 }
169 /* Unrecognized option. */
170 else {
172 XLALPrintError( USAGE, *argv );
174 }
175 } /* End of argument parsing loop. */
176 /******************************************************************/
177
178 /* ------------------------------------------------------- */
179
180 /* create a hough map */
181 ht.mObsCoh = 1000;
182 ht.xSide = 100;
183 ht.ySide = 100;
184 /* allocate memory for hough map */
185 ht.map = ( HoughTT * )LALMalloc( ht.xSide * ht.ySide * sizeof( HoughTT ) );
186 /* make up a hough map */
187 for ( i = 0; i < floor( ht.xSide * ht.ySide / 2.0 ); i++ ) {
188 ht.map[i] = 500;
189 }
190 for ( i = ceil( ht.xSide * ht.ySide / 2.0 ); i < ht.xSide * ht.ySide; i++ ) {
191 ht.map[i] = 900;
192 }
193 SUB( LALHoughStatistics( &status, &stats, &ht ), &status );
194
195 printf( " Maximum number count: %d\n", ( int )stats.maxCount );
196 printf( " Location: %d %d\n", stats.maxIndex[0], stats.maxIndex[1] );
197 printf( " Minimum number count: %d\n", ( int )stats.minCount );
198 printf( " Location: %d %d\n", stats.minIndex[0], stats.minIndex[1] );
199 printf( " Average number count: %f\n", stats.avgCount );
200 printf( " Standard deviation of number count: %f\n", stats.stdDev );
201
202 /* allocate memory for histogram */
203
204 hist.length = ht.mObsCoh + 1;
205 hist.data = NULL;
206 hist.data = ( UINT8 * )LALMalloc( ( hist.length ) * sizeof( UINT8 ) );
207
208 SUB( LALHoughHistogram( &status, &hist, &ht ), &status );
209
210 /* write histogram to a file */
211 fp = fopen( fname, "w" );
212
213 if ( !fp ) {
216 }
217
218 for ( i = 0; i < ( INT4 )hist.length; i++ ) {
219 fprintf( fp, "%d %" LAL_UINT8_FORMAT "\n", i, hist.data[i] );
220 }
221
222
223 fclose( fp );
224 LALFree( ht.map );
225 LALFree( hist.data );
227
230}
231
232/* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
233
234/** \endcond */
#define SUB(func, statusptr)
#define ERROR(code, msg, statement)
#define INFO(statement)
void LALCheckMemoryLeaks(void)
#define LALMalloc(n)
#define LALFree(p)
#define TESTSTATISTICSC_MSGEARG
#define TESTSTATISTICSC_MSGEFILE
#define TESTSTATISTICSC_ENORM
#define TESTSTATISTICSC_MSGENORM
#define TESTSTATISTICSC_EARG
#define TESTSTATISTICSC_EFILE
#define fprintf
int main(int argc, char **argv)
REAL8 HoughTT
Total Hough Map pixel type.
Definition: HoughMap.h:113
uint64_t UINT8
char CHAR
int32_t INT4
#define LAL_UINT8_FORMAT
void LALHoughStatistics(LALStatus *status, HoughStats *out, HOUGHMapTotal *in)
This function calculates the maximum number count, minimum number count, average and standard deviati...
void LALHoughHistogram(LALStatus *status, UINT8Vector *out, HOUGHMapTotal *in)
Produces a histogram of the number counts in a total Hough map.
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define FILEOUT
This structure stores the Hough map.
Definition: HoughMap.h:130
UINT2 ySide
number of physical pixels in the y direction
Definition: HoughMap.h:142
UINT2 xSide
number of physical pixels in the x direction
Definition: HoughMap.h:141
HoughTT * map
the pixel counts; the number of elements to allocate is ySide*xSide
Definition: HoughMap.h:143
UINT4 mObsCoh
ratio of observation time and coherent timescale
Definition: HoughMap.h:133
Structure for storing statistical information about a Hough map.
UINT8 * data