~ubuntu-branches/debian/sid/cpl-plugin-sinfo/sid

« back to all changes in this revision

Viewing changes to sinfoni/tests/sinfo_absolute_test.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2015-09-23 11:21:27 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: package-import@ubuntu.com-20150923112127-7btl00mgr881g759
Tags: upstream-2.6.8+dfsg
ImportĀ upstreamĀ versionĀ 2.6.8+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*                                                                            *
 
2
 *   This file is part of the ESO SINFO Pipeline                              *
 
3
 *   Copyright (C) 2004,2005 European Southern Observatory                    *
 
4
 *                                                                            *
 
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.                                      *
 
9
 *                                                                            *
 
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.                             *
 
14
 *                                                                            *
 
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     *
 
18
 *                                                                           */
 
19
 
 
20
/*
 
21
 * $Author: amodigli $
 
22
 * $Date: 2009-06-05 06:06:11 $
 
23
 * $Revision: 1.5 $
 
24
 * $Name: not supported by cvs2svn $
 
25
 *
 
26
 */
 
27
 
 
28
/*-----------------------------------------------------------------------------
 
29
                                Includes
 
30
 -----------------------------------------------------------------------------*/
 
31
 
 
32
#ifdef HAVE_CONFIG_H
 
33
#  include <config.h>
 
34
#endif
 
35
#include<sinfo_msg.h>
 
36
#include<sinfo_absolute.h>
 
37
#include <cpl.h>
 
38
/*-----------------------------------------------------------------------------
 
39
                                Defines
 
40
 -----------------------------------------------------------------------------*/
 
41
static float  sqrarg ;
 
42
#define SQR(a) (sqrarg = (a) , sqrarg*sqrarg)
 
43
/*-----------------------------------------------------------------------------
 
44
                            Functions prototypes
 
45
 -----------------------------------------------------------------------------*/
 
46
 
 
47
 
 
48
/*----------------------------------------------------------------------------*/
 
49
/**
 
50
 * @defgroup sinfo_absolute_test  SINFO library unit tests
 
51
 */
 
52
/*----------------------------------------------------------------------------*/
 
53
/**@{*/
 
54
 
 
55
static cpl_error_code
 
56
sinfo_test_edge(void){
 
57
 
 
58
    /*Test all possible NULL param options */
 
59
    float* xdat = NULL;
 
60
    float* parlist = NULL;
 
61
    const int ndat=4;
 
62
    float slope=0;
 
63
 
 
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);
 
68
 
 
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);
 
73
 
 
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);
 
78
 
 
79
 
 
80
    /* For defined values we have the following cases:
 
81
     */
 
82
 
 
83
    /* case 1:
 
84
     * if ( xdat[0] <= parlist[0] ) return_parlist[2] ;
 
85
     * */
 
86
    xdat[0]=0;
 
87
    xdat[1]=1;
 
88
    xdat[2]=2;
 
89
    xdat[3]=3;
 
90
 
 
91
    parlist[0]=1;
 
92
    parlist[1]=2;
 
93
    parlist[2]=10;
 
94
    parlist[3]=20;
 
95
 
 
96
    slope=sinfo_new_edge(xdat, parlist) ;
 
97
    cpl_test_eq(slope, parlist[2]);
 
98
    cpl_test_error(CPL_ERROR_NONE);
 
99
 
 
100
    /* case 2:
 
101
     * if ( xdat[0] >  parlist[1] ) return_parlist[3] ;
 
102
     * */
 
103
    xdat[0]=3;
 
104
    xdat[1]=4;
 
105
    xdat[2]=5;
 
106
    xdat[3]=6;
 
107
 
 
108
    parlist[0]=1;
 
109
    parlist[1]=2;
 
110
    parlist[2]=10;
 
111
    parlist[3]=20;
 
112
 
 
113
    slope=sinfo_new_edge(xdat, parlist) ;
 
114
    cpl_test_eq(slope, parlist[3]);
 
115
    cpl_test_error(CPL_ERROR_NONE);
 
116
 
 
117
 
 
118
    /* case 3:
 
119
     *  if ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
 
120
           return (xdat[0] - parlist[0]) * slope1 + parlist[2] ;
 
121
       * */
 
122
      xdat[0]=1;
 
123
      xdat[1]=0.5;
 
124
      xdat[2]=2;
 
125
      xdat[3]=3;
 
126
 
 
127
      parlist[0]=0;
 
128
      parlist[1]=1;
 
129
      parlist[2]=10;
 
130
      parlist[3]=20;
 
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);
 
136
 
 
137
      /* case 4:
 
138
          *  else I think this case is never found!!
 
139
          * */
 
140
 
 
141
    /* free memory */
 
142
    cpl_free(xdat);
 
143
    cpl_free(parlist);
 
144
 
 
145
    return cpl_error_get_code();
 
146
 
 
147
}
 
148
 
 
149
static cpl_error_code
 
150
sinfo_test_edge_deriv(void){
 
151
 
 
152
 
 
153
    /*Test all possible NULL param options */
 
154
    float* xdat = NULL;
 
155
    float* parlist = NULL;
 
156
    float* dervs = NULL;
 
157
    const int ndat=4;
 
158
    float slope=0;
 
159
 
 
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);
 
164
 
 
165
    parlist=cpl_calloc(ndat,sizeof(float)) ;
 
166
    xdat=cpl_calloc(ndat,sizeof(float)) ;
 
167
    dervs=cpl_calloc(ndat,sizeof(float)) ;
 
168
 
 
169
    sinfo_new_edge_deriv(NULL, parlist,dervs) ;
 
170
    cpl_test_eq(slope, 0);
 
171
    cpl_test_error(CPL_ERROR_NULL_INPUT);
 
172
 
 
173
    sinfo_new_edge_deriv(xdat, NULL,dervs) ;
 
174
    cpl_test_eq(slope, 0);
 
175
    cpl_test_error(CPL_ERROR_NULL_INPUT);
 
176
 
 
177
    sinfo_new_edge_deriv(xdat, parlist,NULL) ;
 
178
    cpl_test_eq(slope, 0);
 
179
    cpl_test_error(CPL_ERROR_NULL_INPUT);
 
180
 
 
181
 
 
182
    /* For defined values we have the following cases:
 
183
     */
 
184
 
 
185
    /* case 1:
 
186
     * if ( xdat[0] <= parlist[0] ) return
 
187
     *  dervs[0] = 0. ;
 
188
        dervs[1] = 0. ;
 
189
        dervs[2] = 1. ;
 
190
        dervs[3] = 0. ;
 
191
     * ;
 
192
     * */
 
193
    xdat[0]=0;
 
194
    xdat[1]=1;
 
195
    xdat[2]=2;
 
196
    xdat[3]=3;
 
197
 
 
198
    parlist[0]=1;
 
199
    parlist[1]=2;
 
200
    parlist[2]=10;
 
201
    parlist[3]=20;
 
202
 
 
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);
 
209
 
 
210
 
 
211
    /* case 2:
 
212
     * if ( xdat[0] > parlist[0] ) return
 
213
     *  dervs[0] = 0. ;
 
214
        dervs[1] = 0. ;
 
215
        dervs[2] = 0. ;
 
216
        dervs[3] = 1. ;
 
217
 
 
218
     *  if ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
 
219
           return (xdat[0] - parlist[0]) * slope1 + parlist[2] ;
 
220
     * */
 
221
 
 
222
 
 
223
    xdat[0]=3;
 
224
    xdat[1]=4;
 
225
    xdat[2]=5;
 
226
    xdat[3]=6;
 
227
 
 
228
    parlist[0]=1;
 
229
    parlist[1]=2;
 
230
    parlist[2]=10;
 
231
    parlist[3]=20;
 
232
 
 
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);
 
239
 
 
240
 
 
241
    /* case 3:
 
242
     * else if ( xdat[0] > parlist[0] && xdat[0] <= parlist[1] )
 
243
            return:
 
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] ) ;
 
248
     * */
 
249
 
 
250
    xdat[0]=1;
 
251
    xdat[1]=0.5;
 
252
    xdat[2]=2;
 
253
    xdat[3]=3;
 
254
 
 
255
    parlist[0]=0;
 
256
    parlist[1]=1;
 
257
    parlist[2]=10;
 
258
    parlist[3]=20;
 
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] ) ;
 
265
 
 
266
    sinfo_new_edge_deriv(xdat, parlist,dervs) ;
 
267
 
 
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]);
 
272
 
 
273
 
 
274
 
 
275
    cpl_test_error(CPL_ERROR_NONE);
 
276
 
 
277
    /* case 4:
 
278
     *  else I think this case is never found!!
 
279
     * */
 
280
 
 
281
    /* free memory */
 
282
    cpl_free(xdat);
 
283
    cpl_free(parlist);
 
284
    cpl_free(dervs);
 
285
    cpl_free(result);
 
286
 
 
287
    return cpl_error_get_code();
 
288
}
 
289
 
 
290
 
 
291
 
 
292
static cpl_error_code
 
293
sinfo_test_lsqfit_edge(void){
 
294
 
 
295
    /*
 
296
    int
 
297
    sinfo_new_lsqfit_edge ( float * xdat,
 
298
                      int   * xdim,
 
299
                      float * ydat,
 
300
                      float * wdat,
 
301
                      int   * ndat,
 
302
                      float * fpar,
 
303
                      float * epar,
 
304
                      int   * mpar,
 
305
                      int   * npar,
 
306
                      float * tol ,
 
307
                      int   * its ,
 
308
                      float * lab  ) ;
 
309
                      */
 
310
    return cpl_error_get_code();
 
311
}
 
312
 
 
313
static cpl_error_code
 
314
sinfo_test_fit_slits_edge(void){
 
315
/*
 
316
    int
 
317
    sinfo_new_fit_slits_edge( cpl_image   * lineImage,
 
318
                      FitParams ** par,
 
319
                      float     ** sinfo_slit_pos,
 
320
                      int          box_length,
 
321
                      float        y_box,
 
322
                      float        diff_tol ) ;
 
323
                      */
 
324
 
 
325
    return cpl_error_get_code();
 
326
}
 
327
 
 
328
static cpl_error_code
 
329
sinfo_test_fit_slits_edge_with_estimate(void){
 
330
 
 
331
 
 
332
 
 
333
 
 
334
/*
 
335
    int
 
336
    sinfo_new_fit_slits_edge_with_estimate ( cpl_image   * lineImage,
 
337
                                    float    ** sinfo_slit_pos,
 
338
                                    int         box_length,
 
339
                                    float       y_box,
 
340
                                    float       diff_tol,
 
341
                                    int         low_pos,
 
342
                                    int         high_pos ) ;
 
343
                                    */
 
344
 
 
345
    return cpl_error_get_code();
 
346
}
 
347
 
 
348
/* NOT USED FUNCTIONS
 
349
float
 
350
sinfo_new_hat1 ( float * xdat, float * parlist)
 
351
void
 
352
sinfo_new_hat_deriv1( float * xdat, float * parlist,
 
353
                      float * dervs)
 
354
void
 
355
sinfo_new_hat_deriv2(float * xdat, float * parlist,
 
356
                     float * dervs)
 
357
 
 
358
float
 
359
sinfo_new_hat2 ( float * xdat, float * parlist)
 
360
 
 
361
int
 
362
sinfo_new_fit_slits1( cpl_image   * lineImage,
 
363
                      FitParams ** par,
 
364
                      float     ** sinfo_slit_pos,
 
365
                      int          box_length,
 
366
                      float        y_box )
 
367
 
 
368
 
 
369
*/
 
370
 
 
371
/*----------------------------------------------------------------------------*/
 
372
/**
 
373
  @brief   SINFONI pipeline unit test for skycor
 
374
 
 
375
**/
 
376
/*----------------------------------------------------------------------------*/
 
377
 
 
378
int main(void)
 
379
{
 
380
    /* Initialize CPL + SINFO messaging */
 
381
  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
 
382
  sinfo_test_edge();
 
383
 
 
384
  sinfo_test_edge_deriv();
 
385
 
 
386
/*
 
387
  sinfo_test_lsqfit_edge();
 
388
  sinfo_test_fit_slits_edge();
 
389
  sinfo_test_fit_slits_edge_with_estimate();
 
390
  */
 
391
 
 
392
  cpl_test_error(CPL_ERROR_NONE);
 
393
  return cpl_test_end(0);
 
394
 
 
395
}
 
396
 
 
397
 
 
398
/**@}*/