GRAVI Pipeline Reference Manual 1.9.0
Loading...
Searching...
No Matches
gravi-test.c
Go to the documentation of this file.
1/* $Id: gravi_data-test.c,v 1.59 2011/08/16 17:43:49 nazouaoui Exp $
2 *
3 * This file is part of the ESO Common Pipeline Library
4 * Copyright (C) 2001-2008 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21
22/*
23 * gravi-test.c
24 *
25 * Created on: 17 août 2011
26 * Author: nabih
27 */
28
29
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include <math.h>
34
35#include <assert.h>
36
37#include "gravi-test.h"
38
39#define COMPUTE_FILES 0
40
41
42int gravi_array_compare(cpl_array * array_1, cpl_array * array_2){
43
44 if ((array_1 == NULL) || (array_2 == NULL))
45 return 1;
46
47// else if ((array_1 == NULL) && (array_2 != NULL)){
48// return 1;
49// }
50// else if ((array_1 != NULL) && (array_2 == NULL)){
51// return 1;
52// }
53 cpl_type type_array_1 = cpl_array_get_type(array_1);
54 cpl_type type_array_2 = cpl_array_get_type(array_2);
55
56 if (strcmp(cpl_type_get_name (type_array_1), cpl_type_get_name (type_array_2))){
57 cpl_msg_info(cpl_func,"The arrays have not the same type type1 = %s and type2 = %s\n",
58 cpl_type_get_name (type_array_1), cpl_type_get_name (type_array_2));
59 return 0;
60 }
61
62 if (cpl_array_get_size(array_1) != cpl_array_get_size(array_2)){
63 cpl_msg_info(cpl_func,"the arrays don't have the same size\n");
64 return 0;
65 }
66
67 int size = cpl_array_get_size(array_1);
68 int j;
69
70 /* compute the image list depending of the DATA type */
71 double * array_double_1;
72 double * array_double_2;
73 double complex * array_complex_1;
74 double complex * array_complex_2;
75 int * array_int_1;
76 int * array_int_2;
77 float * array_float_1;
78 float * array_float_2;
79 char ** array_string_1;
80 char ** array_string_2;
81 switch (type_array_1)
82 {
83 case CPL_TYPE_DOUBLE :
84
85 array_double_1 = cpl_array_get_data_double(array_1);
86 array_double_2 = cpl_array_get_data_double(array_2);
87 for (j = 0; j < size ; j++){
88 if (array_double_1[j] > 1e-10){
89 if (fabs((array_double_1[j] - array_double_2[j]) / array_double_1[j]) > 0.1){
90 cpl_msg_info(cpl_func,"The arrays are not the same on the %d nd index:"
91 " %e and %e\n", j, array_double_1[j], array_double_2[j]);
92 return 0;
93 }
94 }
95 else {
96 if (array_double_2[j] > 1e-10){
97 cpl_msg_info(cpl_func,"The arrays are not equal at zero on the %d nd index:"
98 " %e and %e\n", j, array_double_1[j], array_double_2[j]);
99 return 0;
100 }
101 }
102
103
104 }
105
106 break;
107
108 case CPL_TYPE_DOUBLE_COMPLEX :
109
110 array_complex_1 = cpl_array_get_data_double_complex(array_1);
111 array_complex_2 = cpl_array_get_data_double_complex(array_2);
112 for (j = 0; j < size ; j++){
113 if (cabs(array_complex_1[j]) > 1e-10){
114 if ((carg(array_complex_1[j]) - carg(array_complex_2[j])) > 0.1){
115 cpl_msg_info(cpl_func,"The argument of complex arrays are not the same on the %d nd index:"
116 " %e and %e\n", j,carg( array_complex_1[j]), carg(array_complex_2[j]));
117 return 0;
118 }
119 if (fabs((cabs(array_complex_1[j]) - cabs(array_complex_2[j]))) /
120 cabs(array_complex_1[j]) > 0.1){
121 cpl_msg_info(cpl_func,"The module of complex arrays are not the same on the %d nd index:"
122 " %e and %e\n", j, cabs(array_complex_1[j]), cabs(array_complex_2[j]));
123 return 0;
124 }
125 }
126 else {
127 if (cabs(array_complex_2[j]) > 1e-10) {
128 cpl_msg_info(cpl_func,"The module of complex arrays are not equal at zero on the %d nd index:"
129 " %e and %e\n", j, cabs(array_complex_1[j]), cabs(array_complex_2[j]));
130 return 0;
131 }
132 }
133 }
134
135 break;
136
137 case CPL_TYPE_INT :
138 array_int_1 = cpl_array_get_data_int(array_1);
139 array_int_2 = cpl_array_get_data_int(array_2);
140 for (j = 0; j < size ; j++){
141 if (array_int_1[j] != 0) {
142 if ((abs(array_int_1[j] - array_int_2[j]) / array_int_1[j]) > 1){
143 cpl_msg_info(cpl_func,"The arrays are not the same on the %d nd index: "
144 "%d and %d\n", j, array_int_1[j], array_int_2[j]);
145 return 0;
146 }
147 }
148 else {
149 if (array_int_2[j] > 1e-10){
150 cpl_msg_info(cpl_func,"The arrays are not equal at zero on the %d nd index: "
151 "%d and %d\n", j, array_int_1[j], array_int_2[j]);
152 return 0;
153 }
154 }
155
156
157 }
158
159
160 break;
161
162 case CPL_TYPE_FLOAT :
163
164 array_float_1 = cpl_array_get_data_float(array_1);
165 array_float_2 = cpl_array_get_data_float(array_2);
166 for (j = 0; j < size ; j++){
167 if (array_float_1[j] > 1e-10){
168 if (fabs((array_float_1[j] - array_float_2[j]) / array_float_1[j])> 0.1){
169 cpl_msg_info(cpl_func,"The arrays are not the same on the %d nd index: "
170 "%e and %e\n", j, array_float_1[j], array_float_2[j]);
171 return 0;
172 }
173 }
174 else {
175 if (array_float_2[j] > 1e-10){
176 cpl_msg_info(cpl_func,"The arrays are not equal at zero on the %d nd index: "
177 "%e and %e\n", j, array_float_1[j], array_float_2[j]);
178 return 0;
179 }
180 }
181
182 }
183
184 break;
185
186 case CPL_TYPE_STRING :
187 array_string_1 = cpl_array_get_data_string(array_1);
188 array_string_2 = cpl_array_get_data_string(array_2);
189 for (j = 0; j < size; j++){
190 if(strcmp(*(array_string_1 + j), *(array_string_2 + j))){
191 cpl_msg_info(cpl_func,"The arrays are not the same on the %d nd index: "
192 "%s and %s\n", j, array_string_1[j], array_string_2[j]);
193 return 0;
194 }
195 }
196 break;
197
198 default:
199
200 cpl_msg_info(cpl_func,"invalid type of array %s\n", cpl_type_get_name (type_array_2));
201 return -1;
202 break;
203 }
204
205 return 1;
206
207}
208
209
210int gravi_table_compare(cpl_table * table1, cpl_table * table2 ){
211
212 if (cpl_table_compare_structure(table1, table2) == 0){
213 int ncol = cpl_table_get_ncol(table1);
214 int nrow = cpl_table_get_nrow(table1);
215 cpl_array * table_names = cpl_table_get_column_names (table1);
216 int i, j;
217 for (i = 0; i < ncol; i++){
218 const char * col_name = cpl_array_get_string(table_names, i);
219
220 /* Cast the type on int to avoid warning */
221 int type = cpl_table_get_column_type(table1, col_name);
222 cpl_array ** array_table1;
223 cpl_array ** array_table2;
224 double * double_table1;
225 double * double_table2;
226 int * int_table1;
227 int * int_table2;
228 float * float_table1;
229 float * float_table2;
230 char ** string_table1;
231 char ** string_table2;
232
233 switch(type){
234 case CPL_TYPE_DOUBLE | CPL_TYPE_POINTER :
235 case CPL_TYPE_POINTER | CPL_TYPE_INT:
236 case CPL_TYPE_FLOAT | CPL_TYPE_POINTER :
237 case CPL_TYPE_DOUBLE_COMPLEX | CPL_TYPE_POINTER :
238 case CPL_TYPE_FLOAT_COMPLEX | CPL_TYPE_POINTER :
239 array_table1 = cpl_table_get_data_array(table1, col_name);
240 array_table2 = cpl_table_get_data_array(table2, col_name);
241 for (j = 0; j < nrow; j++){
242 if (gravi_array_compare(array_table1[j]
243 , array_table2[j]) != 1){
244 cpl_msg_info(cpl_func,"Case array : on the column %s and in the row %d"
245 " the arrays are different", col_name, j);
246 return 0;
247 }
248 }
249 break;
250 case CPL_TYPE_DOUBLE :
251 double_table1 = cpl_table_get_data_double(table1, col_name);
252 double_table2 = cpl_table_get_data_double(table2, col_name);
253 for (j = 0; j < nrow; j++){
254 if (double_table1[j] > 1e-10){
255 if (fabs((double_table1[j] - double_table2[j]) / double_table1[j]) > 0.1){
256 cpl_msg_info(cpl_func,"Case double : on the column %s and in the row %d"
257 " the double are different", col_name, j);
258 return 0;
259 }
260 }
261 else {
262 if (double_table2[j] > 1e-10){
263 cpl_msg_info(cpl_func,"Case double : on the column %s and in the row %d"
264 " the double are different", col_name, j);
265 return 0;
266 }
267 }
268
269 }
270 break;
271 case CPL_TYPE_INT :
272 int_table1 = cpl_table_get_data_int(table1, col_name);
273 int_table2 = cpl_table_get_data_int(table2, col_name);
274 for (j = 0; j < nrow; j++){
275 if (int_table1[j] != 0){
276 if (abs(int_table1[j] - int_table2[j]) / int_table1[j] > 1){
277 cpl_msg_info(cpl_func,"Case int : on the column %s and in the row %d"
278 " the integers are different\n", col_name, j);
279 return 0;
280 }
281 }
282 else {
283 if (int_table2[j] != 0){
284 cpl_msg_info(cpl_func,"Case int : on the column %s and in the row %d"
285 " the integers are different\n", col_name, j);
286 return 0;
287 }
288 }
289
290 }
291 break;
292
293 case CPL_TYPE_FLOAT :
294 float_table1 = cpl_table_get_data_float(table1, col_name);
295 float_table2 = cpl_table_get_data_float(table2, col_name);
296 for (j = 0; j < nrow; j++){
297 if (float_table1[j] > 1e-10){
298 if (fabs((float_table1[j] - float_table2[j]) / float_table1[j]) > 0.1){
299 cpl_msg_info(cpl_func,"Case int : on the column %s and in the row %d"
300 " the integers are different\n", col_name, j);
301 return 0;
302 }
303 }
304 else {
305 if (float_table2[j] > 1e-10){
306 cpl_msg_info(cpl_func,"Case int : on the column %s and in the row %d"
307 " the integers are different\n", col_name, j);
308 return 0;
309 }
310 }
311 }
312 break;
313
314 case CPL_TYPE_STRING :
315 string_table1 = cpl_table_get_data_string(table1, col_name);
316 string_table2 = cpl_table_get_data_string(table2, col_name);
317 for (j = 0; j < nrow; j++){
318 if (strcmp(string_table1[j], string_table2[j]) != 0){
319 cpl_msg_info(cpl_func,"Case string : on the column %s and in the row %d"
320 " the strings are different\n", col_name, j);
321 return 0;
322 }
323 }
324 break;
325
326 default:
327
328 cpl_msg_info(cpl_func,"invalid type %s\n", cpl_type_get_name (type));
329 return -1;
330 break;
331 }
332 }
333 cpl_array_delete(table_names);
334 return 1;
335
336 }
337 else{
338 cpl_msg_info(cpl_func,"The tables don't have the same number of columns, "
339 "with the same names or the same types\n");
340 return 0;
341 }
342
343
344}
345
346int gravi_propertylist_compare(cpl_propertylist * plist1, cpl_propertylist * plist2){
347
348 int size = cpl_propertylist_get_size (plist1);
349 if ( size != cpl_propertylist_get_size(plist2)){
350 cpl_msg_info(cpl_func,"the property lists don't have the same size\n");
351 return 0;
352 }
353 int i;
354 cpl_property * p;
355
356 const char * name;
357 for (i = 0; i < size; i++){
358 p = cpl_propertylist_get(plist1, i);
359 name = cpl_property_get_name(p);
360 if(!cpl_propertylist_has (plist2, name)){
361 cpl_msg_info(cpl_func,"The property %s is not present on the second "
362 "property list \n", name);
363 return 0;
364 }
365
366 cpl_type type1 = cpl_propertylist_get_type (plist1, name);
367 cpl_type type2 = cpl_propertylist_get_type (plist2, name);
368 if (strcmp(cpl_type_get_name(type1), cpl_type_get_name(type2))){
369 cpl_msg_info(cpl_func,"The property %s in the first property list "
370 "have not the same type as in the second property list \n"
371 , name);
372 return 0;
373 }
374
375 int p_int;
376 double p_double;
377 float p_float;
378 const char * p_string;
379 long p_long;
380 char p_char;
381 switch(type1) {
382 case CPL_TYPE_DOUBLE :
383 p_double = cpl_propertylist_get_double(plist1, name);
384 if (p_double != cpl_propertylist_get_double(plist2, name)){
385 cpl_msg_info(cpl_func,"case Double : the property %s have not the same value\n", name);
386 return 0;
387 }
388 break;
389 case CPL_TYPE_INT :
390 p_int = cpl_propertylist_get_int(plist1, name);
391 if (p_int != cpl_propertylist_get_int(plist2, name)){
392 cpl_msg_info(cpl_func,"case interger : the property %s have not the same value\n", name);
393 return 0;
394 }
395 break;
396 case CPL_TYPE_FLOAT :
397 p_float = cpl_propertylist_get_float(plist1, name);
398 if (p_float != cpl_propertylist_get_float(plist2, name)){
399 cpl_msg_info(cpl_func,"case float : the property %s have not the same value\n", name);
400 return 0;
401 }
402 break;
403 case CPL_TYPE_STRING :
404 p_string = cpl_propertylist_get_string(plist1, name);
405 if (strcmp(p_string, cpl_propertylist_get_string(plist2, name))){
406 cpl_msg_info(cpl_func,"case string : the property %s have not the same value\n", name);
407 return 0;
408 }
409 break;
410 case CPL_TYPE_LONG :
411 p_long = cpl_propertylist_get_long(plist1, name);
412 if (p_long != cpl_propertylist_get_long(plist2, name)){
413 cpl_msg_info(cpl_func,"case long : the property %s have not the same value\n", name);
414 return 0;
415 }
416 break;
417 case CPL_TYPE_CHAR :
418 p_char = cpl_propertylist_get_char(plist1, name);
419 if (p_char != cpl_propertylist_get_char(plist2, name)){
420 cpl_msg_info(cpl_func,"case char : the property %s have not the same value\n", name);
421 return 0;
422 }
423 break;
424 default :
425 cpl_msg_info(cpl_func,"invalid type of property %s\n", cpl_type_get_name (type1));
426 return -1;
427 break;
428
429 }
430
431 }
432
433 return 1;
434}
435
437
438
439 int size = gravi_data_get_size(data1);
440 if (size != gravi_data_get_size(data1)){
441 cpl_msg_info(cpl_func,"The elements don't have the same size\n");
442 return 0;
443 }
444 cpl_propertylist * p1;
446 cpl_propertylist * p2;
448 if (gravi_propertylist_compare(p1, p2) != 1){
449 cpl_msg_info(cpl_func,"The %s property list is diffetent "
450 "between the two elements\n", GRAVI_PRIMARY_HDR_EXT);
451 return 0;
452 }
453
454 int i, ext;
455 const char * name;
456 for(i = 0; i < size; i++){
457 p1 = gravi_data_get_plist_x(data1, i);//data1->exts_hdrs[i];
458 name = cpl_propertylist_get_string(p1, "EXTNAME");
459 ext = 0;
460 while( ext != size ){
461 p2 = gravi_data_get_plist_x(data1, ext);//data2->exts_hdrs[ext];
462 if (!strcmp(name, cpl_propertylist_get_string(p2, "EXTNAME"))){
463 break;
464 }
465 ext++;
466 }
467 if (ext == size){
468 cpl_msg_info(cpl_func,"The seconde element don't contain the %s "
469 "property list\n", name);
470 return 0;
471 }
472// if (gravi_propertylist_compare(data1->exts_hdrs[i],
473// data2->exts_hdrs[ext]) != 1){
474 if (gravi_propertylist_compare(p1, p2) != 1){
475 cpl_msg_info(cpl_func,"The %s property list is not the same for the "
476 "twe elements\n", name);
477 return 0;
478 }
479// if (gravi_table_compare(data1->exts_tbs[i], data2->exts_tbs[ext]) != 1){
481 gravi_data_get_table_x(data2, ext)) != 1){
482 cpl_msg_info(cpl_func,"The table associated to %s property list is not"
483 " the same for the two elements\n", name);
484 return 0;
485 }
486
487 }
488 return 1;
489
490}
491
492
int gravi_propertylist_compare(cpl_propertylist *plist1, cpl_propertylist *plist2)
Definition: gravi-test.c:346
int gravi_table_compare(cpl_table *table1, cpl_table *table2)
Definition: gravi-test.c:210
int gravi_data_compare(gravi_data *data1, gravi_data *data2)
Definition: gravi-test.c:436
int gravi_array_compare(cpl_array *array_1, cpl_array *array_2)
Definition: gravi-test.c:42
#define GRAVI_PRIMARY_HDR_EXT
Definition: gravi-test.h:212
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
Definition: gravi_data.h:39
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
cpl_propertylist * gravi_data_get_plist(gravi_data *self, const char *extname)
Get the propertylist from EXTNAME.
Definition: gravi_data.c:2049
cpl_propertylist * gravi_data_get_plist_x(gravi_data *self, int i)
Get the propertylist of an extension by position.
Definition: gravi_data.c:1876
int gravi_data_get_size(const gravi_data *self)
Get the number of extension in a gravi_data.
Definition: gravi_data.c:828
cpl_table * gravi_data_get_table_x(gravi_data *self, int i)
Get the table of an extension by position.
Definition: gravi_data.c:1901