VIRCAM Pipeline 2.3.15
casu_filt-test.c
1/* $Id: casu_filt-test.c,v 1.3 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.3 $
25 * $Name: $
26 */
27
28#include <stdlib.h>
29#include <string.h>
30
31#include <cpl_init.h>
32#include <cpl_test.h>
33#include <casu_utils.h>
34#include <casu_filt.h>
35
36#define DATSZ 21
37
38static void initdata(float *data);
39/* static void spewdata(float *data); */
40
41int main(void) {
42 float *data;
43 unsigned char *bpm;
44 int nbpm,testpt;
45
46 /* Initialise */
47
48 cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
49
50 /* Get some data arrays */
51
52 data = cpl_malloc(DATSZ*DATSZ*sizeof(float));
53 bpm = cpl_calloc(DATSZ*DATSZ,sizeof(float));
54 nbpm = DATSZ*DATSZ/2;
55 testpt = nbpm + DATSZ;
56
57 /* Test mean calc with no bad pixels */
58
59 initdata(data);
60 casu_bfilt(data,bpm,DATSZ,DATSZ,5,MEANCALC,1);
61 /* spewdata(data); */
62 cpl_test_rel(data[testpt],111.0,1.0e-6);
63
64 /* Test median calc with no bad pixels */
65
66 initdata(data);
67 casu_bfilt(data,bpm,DATSZ,DATSZ,5,MEDIANCALC,1);
68 /* spewdata(data); */
69 cpl_test_rel(data[testpt],111.0,1.0e-6);
70
71 /* Test mean calc with a bad pixel in the middle */
72
73 initdata(data);
74 nbpm = DATSZ*DATSZ/2;
75 bpm[nbpm] = 1;
76 casu_bfilt(data,bpm,DATSZ,DATSZ,5,MEANCALC,1);
77 /* spewdata(data); */
78 cpl_test_rel(data[testpt],111.25,1.0e-6);
79
80 /* Test median calc with a bad pixel in the middle */
81
82 initdata(data);
83 memset(bpm,0,DATSZ*DATSZ);
84 bpm[nbpm] = 1;
85 casu_bfilt(data,bpm,DATSZ,DATSZ,5,MEDIANCALC,1);
86 cpl_test_rel(data[testpt],111.5,1.0e-6);
87 /* spewdata(data); */
88
89 /* Tidy and exit */
90
91 cpl_free(data);
92 cpl_free(bpm);
93 return(cpl_test_end(0));
94}
95
96static void initdata(float *data) {
97 int i,j,n,mid;
98 float val;
99
100 mid = DATSZ/2;
101
102 n = -1;
103 for (j = 0; j <= DATSZ-1; j++) {
104 for (i = 0; i <= DATSZ-1; i++) {
105 n++;
106 if (i >= mid-3 && i <= mid+3 && j >= mid-3 && j <= mid+3) {
107 val = i*10.0 + j;
108 } else {
109 val = (mid-4)*10.0;
110 }
111 data[n] = val;
112 }
113 }
114}
115
116/* static void spewdata(float *data) { */
117/* int i,j,n,mid; */
118/* float val; */
119
120/* mid = DATSZ/2; */
121
122/* n = -1; */
123/* for (j = 0; j <= DATSZ-1; j++) { */
124/* for (i = 0; i <= DATSZ-1; i++) { */
125/* n++; */
126/* val = data[n]; */
127/* fprintf(stderr,"%5.2f ",val); */
128/* } */
129/* fprintf(stderr,"\n"); */
130/* } */
131/* fprintf(stderr,"\n"); */
132/* } */
133
134/*
135
136$Log: casu_filt-test.c,v $
137Revision 1.3 2015/08/07 13:06:54 jim
138Fixed copyright to ESO
139
140Revision 1.2 2015/08/06 05:34:02 jim
141Fixes to get rid of compiler moans
142
143Revision 1.1.1.1 2015/06/12 10:44:32 jim
144Initial import
145
146Revision 1.2 2015/03/12 09:16:51 jim
147Modified to remove some compiler moans
148
149Revision 1.1 2014/03/26 15:31:29 jim
150New Entry
151
152
153*/