VIRCAM Pipeline  2.3.12
casu_stats-test.c
1 /* $Id: casu_stats-test.c,v 1.2 2015/08/07 13:06:54 jim Exp $
2  *
3  * This file is part of the CASU Pipeline utilities
4  * Copyright (C) 2015 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: jim $
23  * $Date: 2015/08/07 13:06:54 $
24  * $Revision: 1.2 $
25  * $Name: $
26  */
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 
31 #include <cpl_init.h>
32 #include <cpl_test.h>
33 #include <casu_fits.h>
34 #include <casu_utils.h>
35 #include <casu_mods.h>
36 #include <casu_stats.h>
37 
38 int main(void) {
39  float *data,val,mad;
40  double *ddata,dval;
41  unsigned char *bpm;
42  int i;
43  long npts;
44 
45  /* Initialise */
46 
47  cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
48 
49  /* Get some workspace for arrays */
50 
51  data = cpl_malloc(21*sizeof(float));
52  ddata = cpl_malloc(21*sizeof(double));
53  bpm = cpl_calloc(21,sizeof(unsigned char));
54  for (i = 0; i < 21; i++) {
55  data[20-i] = (float)i - 10.0;
56  ddata[20-i] = (double)i - 10.0;
57  }
58  npts = 21;
59 
60  /* Test median routines */
61 
62  val = casu_med(data,bpm,npts);
63  cpl_test_rel(val,0.0,0.001);
64  dval = casu_dmed(ddata,bpm,npts);
65  cpl_test_rel(dval,0.0,0.001);
66  bpm[0] = 1;
67  bpm[1] = 1;
68  val = casu_med(data,bpm,npts);
69  cpl_test_rel(val,-1.0,0.001);
70  dval = casu_dmed(ddata,bpm,npts);
71  cpl_test_rel(dval,-1.0,0.001);
72  bpm[0] = 0;
73  bpm[1] = 0;
74 
75  /* Test casu_medmad */
76 
77  casu_medmad(data,bpm,npts,&val,&mad);
78  cpl_test_rel(val,0.0,0.001);
79  cpl_test_rel(mad,5.0,0.001);
80 
81  /* Test casu_medmadcut */
82 
83  casu_medmadcut(data,bpm,npts,-11.0,9,&val,&mad);
84  cpl_test_rel(val,-0.5,0.001);
85  cpl_test_rel(mad,5.0,0.001);
86 
87  /* Test mean routines */
88 
89  val = casu_mean(data,bpm,npts);
90  cpl_test_rel(val,0.0,0.001);
91  dval = casu_dmean(ddata,bpm,npts);
92  cpl_test_rel(dval,0.0,0.001);
93  bpm[0] = 1;
94  bpm[1] = 1;
95  val = casu_mean(data,bpm,npts);
96  cpl_test_rel(val,-1.0,0.01);
97  dval = casu_dmean(ddata,bpm,npts);
98  cpl_test_rel(dval,-1.0,0.01);
99  bpm[0] = 0;
100  bpm[1] = 0;
101 
102  /* Test casu_meansig and casu_medsig */
103 
104  casu_meansig(data,bpm,npts,&val,&mad);
105  cpl_test_rel(val,0.0,0.01);
106  cpl_test_rel(mad,6.0553,0.01);
107  casu_medsig(data,bpm,npts,&val,&mad);
108  cpl_test_rel(val,0.0,0.01);
109  cpl_test_rel(mad,6.0553,0.01);
110 
111  /* Finally test casu_sumbpm */
112 
113  casu_sumbpm(bpm,npts,&i);
114  cpl_test_eq(i,0);
115 
116  /* Tidy and exit */
117 
118  cpl_free(data);
119  cpl_free(ddata);
120  cpl_free(bpm);
121  return(cpl_test_end(0));
122 }
123 
124 /*
125 
126 $Log: casu_stats-test.c,v $
127 Revision 1.2 2015/08/07 13:06:54 jim
128 Fixed copyright to ESO
129 
130 Revision 1.1.1.1 2015/06/12 10:44:32 jim
131 Initial import
132 
133 Revision 1.2 2015/01/29 11:56:18 jim
134 Added medmadcut test
135 
136 Revision 1.1 2015/01/09 11:39:55 jim
137 new entry
138 
139 
140 */
double casu_dmean(double *data, unsigned char *bpm, long npts)
Definition: casu_stats.c:534
void casu_medmad(float *data, unsigned char *bpm, long np, float *med, float *mad)
Definition: casu_stats.c:347
float casu_med(float *data, unsigned char *bpm, long npts)
Definition: casu_stats.c:89
void casu_medsig(float *data, unsigned char *bpm, long np, float *med, float *sig)
Definition: casu_stats.c:672
float casu_mean(float *data, unsigned char *bpm, long npts)
Definition: casu_stats.c:479
double casu_dmed(double *data, unsigned char *bpm, long npts)
Definition: casu_stats.c:170
int casu_sumbpm(unsigned char *bpm, long npts, int *sumb)
Definition: casu_stats.c:738
void casu_medmadcut(float *data, unsigned char *bpm, long np, float lcut, float hcut, float *med, float *mad)
Definition: casu_stats.c:406
int casu_meansig(float *data, unsigned char *bpm, long npts, float *mean, float *sig)
Definition: casu_stats.c:595