LAL  7.5.0.1-bede9b2
LALStatsREAL4Vector.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 David Churches, B.S. Sathyaprakash
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 <lal/LALNoiseModels.h>
21 
22 /**
23  * \author Sathyaprakash, B. S.
24  * \ingroup LALNoiseModels_h
25  * \brief Module to compute the mean, rms, minimum and maximum of a \c REAL4Vector.
26  *
27  */
28 void
30  (
33  REAL4Vector *vector
34  )
35 
36 {
37 
38  INT4 i, n;
39  REAL8 x;
40 
43 
44  ASSERT (vector->data, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
45  ASSERT (vector->length > 0, status, LALNOISEMODELSH_ECHOICE, LALNOISEMODELSH_MSGECHOICE);
46  ASSERT (out, status, LALNOISEMODELSH_ENULL, LALNOISEMODELSH_MSGENULL);
47 
48  out->mean = 0.;
49  out->var = 0.;
50  n = vector->length;
51  out->max = vector->data[0];
52  out->min = vector->data[0];
53 
54  for (i=0; i<n; i++)
55  {
56  x = vector->data[i];
57  if (out->max < x) out->max = x;
58  if (out->min > x) out->min = x;
59  out->mean+=x;
60  }
61  out->mean/=(REAL8) n;
62 
63  for (i=0; i<n; i++)
64  {
65  x = vector->data[i]-out->mean;
66  out->var+=x*x;
67  }
68  out->var /=(REAL8) n;
69  out->stddev = sqrt(out->var);
70 
72  RETURN(status);
73 }
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
double REAL8
Double precision real floating-point number (8 bytes).
int32_t INT4
Four-byte signed integer.
#define LALNOISEMODELSH_ENULL
Arguments contained an unexpected null pointer.
#define LALNOISEMODELSH_ECHOICE
Invalid choice for an input parameter.
void LALStatsREAL4Vector(LALStatus *status, StatsREAL4VectorOut *out, REAL4Vector *vector)
Module to compute the mean, rms, minimum and maximum of a REAL4Vector.
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
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