2
* This file is part of the ESO SINFO Pipeline *
3
* Copyright (C) 2004,2005 European Southern Observatory *
5
* This library is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the Free Software *
17
* Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
22
* $Date: 2009-06-05 06:06:11 $
24
* $Name: not supported by cvs2svn $
28
/*-----------------------------------------------------------------------------
30
-----------------------------------------------------------------------------*/
36
#include<sinfo_absolute.h>
38
/*-----------------------------------------------------------------------------
40
-----------------------------------------------------------------------------*/
42
#define SQR(a) (sqrarg = (a) , sqrarg*sqrarg)
43
/*-----------------------------------------------------------------------------
45
-----------------------------------------------------------------------------*/
48
/*----------------------------------------------------------------------------*/
50
* @defgroup sinfo_absolute_test SINFO library unit tests
52
/*----------------------------------------------------------------------------*/
56
sinfo_test_edge(void){
58
/*Test all possible NULL param options */
60
float* parlist = NULL;
64
/* 1st test both null input: */
65
slope=sinfo_new_edge(NULL, NULL) ;
66
cpl_test_eq(slope, 0);
67
cpl_test_error(CPL_ERROR_NULL_INPUT);
69
parlist=cpl_calloc(ndat,sizeof(float)) ;
70
slope=sinfo_new_edge(NULL, parlist) ;
71
cpl_test_eq(slope, 0);
72
cpl_test_error(CPL_ERROR_NULL_INPUT);
74
xdat=cpl_calloc(ndat,sizeof(float)) ;
75
slope=sinfo_new_edge(xdat, NULL) ;
76
cpl_test_eq(slope, 0);
77
cpl_test_error(CPL_ERROR_NULL_INPUT);
80
/* For defined values we have the following cases:
84
* if ( xdat[0] <= parlist[0] ) return_parlist[2] ;
96
slope=sinfo_new_edge(xdat, parlist) ;
97
cpl_test_eq(slope, parlist[2]);
98
cpl_test_error(CPL_ERROR_NONE);
101
* if ( xdat[0] > parlist[1] ) return_parlist[3] ;
113
slope=sinfo_new_edge(xdat, parlist) ;
114
cpl_test_eq(slope, parlist[3]);
115
cpl_test_error(CPL_ERROR_NONE);
119
* if ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
120
return (xdat[0] - parlist[0]) * slope1 + parlist[2] ;
131
float slope1=( parlist[3] - parlist[2] ) / ( parlist[1] - parlist[0] ) ;
132
float result=(xdat[0] - parlist[0]) * slope1 + parlist[2] ;
133
slope=sinfo_new_edge(xdat, parlist) ;
134
cpl_test_eq(slope, result);
135
cpl_test_error(CPL_ERROR_NONE);
138
* else I think this case is never found!!
145
return cpl_error_get_code();
149
static cpl_error_code
150
sinfo_test_edge_deriv(void){
153
/*Test all possible NULL param options */
155
float* parlist = NULL;
160
/* 1st test both null input: */
161
sinfo_new_edge_deriv(NULL, NULL,NULL) ;
162
cpl_test_eq(slope, 0);
163
cpl_test_error(CPL_ERROR_NULL_INPUT);
165
parlist=cpl_calloc(ndat,sizeof(float)) ;
166
xdat=cpl_calloc(ndat,sizeof(float)) ;
167
dervs=cpl_calloc(ndat,sizeof(float)) ;
169
sinfo_new_edge_deriv(NULL, parlist,dervs) ;
170
cpl_test_eq(slope, 0);
171
cpl_test_error(CPL_ERROR_NULL_INPUT);
173
sinfo_new_edge_deriv(xdat, NULL,dervs) ;
174
cpl_test_eq(slope, 0);
175
cpl_test_error(CPL_ERROR_NULL_INPUT);
177
sinfo_new_edge_deriv(xdat, parlist,NULL) ;
178
cpl_test_eq(slope, 0);
179
cpl_test_error(CPL_ERROR_NULL_INPUT);
182
/* For defined values we have the following cases:
186
* if ( xdat[0] <= parlist[0] ) return
203
sinfo_new_edge_deriv(xdat, parlist,dervs) ;
204
cpl_test_eq(dervs[0], 0);
205
cpl_test_eq(dervs[1], 0);
206
cpl_test_eq(dervs[2], 1);
207
cpl_test_eq(dervs[3], 0);
208
cpl_test_error(CPL_ERROR_NONE);
212
* if ( xdat[0] > parlist[0] ) return
218
* if ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
219
return (xdat[0] - parlist[0]) * slope1 + parlist[2] ;
233
sinfo_new_edge_deriv(xdat, parlist,dervs) ;
234
cpl_test_eq(dervs[0], 0);
235
cpl_test_eq(dervs[1], 0);
236
cpl_test_eq(dervs[2], 0);
237
cpl_test_eq(dervs[3], 1);
238
cpl_test_error(CPL_ERROR_NONE);
242
* else if ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
244
dervs[0] = ( xdat[0] - parlist[1] ) * deriv1_slope1 ;
245
dervs[1] = ( parlist[0] - xdat[0] ) * deriv1_slope1 ;
246
dervs[2] = ( parlist[0] - xdat[0] ) / ( parlist[1] - parlist[0] ) + 1.;
247
dervs[3] = ( xdat[0] - parlist[0] ) / ( parlist[1] - parlist[0] ) ;
259
float deriv_slope1 =( parlist[3] - parlist[2] ) / SQR(parlist[1] - parlist[0]) ;
260
float* result=cpl_calloc(ndat,sizeof(float)) ;
261
result[0] = ( xdat[0] - parlist[1] ) * deriv_slope1 ;
262
result[1] = ( parlist[0] - xdat[0] ) * deriv_slope1 ;
263
result[2] = ( parlist[0] - xdat[0] ) / ( parlist[1] - parlist[0] ) + 1.;
264
result[3] = ( xdat[0] - parlist[0] ) / ( parlist[1] - parlist[0] ) ;
266
sinfo_new_edge_deriv(xdat, parlist,dervs) ;
268
cpl_test_eq(dervs[0], result[0]);
269
cpl_test_eq(dervs[1], result[1]);
270
cpl_test_eq(dervs[2], result[2]);
271
cpl_test_eq(dervs[3], result[3]);
275
cpl_test_error(CPL_ERROR_NONE);
278
* else I think this case is never found!!
287
return cpl_error_get_code();
292
static cpl_error_code
293
sinfo_test_lsqfit_edge(void){
297
sinfo_new_lsqfit_edge ( float * xdat,
310
return cpl_error_get_code();
313
static cpl_error_code
314
sinfo_test_fit_slits_edge(void){
317
sinfo_new_fit_slits_edge( cpl_image * lineImage,
319
float ** sinfo_slit_pos,
325
return cpl_error_get_code();
328
static cpl_error_code
329
sinfo_test_fit_slits_edge_with_estimate(void){
336
sinfo_new_fit_slits_edge_with_estimate ( cpl_image * lineImage,
337
float ** sinfo_slit_pos,
345
return cpl_error_get_code();
348
/* NOT USED FUNCTIONS
350
sinfo_new_hat1 ( float * xdat, float * parlist)
352
sinfo_new_hat_deriv1( float * xdat, float * parlist,
355
sinfo_new_hat_deriv2(float * xdat, float * parlist,
359
sinfo_new_hat2 ( float * xdat, float * parlist)
362
sinfo_new_fit_slits1( cpl_image * lineImage,
364
float ** sinfo_slit_pos,
371
/*----------------------------------------------------------------------------*/
373
@brief SINFONI pipeline unit test for skycor
376
/*----------------------------------------------------------------------------*/
380
/* Initialize CPL + SINFO messaging */
381
cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
384
sinfo_test_edge_deriv();
387
sinfo_test_lsqfit_edge();
388
sinfo_test_fit_slits_edge();
389
sinfo_test_fit_slits_edge_with_estimate();
392
cpl_test_error(CPL_ERROR_NONE);
393
return cpl_test_end(0);