VIRCAM Pipeline  2.3.10
casu_mask-test.c
1 /* $Id: casu_mask-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 <stdio.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 
32 #include <cpl_init.h>
33 #include <cpl_test.h>
34 #include <casu_fits.h>
35 #include <casu_utils.h>
36 #include <casu_mods.h>
37 #include <casu_mask.h>
38 
39 int main(void) {
40  int retval,ok,i;
41  cpl_image *im;
42  cpl_frameset *frms;
43  cpl_frame *fr;
44  cpl_propertylist *phu,*ehu;
45  cpl_size *labels,nlab;
46  casu_mask *cm;
47  unsigned char *bpm;
48  const char *fname = "testmask.fit";
49 
50  /* Initialise */
51 
52  cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
53 
54  /* Create a dummy confidence map with two bad pixels at (1,1) and
55  at (2,1) */
56 
57  im = cpl_image_new(100,100,CPL_TYPE_INT);
58  cpl_image_fill_noise_uniform(im,95.0,105.0);
59  cpl_image_set(im,1,1,0.0);
60  cpl_image_set(im,2,1,0.0);
61  phu = cpl_propertylist_new();
62  ehu = cpl_propertylist_new();
63  if (access(fname,F_OK) == 0)
64  remove(fname);
65  cpl_image_save(NULL,fname,CPL_TYPE_UCHAR,phu,CPL_IO_DEFAULT);
66  cpl_image_save(im,fname,CPL_TYPE_INT,ehu,CPL_IO_EXTEND);
67  cpl_propertylist_delete(phu);
68  cpl_propertylist_delete(ehu);
69  cpl_image_delete(im);
70 
71  /* Create a frameset with this file in it. Labelise it */
72 
73  frms = cpl_frameset_new();
74  fr = cpl_frame_new();
75  cpl_frame_set_filename(fr,fname);
76  cpl_frame_set_tag(fr,"testconf");
77  cpl_frameset_insert(frms,fr);
78  labels = cpl_frameset_labelise(frms,casu_compare_tags,&nlab);
79 
80  /* Define the mask now and test the accessor routines */
81 
82  cm = casu_mask_define(frms,labels,nlab,"testconf","testbpm");
83  cpl_test_nonnull(cm);
84  cpl_test_eq_string(fname,casu_mask_get_filename(cm));
85  cpl_test_eq(casu_mask_get_type(cm),MASK_CPM);
86  cpl_free(labels);
87 
88  /* Load the mask and test the rest of the accessors */
89 
90  retval = casu_mask_load(NULL,1,-1,-1);
91  cpl_test_eq(retval,CASU_FATAL);
92  retval = casu_mask_load(cm,1,-1,-1);
93  cpl_test_eq(retval,CASU_OK);
94  cpl_test_nonnull(casu_mask_get_fits(cm));
95  cpl_test_eq(casu_mask_get_size_x(cm),100);
96  cpl_test_eq(casu_mask_get_size_y(cm),100);
97 
98  /* Get the data and make sure the values are correct. They should all
99  be zero except for the first two */
100 
101  bpm = casu_mask_get_data(cm);
102  cpl_test_nonnull(bpm);
103  ok = 1;
104  for (i = 0; i < 10000; i++) {
105  if (i < 2 && bpm[i] != 1) {
106  ok = 0;
107  break;
108  } else if (i >= 2 && bpm[i] != 0) {
109  ok = 0;
110  break;
111  }
112  }
113  cpl_test_eq(ok,1);
114 
115  /* Tidy and exit */
116 
117  casu_mask_delete(cm);
118  remove(fname);
119  cpl_frameset_delete(frms);
120  return(cpl_test_end(0));
121 }
122 
123 /*
124 
125 $Log: casu_mask-test.c,v $
126 Revision 1.3 2015/08/07 13:06:54 jim
127 Fixed copyright to ESO
128 
129 Revision 1.2 2015/08/06 05:34:02 jim
130 Fixes to get rid of compiler moans
131 
132 Revision 1.1.1.1 2015/06/12 10:44:32 jim
133 Initial import
134 
135 Revision 1.1 2015/01/09 11:39:55 jim
136 new entry
137 
138 
139 */
void casu_mask_delete(casu_mask *m)
Definition: casu_mask.c:276
unsigned char * casu_mask_get_data(casu_mask *m)
Definition: casu_mask.c:544
int casu_mask_get_size_y(casu_mask *m)
Definition: casu_mask.c:498
const char * casu_mask_get_filename(casu_mask *m)
Definition: casu_mask.c:447
int casu_mask_load(casu_mask *m, int nexten, int nx, int ny)
Definition: casu_mask.c:214
casu_mask * casu_mask_define(cpl_frameset *framelist, cpl_size *labels, cpl_size nlab, const char *conftag, const char *bpmtag)
Definition: casu_mask.c:89
int casu_mask_get_type(casu_mask *m)
Definition: casu_mask.c:521
casu_fits * casu_mask_get_fits(casu_mask *m)
Definition: casu_mask.c:424
int casu_mask_get_size_x(casu_mask *m)
Definition: casu_mask.c:475
int casu_compare_tags(const cpl_frame *frame1, const cpl_frame *frame2)
Compare input tags.
Definition: casu_utils.c:96