VIRCAM Pipeline  2.3.12
casu_match-test.c
1 /* $Id: casu_match-test.c,v 1.3 2015/10/08 10:05:47 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/10/08 10:05:47 $
24  * $Revision: 1.3 $
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 
37 int main(void) {
38  int status,retval,i,nm;
39  cpl_table *progtab,*temptab,*outtab;
40  float *xptr,*yptr,xoff,yoff;
41  float offx[20] = {0.10,-0.07,0.03,0.21,-0.15,-0.02,-0.08,0.11,0.13,-0.16,
42  0.01,-0.18,0.20,-0.14,-0.10,0.08,0.12,-0.05,0.04,-0.06};
43  float offy[20] = {0.01,-0.18,0.20,-0.14,-0.10,0.08,0.12,-0.05,0.04,-0.06,
44  0.10,-0.07,0.03,0.21,-0.15,-0.02,-0.08,0.11,0.13,-0.16};
45  /* Initialise */
46 
47  cpl_test_init(PACKAGE_BUGREPORT,CPL_MSG_WARNING);
48 
49  /* Do casu_matchxy first. Start by creating some tables */
50 
51  progtab = cpl_table_new(20);
52  cpl_table_new_column(progtab,"X_coordinate",CPL_TYPE_FLOAT);
53  cpl_table_new_column(progtab,"Y_coordinate",CPL_TYPE_FLOAT);
54  xptr = cpl_table_get_data_float(progtab,"X_coordinate");
55  yptr = cpl_table_get_data_float(progtab,"Y_coordinate");
56  for (i = 0; i < 20; i++) {
57  xptr[i] = (float)(i*(i+1));
58  yptr[i] = (float)(i*(i-1));
59  }
60  temptab = cpl_table_new(20);
61  cpl_table_new_column(temptab,"X_coordinate",CPL_TYPE_FLOAT);
62  cpl_table_new_column(temptab,"Y_coordinate",CPL_TYPE_FLOAT);
63  xptr = cpl_table_get_data_float(temptab,"X_coordinate");
64  yptr = cpl_table_get_data_float(temptab,"Y_coordinate");
65  for (i = 0; i < 20; i++) {
66  xptr[i] = (float)(i*(i+1)) + 50.0 + offx[i];
67  yptr[i] = (float)(i*(i-1)) - 40.0 + offy[i];
68  }
69 
70  /* Test inherited status */
71 
72  status = CASU_FATAL;
73  retval = casu_matchxy(progtab,temptab,10,&xoff,&yoff,&nm,&outtab,&status);
74  cpl_test_eq(status,CASU_FATAL);
75  cpl_test_eq(status,retval);
76  cpl_test_eq(xoff,0.0);
77  cpl_test_eq(yoff,0.0);
78  cpl_test_eq(nm,0);
79  cpl_test_null(outtab);
80 
81  /* Now test to see if you get the right match */
82 
83  status = CASU_OK;
84  retval = casu_matchxy(progtab,temptab,20,&xoff,&yoff,&nm,&outtab,&status);
85  cpl_test_eq(status,CASU_OK);
86  cpl_test_eq(status,retval);
87  cpl_test_rel(xoff,50.0,0.01);
88  cpl_test_rel(yoff,-40.0,0.01);
89  cpl_test_eq(nm,20);
90  cpl_test_nonnull(outtab);
91  cpl_test_eq(cpl_table_get_ncol(outtab),4);
92  cpl_table_delete(outtab);
93 
94  /* Now add some columns to the prog table to simulate it being an
95  imcore table. */
96 
97  cpl_table_new_column(progtab,"RA",CPL_TYPE_FLOAT);
98  cpl_table_new_column(progtab,"DEC",CPL_TYPE_FLOAT);
99  cpl_table_new_column(progtab,"FLUX1",CPL_TYPE_FLOAT);
100  cpl_table_new_column(progtab,"FLUX2",CPL_TYPE_FLOAT);
101  cpl_table_name_column(temptab,"X_coordinate","xpredict");
102  cpl_table_name_column(temptab,"Y_coordinate","ypredict");
103  status = CASU_FATAL;
104  retval = casu_matchstds(progtab,temptab,10,&outtab,&status);
105  cpl_test_eq(status,CASU_FATAL);
106  cpl_test_eq(status,retval);
107  cpl_test_null(outtab);
108  status = CASU_OK;
109  retval = casu_matchstds(progtab,temptab,10,&outtab,&status);
110  cpl_test_eq(status,CASU_OK);
111  cpl_test_eq(status,retval);
112  cpl_test_nonnull(outtab);
113  cpl_test_eq(cpl_table_get_ncol(outtab),6);
114 
115  /* Tidy and exit */
116 
117  cpl_table_delete(progtab);
118  cpl_table_delete(temptab);
119  cpl_table_delete(outtab);
120  return(cpl_test_end(0));
121 }
122 
123 /*
124 
125 $Log: casu_match-test.c,v $
126 Revision 1.3 2015/10/08 10:05:47 jim
127 Modified the way we do positional errors
128 
129 Revision 1.2 2015/08/07 13:06:54 jim
130 Fixed copyright to ESO
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 */
int casu_matchstds(cpl_table *objtab, cpl_table *stdstab, float srad, cpl_table **outtab, int *status)
Match object and standard star tables by their xy coordinates.
Definition: casu_match.c:300
int casu_matchxy(cpl_table *progtab, cpl_table *template, float srad, float *xoffset, float *yoffset, int *nm, cpl_table **outtab, int *status)
Match two lists of x,y coordinates from two tables to find the cartesian offset between them.
Definition: casu_match.c:105