UVES Pipeline Reference Manual  5.4.6
uves_utils-test.c
1 /* *
2  * This file is part of the ESO UVES 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: 2010-09-24 09:31:49 $
23  * $Revision: 1.14 $
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 
36 #include <uves_utils.h>
37 #include <uves_dfs.h>
38 #include <uves_utils_cpl.h>
39 #include <uves_utils_polynomial.h>
40 #include <uves_utils_wrappers.h>
41 #include <uves_error.h>
42 
43 #include <cpl_test.h>
44 #include <cpl.h>
45 #include <string.h>
46 #include <stdlib.h>
47 
48 /*-----------------------------------------------------------------------------
49  Defines
50  -----------------------------------------------------------------------------*/
51 
52 /*
53  * The following is duplicated from CPL's unit test
54  * to test the workaround for cpl_table_erase_selected()
55  */
56 
57 
58 
59 
60 #ifdef VERBOSE
61 
62 #define test_data(r,f,m) \
63 printf("%s", m); \
64 fflush(stdout); \
65 fflush(stderr); \
66 r = f; \
67 if (!r) { \
68  printf("Failure\n"); \
69  \
70  return 1; \
71 } \
72 printf("OK\n")
73 
74 #else
75 
76 #define test_data(r,f,m) \
77 r = f; \
78 if (!r) { \
79  printf("%s", m); \
80  printf("Failure\n"); \
81  \
82  return 1; \
83 }
84 
85 #endif
86 
87 
88 /*
89  * Test for functions returning 0 on success.
90  *
91  * f = function call
92  * m = message
93  */
94 
95 #ifdef VERBOSE
96 
97 #define test(f,m) \
98 printf("%s", m); \
99 fflush(stdout); \
100 fflush(stderr); \
101 if (f) { \
102  printf("Failure\n"); \
103  \
104  return 1; \
105 } \
106 printf("OK\n")
107 
108 #else
109 
110 #define test(f,m) \
111 if (f) { \
112  printf("%s", m); \
113  printf("Failure\n"); \
114  \
115  return 1; \
116 }
117 
118 #endif
119 
120 /*
121  * Test for expected failure in functions returning 0 on success.
122  *
123  * e = expected error code
124  * f = function call
125  * m = message
126  */
127 
128 #ifdef VERBOSE
129 
130 #define test_failure(e,f,m) \
131 printf("%s", m); \
132 fflush(stdout); \
133 fflush(stderr); \
134 if (f != e) { \
135  printf("\n"); \
136  printf(" Received error: \"%s\"\n", cpl_error_get_message()); \
137  cpl_error_set("cpl_table-test", e); \
138  printf(" Expected error: \"%s\"\n", cpl_error_get_message()); \
139  \
140  return 1; \
141 } \
142 cpl_error_reset(); \
143 printf("OK\n")
144 
145 #else
146 
147 #define test_failure(e,f,m) \
148 if (f != e) { \
149  printf("%s", m); \
150  printf("\n"); \
151  printf(" Received error: \"%s\"\n", cpl_error_get_message()); \
152  cpl_error_set("cpl_table-test", e); \
153  printf(" Expected error: \"%s\"\n", cpl_error_get_message()); \
154  \
155  return 1; \
156 } \
157 cpl_error_reset()
158 
159 #endif
160 
161 
162 /*
163  * Test for functions returning an expected integer value.
164  *
165  * e = expected value
166  * f = function call
167  * m = message
168  */
169 
170 #ifdef VERBOSE
171 
172 #define test_ivalue(e,f,m) \
173 printf("%s", m); \
174 fflush(stdout); \
175 fflush(stderr); \
176 itest = f; \
177 if (itest != e) { \
178  printf("Received %d, expected %d\n", itest, e); \
179  \
180  return 1; \
181 } \
182 printf("OK\n")
183 
184 #else
185 
186 #define test_ivalue(e,f,m) \
187 itest = f; \
188 if (itest != e) { \
189  printf("%s", m); \
190  printf("Received %d, expected %d\n", itest, e); \
191  \
192  return 1; \
193 }
194 
195 #endif
196 
197 
198 /*
199  * Test for functions returning an expected pointer value.
200  *
201  * e = expected value
202  * f = function call
203  * m = message
204  */
205 
206 #ifdef VERBOSE
207 
208 #define test_pvalue(e,f,m) \
209 printf("%s", m); \
210 fflush(stdout); \
211 fflush(stderr); \
212 ptest = f; \
213 if (ptest != e) { \
214  printf("Received %p, expected %p\n", ptest, e); \
215  \
216  return 1; \
217 } \
218 printf("OK\n")
219 
220 #else
221 
222 #define test_pvalue(e,f,m) \
223 ptest = f; \
224 if (ptest != e) { \
225  printf("%s", m); \
226  printf("Received %p, expected %p\n", ptest, e); \
227  \
228  return 1; \
229 }
230 
231 #endif
232 
233 /*
234  * Test for functions returning an expected floating point value.
235  *
236  * e = expected value
237  * t = tolerance on expected value
238  * f = function call
239  * m = message
240  */
241 
242 #ifdef VERBOSE
243 
244 #define test_fvalue(e,t,f,m) \
245 printf("%s", m); \
246 fflush(stdout); \
247 fflush(stderr); \
248 ftest = f; \
249 if (fabs(ftest - (e)) > t) { \
250  printf("Received %f, expected %f\n", ftest, e); \
251  \
252  return 1; \
253 } \
254 printf("OK\n")
255 
256 #else
257 
258 #define test_fvalue(e,t,f,m) \
259 ftest = f; \
260 if (fabs(ftest - (e)) > t) { \
261  printf("%s", m); \
262  printf("Received %f, expected %f\n", ftest, e); \
263  \
264  return 1; \
265 }
266 
267 #endif
268 
269 /*
270  * Test for functions returning an expected character string.
271  *
272  * e = expected value
273  * f = function call
274  * m = message
275  */
276 
277 #ifdef VERBOSE
278 
279 #define test_svalue(e,f,m) \
280 printf("%s", m); \
281 fflush(stdout); \
282 fflush(stderr); \
283 stest = f; \
284 if (strcmp(e,stest)) { \
285  printf("Received %s, expected %s\n", stest, e); \
286  \
287  return 1; \
288 } \
289 printf("OK\n")
290 
291 #else
292 
293 #define test_svalue(e,f,m) \
294 stest = f; \
295 if (strcmp(e,stest)) { \
296  printf("%s", m); \
297  printf("Received %s, expected %s\n", stest, e); \
298  \
299  return 1; \
300 }
301 
302 #endif
303 
304 
305 
306 /*-----------------------------------------------------------------------------
307  Functions prototypes
308  -----------------------------------------------------------------------------*/
309 
310 /*-----------------------------------------------------------------------------
311  Implementation
312  -----------------------------------------------------------------------------*/
313 
314 
315 
316 /*----------------------------------------------------------------------------*/
320 /*----------------------------------------------------------------------------*/
322 #define MAX_SIZE 4096
323 static void
324 uves_filter_cosmic_test(void)
325 {
326 
327  //const char* src_dir="/data1/uves/valentina/";
328  const char* src_dir="/media/disk/uves/valentina/";
329  //const char* src_dir="./";
330  const char* input="PA1_D2B_001.fits";
331  //const char* input="cleaned.fits";
332  char cosmic_name[MAX_SIZE];
333  char filter_name[MAX_SIZE];
334  char clean_name[MAX_SIZE];
335  char mask_name[MAX_SIZE];
336  const double sky=150.;
337  const double gain=1.84;
338  const double ron=4.1;
339  const int ns=4;
340  int sx=0;
341  int sy=0;
342 
343  const double rc=2;
344  cpl_frame* frm=NULL;
345  cpl_image* inp=NULL;
346  cpl_image* flt=NULL;
347  cpl_image* out=NULL;
348  cpl_image* msk=NULL;
349  cpl_propertylist* h=NULL;
350  sprintf(cosmic_name,"%s%s",src_dir,input);
351  sprintf(filter_name,"%s","filter.fits");
352  sprintf(clean_name,"%s","cleaned.fits");
353  sprintf(mask_name,"%s","mask.fits");
354  check_nomsg(frm=cpl_frame_new());
355  check_nomsg(cpl_frame_set_filename(frm,cosmic_name));
356  check_nomsg(cpl_frame_set_type(frm,CPL_FRAME_TYPE_IMAGE));
357  check_nomsg(cpl_frame_set_group(frm,CPL_FRAME_GROUP_RAW));
358 
359  check_nomsg(inp=cpl_image_load(cosmic_name,CPL_TYPE_FLOAT,0,0));
360  check_nomsg(h=cpl_propertylist_load(cosmic_name,0));
361  check_nomsg(sx=cpl_image_get_size_x(inp));
362  check_nomsg(sy=cpl_image_get_size_y(inp));
363 
364  check_nomsg(msk=cpl_image_new(sx,sy,CPL_TYPE_INT));
365 
366  check_nomsg(uves_rcosmic(inp,&flt,&out,&msk,sky,ron,gain,ns,rc));
367  check_nomsg(cpl_image_save(flt,filter_name,CPL_BPP_IEEE_FLOAT,
368  h,CPL_IO_DEFAULT));
369  check_nomsg(cpl_image_save(msk,mask_name,CPL_BPP_IEEE_FLOAT,
370  h,CPL_IO_DEFAULT));
371  check_nomsg(cpl_image_save(out,clean_name,CPL_BPP_IEEE_FLOAT,
372  h,CPL_IO_DEFAULT));
373 
374 
375  cleanup:
376  uves_free_frame(&frm);
377  cpl_propertylist_delete(h);
378  uves_free_image(&inp);
379  uves_free_image(&out);
380  uves_free_image(&flt);
381  uves_free_image(&msk);
382 
383  return;
384 }
385 
386 
387 static void
388 uves_find_property_test(void)
389 {
391 
392  uves_propertylist_append_int(header, "INTVAL", 3);
393  uves_propertylist_append_double(header, "HELLO", 98.12);
394  uves_propertylist_append_int(header, "INTVAL", 3);
395  uves_propertylist_append_double(header, "HELLO", 98.12);
396  uves_propertylist_append_int(header, "INTVAL", 3);
397 
398  /* Now CPL sets an error status (not catched by UVES propertylist wrapper)
399  on the first 3 extensions as they miss the keyword.
400  We need to comment out those: or FIX uves_propertylist.c
401  TO_BE_FIXED
402  cpl_test( uves_find_property(header, "INTVAL", 0) != NULL);
403  cpl_test( uves_find_property(header, "INTVAL", 1) != NULL);
404  cpl_test( uves_find_property(header, "INTVAL", 2) != NULL);
405  cpl_test( uves_find_property(header, "INTVAL", 3) == NULL);
406  cpl_test( uves_find_property(header, "INTVAL", 4) == NULL);
407  */
408 
409  uves_free_propertylist(&header);
410 
411  return;
412 }
413 
414 static void
415 uves_average_reject_test(void)
416 {
417  cpl_table *table = cpl_table_new(100);
418  int i;
419 
420  cpl_table_new_column(table, "X", CPL_TYPE_DOUBLE);
421  cpl_table_set_double(table, "X", 0, 100);
422  cpl_table_set_double(table, "X", 1, 101);
423  cpl_table_set_double(table, "X", 2, 2000); /* Outlier here */
424  cpl_table_set_double(table, "X", 3, 98);
425  cpl_table_set_double(table, "X", 4, 103);
426  cpl_table_set_double(table, "X", 5, 102);
427  cpl_table_set_double(table, "X", 6, 100);
428  cpl_table_set_double(table, "X", 7, 103);
429  cpl_table_set_double(table, "X", 8, 100);
430  cpl_table_set_double(table, "X", 9, 99);
431 
432  srand(0); /* For reproducability */
433  for (i = 10; i < 100; i++)
434  {
435  cpl_table_set_double(table, "X", i, 100 + 3*uves_gaussrand());
436 
437  }
438  {
439  double kappa = 4.0;
440  double expected_avg = 100;
441  double tolerance = 3.0;
442 
443  cpl_test( 2000 - 100 > kappa * cpl_table_get_column_stdev(table, "X"));
444 
445  cpl_test_abs( uves_average_reject(table, "X", "temp", kappa),
446  expected_avg, tolerance);
447  }
448  cpl_test_eq( cpl_table_get_nrow(table), 99);
449  cpl_test_abs( cpl_table_get_double(table, "X", 0, NULL), 100, 0.1);
450  cpl_test_abs( cpl_table_get_double(table, "X", 1, NULL), 101, 0.1);
451  cpl_test_abs( cpl_table_get_double(table, "X", 2, NULL), 98, 0.1);
452  cpl_test_abs( cpl_table_get_double(table, "X", 3, NULL), 103, 0.1);
453 
454  uves_free_table(&table);
455 
456  return;
457 }
458 
459 static void
460 uves_polynomial_fit_2d_test(void)
461 {
462  unsigned size = 4;
463  cpl_bivector *xy_pos = cpl_bivector_new(size);
464  cpl_vector *values = cpl_vector_new(size);
465  cpl_vector *sigmas = NULL;
466  int deg1 = 0;
467  int deg2 = 0;
468  polynomial *solution;
469 
470  /* "good" input */
471  cpl_bivector_get_x_data(xy_pos)[0] = 1;
472  cpl_bivector_get_x_data(xy_pos)[1] = 2;
473  cpl_bivector_get_x_data(xy_pos)[2] = 3;
474  cpl_bivector_get_x_data(xy_pos)[3] = 4;
475 
476  cpl_bivector_get_y_data(xy_pos)[0] = 4;
477  cpl_bivector_get_y_data(xy_pos)[1] = 3;
478  cpl_bivector_get_y_data(xy_pos)[2] = 2;
479  cpl_bivector_get_y_data(xy_pos)[3] = 1;
480 
481  cpl_vector_get_data(values)[0] = 17;
482  cpl_vector_get_data(values)[1] = 17;
483  cpl_vector_get_data(values)[2] = 17;
484  cpl_vector_get_data(values)[3] = 17;
485 
486  solution = uves_polynomial_fit_2d(xy_pos, values, sigmas,
487  deg1, deg2,
488  NULL, NULL, NULL); /* mse, red_chisq, variance */
489 
490  cpl_test(solution != NULL);
491  cpl_test_abs(uves_polynomial_evaluate_2d(solution, 1, 1), 17, 0.001);
492 
493 
494  /* Degenerate input */
495  deg1 = 1;
496  deg2 = 1;
497  cpl_bivector_get_x_data(xy_pos)[0] = 1;
498  cpl_bivector_get_x_data(xy_pos)[1] = 1;
499  cpl_bivector_get_x_data(xy_pos)[2] = 1;
500  cpl_bivector_get_x_data(xy_pos)[3] = 1;
501 
502  cpl_bivector_get_y_data(xy_pos)[0] = 1;
503  cpl_bivector_get_y_data(xy_pos)[1] = 1;
504  cpl_bivector_get_y_data(xy_pos)[2] = 1;
505  cpl_bivector_get_y_data(xy_pos)[3] = 1;
506 
507 
508  uves_polynomial_delete(&solution);
509  solution = uves_polynomial_fit_2d(xy_pos, values, sigmas,
510  deg1, deg2,
511  NULL, NULL, NULL); /* mse, red_chisq, variance */
512 
513  cpl_test(cpl_error_get_code() == CPL_ERROR_SINGULAR_MATRIX);
515  cpl_test(solution == NULL);
516 
517 
518 
519  uves_polynomial_delete(&solution);
520  uves_free_bivector(&xy_pos);
521  uves_free_vector(&values);
522 
523  return;
524 }
525 
526 
527 
528 static int table_erase_selected(void)
529 {
530 
531  int nrows = 10;
532  int i, j, k, null, error;
533  int pp;
534  int itest;
535  double ftest;
536  const char *stest;
537  void *ptest;
538  char message[80];
539 
540  int *iArray;
541  float *fArray;
542  double *dArray;
543  double *ddArray;
544  char **sArray;
545 
546  int icheck[25];
547  float fcheck[25];
548  double dcheck[25];
549  const char *scheck[25];
550 
551  const char *unit;
552  const char *names[2];
553  int reverse[2];
554 
555  cpl_table *table;
556  cpl_table *copia;
557  cpl_array *array;
558 
559  uves_propertylist *reflist;
560 
561 /*
562  uves_propertylist *list1;
563  uves_propertylist *list2;
564 */
565 
566  iArray = cpl_malloc(nrows * sizeof(int));
567  fArray = cpl_malloc(nrows * sizeof(float));
568  dArray = cpl_malloc(nrows * sizeof(double));
569  ddArray = cpl_malloc(nrows * sizeof(double));
570  sArray = cpl_malloc(nrows * sizeof(char *));
571 
572  iArray[0] = 5;
573  iArray[1] = 0;
574  iArray[2] = 2;
575  iArray[3] = 8;
576  iArray[4] = 9;
577  iArray[5] = 3;
578  iArray[6] = 7;
579  iArray[7] = 1;
580  iArray[8] = 4;
581  iArray[9] = 6;
582 
583  fArray[0] = 5.1;
584  fArray[1] = 0.1;
585  fArray[2] = 2.1;
586  fArray[3] = 8.1;
587  fArray[4] = 9.1;
588  fArray[5] = 3.1;
589  fArray[6] = 7.1;
590  fArray[7] = 1.1;
591  fArray[8] = 4.1;
592  fArray[9] = 6.1;
593 
594  ddArray[0] = dArray[0] = 5.11;
595  ddArray[1] = dArray[1] = 0.11;
596  ddArray[2] = dArray[2] = 2.11;
597  ddArray[3] = dArray[3] = 8.11;
598  ddArray[4] = dArray[4] = 9.11;
599  ddArray[5] = dArray[5] = 3.11;
600  ddArray[6] = dArray[6] = 7.11;
601  ddArray[7] = dArray[7] = 1.11;
602  ddArray[8] = dArray[8] = 4.11;
603  ddArray[9] = dArray[9] = 6.11;
604 
605  sArray[0] = cpl_strdup("caaa");
606  sArray[1] = cpl_strdup("abcd");
607  sArray[2] = cpl_strdup("aaaa");
608  sArray[3] = cpl_strdup("daaa");
609  sArray[4] = cpl_strdup("acde");
610  sArray[5] = cpl_strdup("baaa");
611  sArray[6] = cpl_strdup("aaaa");
612  sArray[7] = cpl_strdup("acde");
613  sArray[8] = cpl_strdup(" sss");
614  sArray[9] = cpl_strdup("daaa");
615 
616 
617  /*
618  * Testing begins here
619  */
620 
621  /*
622  * Testing tables with zero rows.
623  */
624 
625  test_data(table, cpl_table_new(0), "Creating a table without rows... ");
626 
627  test(cpl_table_new_column(table, "Int", CPL_TYPE_INT),
628  "Creating empty Integer column... ");
629  test(cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT),
630  "Creating empty Float column... ");
631  test(cpl_table_new_column(table, "Double", CPL_TYPE_DOUBLE),
632  "Creating empty Double column... ");
633  test(cpl_table_new_column(table, "String", CPL_TYPE_STRING),
634  "Creating empty String column... ");
635  test(cpl_table_new_column_array(table, "AInt",
636  CPL_TYPE_INT | CPL_TYPE_POINTER, 0),
637  "Creating empty IntegerArray column... ");
638  test(cpl_table_new_column_array(table, "AFloat",
639  CPL_TYPE_FLOAT | CPL_TYPE_POINTER, 0),
640  "Creating empty FloatArray column... ");
641  test(cpl_table_new_column_array(table, "ADouble",
642  CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 0),
643  "Creating empty DoubleArray column... ");
644 
645  test_ivalue(0, cpl_table_get_nrow(table), "Check zero table length... ");
646  test_ivalue(7, cpl_table_get_ncol(table), "Check zero table width... ");
647 
648  test_ivalue(0, cpl_table_get_column_depth(table, "Double"),
649  "Check \"Double\" depth... ");
650 
651  test_ivalue(0, cpl_table_get_column_depth(table, "AInt"),
652  "Check \"AInt\" depth... ");
653 
654  test(cpl_table_set_size(table, 1), "Expanding table to one row... ");
655 
656  test_ivalue(1, cpl_table_get_nrow(table), "Check table with one row... ");
657 
658  test(cpl_table_set_size(table, 0), "Deleting all rows from table... ");
659 
660  test_ivalue(0, cpl_table_get_nrow(table),
661  "Check again zero table length... ");
662 
663  test(cpl_table_erase_column(table, "Double"),
664  "Delete zero-column \"Double\"... ");
665 
666  test_ivalue(6, cpl_table_get_ncol(table), "Check zero-column removal... ");
667 
668  test(cpl_table_erase_column(table, "AInt"),
669  "Delete zero-column \"AInt\"... ");
670 
671  test_ivalue(5, cpl_table_get_ncol(table),
672  "Check zero-column array removal... ");
673 
674  test_pvalue(NULL, cpl_table_get_data_float(table, "Float"),
675  "Check NULL pointer to column Float... ");
676 
677  test_failure(CPL_ERROR_NULL_INPUT,
678  cpl_table_erase_selected(NULL),
679  "Erase selected on NULL table... ");
680 
681  test(cpl_table_erase_selected(table),
682  "Erase selected on empty table... ");
683 
684  test_failure(CPL_ERROR_NULL_INPUT,
685  cpl_table_set_column_unit(NULL, "Float", "arcsec"),
686  "Try to assign unit to NULL table... ");
687 
688  test_failure(CPL_ERROR_NULL_INPUT,
689  cpl_table_set_column_unit(table, NULL, "arcsec"),
690  "Try to assign unit to NULL column... ");
691 
692  test_failure(CPL_ERROR_DATA_NOT_FOUND,
693  cpl_table_set_column_unit(table, "Double", "arcsec"),
694  "Try to assign unit to non existing column... ");
695 
696  test(cpl_table_set_column_unit(table, "Float", "arcsec"),
697  "Assign unit 'arcsec' to column Float... ");
698 
699  if (strcmp(unit = (char *)cpl_table_get_column_unit(table, "Float"),
700  "arcsec")) {
701  printf("Check column unit... ");
702  printf("Expected \"arcsec\", obtained \"%s\"\n", unit);
703 
704  return 1;
705  }
706 
707  test(cpl_table_set_column_unit(table, "Float", NULL),
708  "Assign unit NULL to column Float... ");
709 
710  test_pvalue(NULL, (char *)cpl_table_get_column_unit(table, "Float"),
711  "Get unit NULL from column Float... ");
712 
713  test(cpl_table_set_size(table, 1), "Expanding again table to one row... ");
714 
715  test(cpl_table_erase_invalid_rows(table), "Pruning table to zero... ");
716 
717  test_ivalue(1, cpl_table_get_nrow(table),
718  "Checking zero-table length after pruning... ");
719 
720  test_ivalue(0, cpl_table_get_ncol(table),
721  "Checking zero-table width after pruning... ");
722 
723  cpl_table_delete(table);
724 
725 /* %%% */
726 
727  /*
728  * Testing tables with more rows
729  */
730 
731  test_data(table, cpl_table_new(nrows), "Creating the test table... ");
732 
733  test(cpl_table_wrap_int(table, iArray, "Integer"),
734  "Wrapping the Integer column... ");
735 
736 // test_pvalue(iArray, cpl_table_unwrap(table, "Integer"),
737 // "Unwrap the Integer column data... ");
738  cpl_table_unwrap(table, "Integer");
739 
740  test(cpl_table_wrap_int(table, iArray, "Integer"),
741  "Creating the Integer column... ");
742 
743  test(cpl_table_wrap_double(table, dArray, "Double"),
744  "Creating the Double column... ");
745 
746  test(cpl_table_wrap_double(table, ddArray, "DoubleDouble"),
747  "Creating the DoubleDouble column... ");
748 
749  test(cpl_table_wrap_string(table, sArray, "String"),
750  "Creating the String column... ");
751 
752  test(cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT),
753  "Creating the Float column... ");
754 
755  for (i = 0; i < nrows; i++) {
756  sprintf(message, "Writing to row %d of the Float column... ", i);
757  test(cpl_table_set_float(table, "Float", i, fArray[i]), message);
758  }
759 
760  test(cpl_table_new_column_array(table, "AInt",
761  CPL_TYPE_INT | CPL_TYPE_POINTER, 2),
762  "Creating the ArrayInt column... ");
763 
764  test(cpl_table_new_column_array(table, "AFloat", CPL_TYPE_FLOAT, 2),
765  "Creating the ArrayFloat column... ");
766 
767  test(cpl_table_new_column_array(table, "ADouble",
768  CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 2),
769  "Creating the ArrayDouble column... ");
770 
771  test_ivalue(2, cpl_table_get_column_depth(table, "AInt"),
772  "Check \"AInt\" depth (2)... ");
773 
774  k = 0;
775  array = cpl_array_new(2, CPL_TYPE_INT);
776  for (i = 0; i < nrows; i++) {
777  for (j = 0; j < 2; j++) {
778  sprintf(message,
779  "Writing element %d of array %d of the AInt column... ", j, i);
780  k++;
781  test(cpl_array_set_int(array, j, k), message);
782  }
783  sprintf(message, "Setting array at position %d of the AInt column... ", i);
784  test(cpl_table_set_array(table, "AInt", i, array), message);
785  }
786  cpl_array_delete(array);
787 
788  k = 0;
789  for (i = 0; i < nrows; i++) {
790  sprintf(message, "Getting array %d of the AInt column... ", i);
791  test_data(array, (cpl_array *)cpl_table_get_array(table, "AInt", i),
792  message);
793  for (j = 0; j < 2; j++) {
794  sprintf(message,
795  "Reading element %d of array %d of the AInt column... ", j, i);
796  k++;
797  test_ivalue(k, cpl_array_get_int(array, j, NULL), message);
798  }
799  }
800 
801  k = 0;
802  array = cpl_array_new(2, CPL_TYPE_FLOAT);
803  for (i = 0; i < nrows; i++) {
804  for (j = 0; j < 2; j++) {
805  sprintf(message,
806  "Writing element %d of array %d of the AFloat column... ", j, i);
807  k++;
808  test(cpl_array_set_float(array, j, k), message);
809  }
810  sprintf(message,
811  "Setting array at position %d of the AFloat column... ", i);
812  test(cpl_table_set_array(table, "AFloat", i, array), message);
813  }
814  cpl_array_delete(array);
815 
816  k = 0;
817  for (i = 0; i < nrows; i++) {
818  sprintf(message, "Getting array %d of the AFloat column... ", i);
819  test_data(array, (cpl_array *)cpl_table_get_array(table, "AFloat", i),
820  message);
821  for (j = 0; j < 2; j++) {
822  sprintf(message,
823  "Reading element %d of array %d of the AFloat column... ", j, i);
824  k++;
825  test_fvalue((float)k, 0.0001,
826  cpl_array_get_float(array, j, NULL), message);
827  }
828  }
829 
830  k = 0;
831  array = cpl_array_new(2, CPL_TYPE_DOUBLE);
832  for (i = 0; i < nrows; i++) {
833  for (j = 0; j < 2; j++) {
834  sprintf(message,
835  "Writing element %d of array %d of the ADouble column... ", j, i);
836  k++;
837  test(cpl_array_set_double(array, j, k), message);
838  }
839  sprintf(message,
840  "Setting array at position %d of the ADouble column... ", i);
841  test(cpl_table_set_array(table, "ADouble", i, array), message);
842  }
843  cpl_array_delete(array);
844 
845  k = 0;
846  for (i = 0; i < nrows; i++) {
847  sprintf(message, "Getting array %d of the ADouble column... ", i);
848  test_data(array, (cpl_array *)cpl_table_get_array(table, "ADouble", i),
849  message);
850  for (j = 0; j < 2; j++) {
851  sprintf(message,
852  "Reading element %d of array %d of the ADouble column... ", j, i);
853  k++;
854  test_fvalue((float)k, 0.0001,
855  cpl_array_get_double(array, j, NULL), message);
856  }
857  }
858 
859  test_ivalue(2, cpl_table_get_column_depth(table, "AInt"),
860  "Check \"AInt\" depth (3)... ");
861 
862  test_data(array, (cpl_array *)cpl_table_get_array(table, "AInt", 0),
863  "Get AInt array");
864  test_ivalue(CPL_TYPE_INT, cpl_array_get_type(array),
865  "Array AInt must be int... ");
866 
867 /**** %%%
868  list1 = uves_propertylist_new();
869  uves_propertylist_append_bool(list1, "hierarch eso ins bool", 0);
870  uves_propertylist_append_bool(list1, "hierarch eso ins bool", 0);
871  uves_propertylist_set_comment(list1, "hierarch eso ins bool", "This is a comment");
872  uves_propertylist_append_int(list1, "NAXIS", 111);
873  uves_propertylist_set_comment(list1, "NAXIS", "This is a comment");
874  uves_propertylist_append_long(list1, "long", 111111111);
875  uves_propertylist_set_comment(list1, "long", "This is a comment");
876  uves_propertylist_append_float(list1, "float", 4.4);
877  uves_propertylist_set_comment(list1, "float", "This is a comment");
878  uves_propertylist_append_double(list1, "double", 8.8);
879  uves_propertylist_set_comment(list1, "double", "This is a comment");
880  uves_propertylist_append_char(list1, "char", 'D');
881  uves_propertylist_set_comment(list1, "char", "This is a comment");
882  list2 = uves_propertylist_new();
883  uves_propertylist_append_string(list2, "hierarch eso det string", "This is a test");
884  uves_propertylist_set_comment(list2, "hierarch eso det string", "This is a comment");
885  uves_propertylist_append_int(list2, "TFIELDS", 3000);
886  uves_propertylist_set_comment(list2, "TFIELDS", "This is a comment");
887  uves_propertylist_append_string(list2, "TUNIT2", "This is a test");
888  uves_propertylist_set_comment(list2, "TUNIT2", "This is a comment");
889  uves_propertylist_append_string(list2, "TFORM1", "This is a test");
890  uves_propertylist_set_comment(list2, "TFORM1", "This is a comment");
891  uves_propertylist_append_string(list2, "TTYPE3", "This is a test");
892  uves_propertylist_set_comment(list2, "TTYPE3", "This is a comment");
893  uves_propertylist_append_bool(list2, "hierarch eso ins bool", 0);
894  uves_propertylist_set_comment(list2, "hierarch eso ins bool", "This is a comment");
895  uves_propertylist_append_int(list2, "hierarch eso det int", 111);
896  uves_propertylist_set_comment(list2, "hierarch eso det int", "This is a comment");
897  uves_propertylist_append_long(list2, "long", 111111111);
898  uves_propertylist_set_comment(list2, "long", "This is a comment");
899  uves_propertylist_append_float(list2, "float", 4.4);
900  uves_propertylist_set_comment(list2, "float", "This is a comment");
901  uves_propertylist_append_double(list2, "double", 8.8);
902  uves_propertylist_set_comment(list2, "double", "This is a comment");
903  uves_propertylist_append_char(list2, "char", 'D');
904  uves_propertylist_set_comment(list2, "char", "This is a comment");
905 ****/
906 
913 /****
914  uves_propertylist_delete(list1);
915  uves_propertylist_delete(list2);
916 ****/
917 
918  test_ivalue(10, cpl_table_get_nrow(table), "Check table length (1)... ");
919  test_ivalue(8, cpl_table_get_ncol(table), "Check table width... ");
920 
921  test_failure(CPL_ERROR_DATA_NOT_FOUND,
922  cpl_table_erase_column(table, "Diable"),
923  "Trying to delete a not existing column... ");
924 
925  test(cpl_table_erase_column(table, "DoubleDouble"),
926  "Delete column \"DoubleDouble\"... ");
927 
928  test_ivalue(7, cpl_table_get_ncol(table), "Check again table width... ");
929 
930  test_ivalue(CPL_TYPE_INT, cpl_table_get_column_type(table, "Integer"),
931  "Column Integer must be int... ");
932  test_ivalue(CPL_TYPE_DOUBLE, cpl_table_get_column_type(table, "Double"),
933  "Column Double must be double... ");
934  test_ivalue(CPL_TYPE_STRING, cpl_table_get_column_type(table, "String"),
935  "Column String must be char*... ");
936  test_ivalue(CPL_TYPE_FLOAT, cpl_table_get_column_type(table, "Float"),
937  "Column Float must be float... ");
938  test_ivalue((CPL_TYPE_INT | CPL_TYPE_POINTER),
939  cpl_table_get_column_type(table, "AInt"),
940  "Column AInt must be arrays of int... ");
941  test_ivalue((CPL_TYPE_DOUBLE | CPL_TYPE_POINTER),
942  cpl_table_get_column_type(table, "ADouble"),
943  "Column Double must be arrays of double... ");
944  test_ivalue((CPL_TYPE_FLOAT | CPL_TYPE_POINTER),
945  cpl_table_get_column_type(table, "AFloat"),
946  "Column Float must be arrays of float... ");
947 
948 // test_pvalue(iArray, cpl_table_get_data_int(table, "Integer"),
949 // "Check pointer to column Integer data... ");
950 // test_pvalue(dArray, cpl_table_get_data_double(table, "Double"),
951 // "Check pointer to column Double data... ");
952 // test_pvalue(sArray, cpl_table_get_data_string(table, "String"),
953 // "Check pointer to column String data... ");
954 
955 
956  copia = cpl_table_new(5);
957 
958  test(cpl_table_copy_structure(copia, table),
959  "Creating a new cpl_table modeled on an existing cpl_table... ");
960 
961  test_ivalue(5, cpl_table_get_nrow(copia), "Check table length (2)... ");
962  test_ivalue(7, cpl_table_get_ncol(copia), "Check table width... ");
963 
964  test(cpl_table_compare_structure(table, copia),
965  "Tables must have the same structure... ");
966  cpl_table_erase_column(copia, "Double");
967  test_ivalue(1, cpl_table_compare_structure(table, copia),
968  "Deleting column Double - now tables must have different structure... ");
969  test(cpl_table_new_column(copia, "Double", CPL_TYPE_DOUBLE),
970  "Creating again the Double column... ");
971  test(cpl_table_compare_structure(table, copia),
972  "Tables must have the same structure again... ");
973 
974  test(cpl_table_fill_column_window_int(copia, "Integer", 0, 5, -1),
975  "Fill column Integer of new table... ");
976  test(cpl_table_fill_column_window_double(copia, "Double", 0, 5, -1.11),
977  "Fill column Double of new table... ");
978  test(cpl_table_fill_column_window_float(copia, "Float", 0, 5, -1.1),
979  "Fill column Float of new table... ");
980  test(cpl_table_fill_column_window_string(copia, "String", 0, 5, "extra"),
981  "Fill column String of new table... ");
982 
983  array = cpl_array_new(2, CPL_TYPE_INT);
984  for (j = 0; j < 2; j++)
985  cpl_array_set_int(array, j, j);
986  test(cpl_table_fill_column_window_array(copia, "AInt", 0, 5, array),
987  "Fill column AInt of new table... ");
988  cpl_array_delete(array);
989 
990  array = cpl_array_new(2, CPL_TYPE_FLOAT);
991  for (j = 0; j < 2; j++)
992  cpl_array_set_float(array, j, j);
993  test(cpl_table_fill_column_window_array(copia, "AFloat", 0, 5, array),
994  "Fill column AFloat of new table... ");
995  cpl_array_delete(array);
996 
997  array = cpl_array_new(2, CPL_TYPE_DOUBLE);
998  for (j = 0; j < 2; j++)
999  cpl_array_set_double(array, j, j);
1000  test(cpl_table_fill_column_window_array(copia, "ADouble", 0, 5, array),
1001  "Fill column ADouble of new table... ");
1002  cpl_array_delete(array);
1003 
1004  test(cpl_table_insert(table, copia, 15),
1005  "Appending new table to old table... ");
1006  test(cpl_table_insert(table, copia, 5),
1007  "Inserting new table in old table... ");
1008  test(cpl_table_insert(table, copia, 0),
1009  "Prepending new table to old table... ");
1010 
1011  cpl_table_delete(copia);
1012 
1014  cpl_table_fill_invalid_int(table, "Integer", 320);
1015  cpl_table_fill_invalid_int(table, "AInt", 320);
1016  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1017  cpl_table_delete(table);
1018  table = cpl_table_load("test_table.tfits", 1, 1);
1019 
1020 
1021  test_ivalue(25, cpl_table_get_nrow(table), "Check table length (3)... ");
1022 
1023  icheck[0] = -1;
1024  icheck[1] = -1;
1025  icheck[2] = -1;
1026  icheck[3] = -1;
1027  icheck[4] = -1;
1028  icheck[5] = 5;
1029  icheck[6] = 0;
1030  icheck[7] = 2;
1031  icheck[8] = 8;
1032  icheck[9] = 9;
1033  icheck[10] = -1;
1034  icheck[11] = -1;
1035  icheck[12] = -1;
1036  icheck[13] = -1;
1037  icheck[14] = -1;
1038  icheck[15] = 3;
1039  icheck[16] = 7;
1040  icheck[17] = 1;
1041  icheck[18] = 4;
1042  icheck[19] = 6;
1043  icheck[20] = -1;
1044  icheck[21] = -1;
1045  icheck[22] = -1;
1046  icheck[23] = -1;
1047  icheck[24] = -1;
1048 
1049  error = 0;
1050 
1051  for (i = 0; i < 25; i++) {
1052  if (cpl_table_get_int(table, "Integer", i, NULL) != icheck[i]) {
1053  error = 1;
1054  break;
1055  }
1056  }
1057 
1058  if (error) {
1059  printf("Check Integer column... ");
1060  printf("Failure\n");
1061 
1062  return 1;
1063  }
1064 
1065  dcheck[0] = -1.1100;
1066  dcheck[1] = -1.1100;
1067  dcheck[2] = -1.1100;
1068  dcheck[3] = -1.1100;
1069  dcheck[4] = -1.1100;
1070  dcheck[5] = 5.1100;
1071  dcheck[6] = 0.1100;
1072  dcheck[7] = 2.1100;
1073  dcheck[8] = 8.1100;
1074  dcheck[9] = 9.1100;
1075  dcheck[10] = -1.1100;
1076  dcheck[11] = -1.1100;
1077  dcheck[12] = -1.1100;
1078  dcheck[13] = -1.1100;
1079  dcheck[14] = -1.1100;
1080  dcheck[15] = 3.1100;
1081  dcheck[16] = 7.1100;
1082  dcheck[17] = 1.1100;
1083  dcheck[18] = 4.1100;
1084  dcheck[19] = 6.1100;
1085  dcheck[20] = -1.1100;
1086  dcheck[21] = -1.1100;
1087  dcheck[22] = -1.1100;
1088  dcheck[23] = -1.1100;
1089  dcheck[24] = -1.1100;
1090 
1091  error = 0;
1092 
1093  for (i = 0; i < 25; i++) {
1094  if (fabs(cpl_table_get_double(table, "Double", i, NULL) - dcheck[i])
1095  > 0.00001) {
1096  error = 1;
1097  break;
1098  }
1099  }
1100 
1101  if (error) {
1102  printf("Check Double column... ");
1103  printf("Failure\n");
1104 
1105  return 1;
1106  }
1107 
1108  scheck[0] = "extra";
1109  scheck[1] = "extra";
1110  scheck[2] = "extra";
1111  scheck[3] = "extra";
1112  scheck[4] = "extra";
1113  scheck[5] = "caaa";
1114  scheck[6] = "abcd";
1115  scheck[7] = "aaaa";
1116  scheck[8] = "daaa";
1117  scheck[9] = "acde";
1118  scheck[10] = "extra";
1119  scheck[11] = "extra";
1120  scheck[12] = "extra";
1121  scheck[13] = "extra";
1122  scheck[14] = "extra";
1123  scheck[15] = "baaa";
1124  scheck[16] = "aaaa";
1125  scheck[17] = "acde";
1126  scheck[18] = " sss";
1127  scheck[19] = "daaa";
1128  scheck[20] = "extra";
1129  scheck[21] = "extra";
1130  scheck[22] = "extra";
1131  scheck[23] = "extra";
1132  scheck[24] = "extra";
1133 
1134  error = 0;
1135 
1136  for (i = 0; i < 25; i++) {
1137  if (strcmp(cpl_table_get_string(table, "String", i), scheck[i])) {
1138  error = 1;
1139  break;
1140  }
1141  }
1142 
1143  if (error) {
1144  printf("Check String column... ");
1145  printf("Failure\n");
1146 
1147  return 1;
1148  }
1149 
1150  fcheck[0] = -1.10;
1151  fcheck[1] = -1.10;
1152  fcheck[2] = -1.10;
1153  fcheck[3] = -1.10;
1154  fcheck[4] = -1.10;
1155  fcheck[5] = 5.10;
1156  fcheck[6] = 0.10;
1157  fcheck[7] = 2.10;
1158  fcheck[8] = 8.10;
1159  fcheck[9] = 9.10;
1160  fcheck[10] = -1.10;
1161  fcheck[11] = -1.10;
1162  fcheck[12] = -1.10;
1163  fcheck[13] = -1.10;
1164  fcheck[14] = -1.10;
1165  fcheck[15] = 3.10;
1166  fcheck[16] = 7.10;
1167  fcheck[17] = 1.10;
1168  fcheck[18] = 4.10;
1169  fcheck[19] = 6.10;
1170  fcheck[20] = -1.10;
1171  fcheck[21] = -1.10;
1172  fcheck[22] = -1.10;
1173  fcheck[23] = -1.10;
1174  fcheck[24] = -1.10;
1175 
1176  error = 0;
1177 
1178  for (i = 0; i < 25; i++) {
1179  if (fabs(cpl_table_get_float(table, "Float", i, NULL) - fcheck[i])
1180  > 0.00001) {
1181  error = 1;
1182  break;
1183  }
1184  }
1185 
1186  if (error) {
1187  printf("Check Float column... ");
1188  printf("Failure\n");
1189 
1190  return 1;
1191  }
1192 
1193  test(cpl_table_set_invalid(table, "Integer", 0),
1194  "Set Integer 0 to NULL... ");
1195  test(cpl_table_set_invalid(table, "Integer", 5),
1196  "Set Integer 5 to NULL... ");
1197  test(cpl_table_set_invalid(table, "Integer", 24),
1198  "Set Integer 24 to NULL... ");
1199 
1200  test(cpl_table_set_invalid(table, "AInt", 0),
1201  "Set AInt 0 to NULL... ");
1202  test(cpl_table_set_invalid(table, "AFloat", 5),
1203  "Set AFloat 5 to NULL... ");
1204  test(cpl_table_set_invalid(table, "ADouble", 24),
1205  "Set ADouble 24 to NULL... ");
1206 
1208  cpl_table_fill_invalid_int(table, "Integer", 320);
1209  cpl_table_fill_invalid_int(table, "AInt", 320);
1210  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1211  cpl_table_delete(table);
1212  table = cpl_table_load("test_table.tfits", 1, 1);
1213 
1214 
1215  test_ivalue(3, cpl_table_count_invalid(table, "Integer"),
1216  "Count Integer written NULLs... ");
1217  test_ivalue(1, cpl_table_count_invalid(table, "AInt"),
1218  "Count AInt written NULLs... ");
1219  test_ivalue(1, cpl_table_count_invalid(table, "AFloat"),
1220  "Count AFloat written NULLs... ");
1221  test_ivalue(1, cpl_table_count_invalid(table, "ADouble"),
1222  "Count ADouble written NULLs... ");
1223 
1224  error = 0;
1225 
1226  for (i = 0; i < 25; i++) {
1227  cpl_table_get_int(table, "Integer", i, &null);
1228  if (!null) {
1229  if (cpl_table_get_int(table, "Integer", i, &null) != icheck[i]) {
1230  error = 1;
1231  break;
1232  }
1233  }
1234  else if (i != 0 && i != 5 && i != 24) {
1235  error = 1;
1236  break;
1237  }
1238  }
1239 
1240  if (error) {
1241  printf("Check Integer column... ");
1242  printf("Failure\n");
1243 
1244  return 1;
1245  }
1246 
1247  test(cpl_table_set_int(table, "Integer", 0, -1),
1248  "Set Integer 0 to -1... ");
1249  test(cpl_table_set_int(table, "Integer", 5, 5),
1250  "Set Integer 5 to 5... ");
1251  test(cpl_table_set_int(table, "Integer", 24, -1),
1252  "Set Integer 24 to -1... ");
1253 
1254  array = cpl_array_new(2, CPL_TYPE_INT);
1255  for (j = 0; j < 2; j++)
1256  cpl_array_set_int(array, j, j);
1257  test(cpl_table_set_array(table, "AInt", 0, array),
1258  "Set a valid array to AInt 0... ");
1259  cpl_array_delete(array);
1260  test_ivalue(0, cpl_table_count_invalid(table, "AInt"),
1261  "No invalid elements in AInt... ");
1262 
1263  array = cpl_array_new(2, CPL_TYPE_FLOAT);
1264  for (j = 0; j < 2; j++)
1265  cpl_array_set_float(array, j, j);
1266  test(cpl_table_set_array(table, "AFloat", 5, array),
1267  "Set a valid array to AFloat 5... ");
1268  cpl_array_delete(array);
1269  test_ivalue(0, cpl_table_count_invalid(table, "AFloat"),
1270  "No invalid elements in AFloat... ");
1271 
1272  array = cpl_array_new(2, CPL_TYPE_DOUBLE);
1273  for (j = 0; j < 2; j++)
1274  cpl_array_set_double(array, j, j);
1275  test(cpl_table_set_array(table, "ADouble", 24, array),
1276  "Set a valid array to ADouble 24... ");
1277  cpl_array_delete(array);
1278  test_ivalue(0, cpl_table_count_invalid(table, "ADouble"),
1279  "No invalid elements in ADouble... ");
1280 
1282  cpl_table_fill_invalid_int(table, "Integer", 320);
1283  cpl_table_fill_invalid_int(table, "AInt", 320);
1284  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1285  cpl_table_delete(table);
1286  table = cpl_table_load("test_table.tfits", 1, 1);
1287 
1288 
1289  test_ivalue(0, cpl_table_count_invalid(table, "Integer"),
1290  "Count NULLs... ");
1291 
1292  error = 0;
1293 
1294  for (i = 0; i < 25; i++) {
1295  cpl_table_get_int(table, "Integer", i, &null);
1296  if (!null) {
1297  if (cpl_table_get_int(table, "Integer", i, &null) != icheck[i]) {
1298  error = 1;
1299  break;
1300  }
1301  }
1302  else {
1303  error = 1;
1304  break;
1305  }
1306  }
1307 
1308  if (error) {
1309  printf("Check Integer column... ");
1310  printf("Failure\n");
1311 
1312  return 1;
1313  }
1314 
1315  test(cpl_table_set_invalid(table, "Double", 0), "Set Double 0 to NULL... ");
1316  test(cpl_table_set_invalid(table, "Double", 5), "Set Double 5 to NULL... ");
1317  test(cpl_table_set_invalid(table, "Double", 24), "Set Double 24 to NULL... ");
1318 
1320  cpl_table_fill_invalid_int(table, "Integer", 320);
1321  cpl_table_fill_invalid_int(table, "AInt", 320);
1322  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1323  cpl_table_delete(table);
1324  table = cpl_table_load("test_table.tfits", 1, 1);
1325 
1326 
1327  test_ivalue(3, cpl_table_count_invalid(table, "Double"),
1328  "Count written NULLs... ");
1329 
1330  error = 0;
1331 
1332  for (i = 0; i < 25; i++) {
1333  cpl_table_get_double(table, "Double", i, &null);
1334  if (!null) {
1335  if (cpl_table_get_double(table, "Double", i, &null) != dcheck[i]) {
1336  error = 1;
1337  break;
1338  }
1339  }
1340  else if (i != 0 && i != 5 && i != 24) {
1341  error = 1;
1342  break;
1343  }
1344  }
1345 
1346  if (error) {
1347  printf("Check Double column... ");
1348  printf("Failure\n");
1349 
1350  return 1;
1351  }
1352 
1353  test(cpl_table_set_double(table, "Double", 0, -1.11),
1354  "Set Double 0 to -1.11... ");
1355  test(cpl_table_set_double(table, "Double", 5, 5.11),
1356  "Set Double 5 to 5.11... ");
1357  test(cpl_table_set_double(table, "Double", 24, -1.11),
1358  "Set Double 24 to -1.11... ");
1359 
1361  cpl_table_fill_invalid_int(table, "Integer", 320);
1362  cpl_table_fill_invalid_int(table, "AInt", 320);
1363  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1364  cpl_table_delete(table);
1365  table = cpl_table_load("test_table.tfits", 1, 1);
1366 
1367 
1368  test_ivalue(0, cpl_table_count_invalid(table, "Double"),
1369  "Count NULLs... ");
1370 
1371  error = 0;
1372 
1373  for (i = 0; i < 25; i++) {
1374  cpl_table_get_double(table, "Double", i, &null);
1375  if (!null) {
1376  if (fabs(cpl_table_get_double(table, "Double", i, &null)-dcheck[i])
1377  > 0.00001) {
1378  error = 1;
1379  break;
1380  }
1381  }
1382  else {
1383  error = 1;
1384  break;
1385  }
1386  }
1387 
1388  if (error) {
1389  printf("Check Double column... ");
1390  printf("Failure\n");
1391 
1392  return 1;
1393  }
1394 
1395 
1396  test(cpl_table_set_invalid(table, "String", 0), "Set String 0 to NULL... ");
1397  test(cpl_table_set_invalid(table, "String", 5), "Set String 5 to NULL... ");
1398  test(cpl_table_set_invalid(table, "String", 24), "Set String 24 to NULL... ");
1399 
1401  cpl_table_fill_invalid_int(table, "Integer", 320);
1402  cpl_table_fill_invalid_int(table, "AInt", 320);
1403  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1404  cpl_table_delete(table);
1405  table = cpl_table_load("test_table.tfits", 1, 1);
1406 
1407 
1408  test_ivalue(3, cpl_table_count_invalid(table, "String"),
1409  "Count written NULLs... ");
1410 
1411  error = 0;
1412 
1413  for (i = 0; i < 25; i++) {
1414  if (cpl_table_get_string(table, "String", i)) {
1415  if (strcmp(cpl_table_get_string(table, "String", i), scheck[i])) {
1416  error = 1;
1417  break;
1418  }
1419  }
1420  else if (i != 0 && i != 5 && i != 24) {
1421  error = 1;
1422  break;
1423  }
1424  }
1425 
1426  if (error) {
1427  printf("Check String column... ");
1428  printf("Failure\n");
1429 
1430  return 1;
1431  }
1432 
1433  test(cpl_table_set_string(table, "String", 0, "extra"),
1434  "Set String 0 to \"extra\"... ");
1435  test(cpl_table_set_string(table, "String", 5, "caaa"),
1436  "Set String 5 to \"caaa\"... ");
1437  test(cpl_table_set_string(table, "String", 24, "extra"),
1438  "Set String 24 to \"extra\"... ");
1439 
1441  cpl_table_fill_invalid_int(table, "Integer", 320);
1442  cpl_table_fill_invalid_int(table, "AInt", 320);
1443  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1444  cpl_table_delete(table);
1445  table = cpl_table_load("test_table.tfits", 1, 1);
1446 
1447 
1448  test_ivalue(0, cpl_table_count_invalid(table, "String"),
1449  "Count NULLs... ");
1450 
1451  error = 0;
1452 
1453  for (i = 0; i < 25; i++) {
1454  if (cpl_table_get_string(table, "String", i)) {
1455  if (strcmp(cpl_table_get_string(table, "String", i), scheck[i])) {
1456  error = 1;
1457  break;
1458  }
1459  }
1460  else {
1461  error = 1;
1462  break;
1463  }
1464  }
1465 
1466  if (error) {
1467  printf("Check String column... ");
1468  printf("Failure\n");
1469 
1470  return 1;
1471  }
1472 
1473 
1474  test(cpl_table_set_invalid(table, "Float", 0), "Set Float 0 to NULL... ");
1475  test(cpl_table_set_invalid(table, "Float", 5), "Set Float 5 to NULL... ");
1476  test(cpl_table_set_invalid(table, "Float", 24), "Set Float 24 to NULL... ");
1477 
1479  cpl_table_fill_invalid_int(table, "Integer", 320);
1480  cpl_table_fill_invalid_int(table, "AInt", 320);
1481  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1482  cpl_table_delete(table);
1483  table = cpl_table_load("test_table.tfits", 1, 1);
1484 
1485 
1486  test_ivalue(3, cpl_table_count_invalid(table, "Float"),
1487  "Count written NULLs... ");
1488 
1489  error = 0;
1490 
1491  for (i = 0; i < 25; i++) {
1492  cpl_table_get_float(table, "Float", i, &null);
1493  if (!null) {
1494  if (cpl_table_get_float(table, "Float", i, &null) != fcheck[i]) {
1495  error = 1;
1496  break;
1497  }
1498  }
1499  else if (i != 0 && i != 5 && i != 24) {
1500  error = 1;
1501  break;
1502  }
1503  }
1504 
1505  if (error) {
1506  printf("Check Float column... ");
1507  printf("Failure\n");
1508 
1509  return 1;
1510  }
1511 
1512  test(cpl_table_set_float(table, "Float", 0, -1.1),
1513  "Set Float 0 to -1.1... ");
1514  test(cpl_table_set_float(table, "Float", 5, 5.1),
1515  "Set Float 5 to 5.1... ");
1516  test(cpl_table_set_float(table, "Float", 24, -1.1),
1517  "Set Float 24 to -1.1... ");
1518 
1520  cpl_table_fill_invalid_int(table, "Integer", 320);
1521  cpl_table_fill_invalid_int(table, "AInt", 320);
1522  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1523  cpl_table_delete(table);
1524  table = cpl_table_load("test_table.tfits", 1, 1);
1525 
1526 
1527  test_ivalue(0, cpl_table_count_invalid(table, "Float"),
1528  "Count NULLs... ");
1529 
1530  error = 0;
1531 
1532  for (i = 0; i < 25; i++) {
1533  cpl_table_get_float(table, "Float", i, &null);
1534  if (!null) {
1535  if (fabs(cpl_table_get_float(table, "Float", i, &null)-fcheck[i])
1536  > 0.00001) {
1537  error = 1;
1538  break;
1539  }
1540  }
1541  else {
1542  error = 1;
1543  break;
1544  }
1545  }
1546 
1547  if (error) {
1548  printf("Check Float column... ");
1549  printf("Failure\n");
1550 
1551  return 1;
1552  }
1553 
1554  /* %%% */
1555 
1556  test(cpl_table_set_column_invalid(table, "Integer", 0, 3),
1557  "Set Integer 0-2 to NULL... ");
1558  test(cpl_table_set_column_invalid(table, "Integer", 5, 3),
1559  "Set Integer 5-7 to NULL... ");
1560  test(cpl_table_set_column_invalid(table, "Integer", 20, 20),
1561  "Set Integer 20 till end to NULL... ");
1562 
1563  test(cpl_table_set_column_invalid(table, "AInt", 0, 3),
1564  "Set AInt 0-2 to NULL... ");
1565  test(cpl_table_set_column_invalid(table, "AInt", 5, 3),
1566  "Set AInt 5-7 to NULL... ");
1567  test(cpl_table_set_column_invalid(table, "AInt", 20, 20),
1568  "Set AInt 20 till end to NULL... ");
1569 
1571  cpl_table_fill_invalid_int(table, "Integer", 320);
1572  cpl_table_fill_invalid_int(table, "AInt", 320);
1573  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1574  cpl_table_delete(table);
1575  table = cpl_table_load("test_table.tfits", 1, 1);
1576 
1577 
1578  test_ivalue(11, cpl_table_count_invalid(table, "Integer"),
1579  "Count Integer NULLs... ");
1580 
1581  test_ivalue(11, cpl_table_count_invalid(table, "AInt"),
1582  "Count AInt NULLs... ");
1583 
1584  error = 0;
1585 
1586  for (i = 0; i < 25; i++) {
1587  cpl_table_get_int(table, "Integer", i, &null);
1588  if (!null) {
1589  if (cpl_table_get_int(table, "Integer", i, &null) != icheck[i]) {
1590  error = 1;
1591  break;
1592  }
1593  }
1594  else if ((i > 2 && i < 5) || (i > 7 && i < 20)) {
1595  error = 1;
1596  break;
1597  }
1598  }
1599 
1600  if (error) {
1601  printf("Check Integer column... ");
1602  printf("Failure\n");
1603 
1604  return 1;
1605  }
1606 
1607  test(cpl_table_set_column_invalid(table, "Double", 0, 3),
1608  "Set Double 0-2 to NULL... ");
1609  test(cpl_table_set_column_invalid(table, "Double", 5, 3),
1610  "Set Double 5-7 to NULL... ");
1611  test(cpl_table_set_column_invalid(table, "Double", 20, 20),
1612  "Set Double 20 till end to NULL... ");
1613 
1615  cpl_table_fill_invalid_int(table, "Integer", 320);
1616  cpl_table_fill_invalid_int(table, "AInt", 320);
1617  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1618  cpl_table_delete(table);
1619  table = cpl_table_load("test_table.tfits", 1, 1);
1620 
1621 
1622  test_ivalue(11, cpl_table_count_invalid(table, "Double"),
1623  "Count written NULLs... ");
1624 
1625  error = 0;
1626 
1627  for (i = 0; i < 25; i++) {
1628  cpl_table_get_double(table, "Double", i, &null);
1629  if (!null) {
1630  if (fabs(cpl_table_get_double(table, "Double", i, &null)-dcheck[i])
1631  > 0.000001) {
1632  error = 1;
1633  break;
1634  }
1635  }
1636  else if ((i > 2 && i < 5) || (i > 7 && i < 20)) {
1637  error = 1;
1638  break;
1639  }
1640  }
1641 
1642  if (error) {
1643  printf("Check Double column... ");
1644  printf("Failure\n");
1645 
1646  return 1;
1647  }
1648 
1649 
1650  test(cpl_table_set_column_invalid(table, "Float", 0, 3),
1651  "Set Float 0-2 to NULL... ");
1652  test(cpl_table_set_column_invalid(table, "Float", 5, 3),
1653  "Set Float 5-7 to NULL... ");
1654  test(cpl_table_set_column_invalid(table, "Float", 20, 20),
1655  "Set Float 20 till end to NULL... ");
1656 
1658  cpl_table_fill_invalid_int(table, "Integer", 320);
1659  cpl_table_fill_invalid_int(table, "AInt", 320);
1660  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1661  cpl_table_delete(table);
1662  table = cpl_table_load("test_table.tfits", 1, 1);
1663 
1664 
1665  test_ivalue(11, cpl_table_count_invalid(table, "Float"),
1666  "Count written NULLs... ");
1667 
1668  error = 0;
1669 
1670  for (i = 0; i < 25; i++) {
1671  cpl_table_get_float(table, "Float", i, &null);
1672  if (!null) {
1673  if (fabs(cpl_table_get_float(table, "Float", i, &null)-fcheck[i])
1674  > 0.000001) {
1675  error = 1;
1676  break;
1677  }
1678  }
1679  else if ((i > 2 && i < 5) || (i > 7 && i < 20)) {
1680  error = 1;
1681  break;
1682  }
1683  }
1684 
1685  if (error) {
1686  printf("Check Float column... ");
1687  printf("Failure\n");
1688 
1689  return 1;
1690  }
1691 
1692 
1693  test(cpl_table_set_column_invalid(table, "String", 0, 3),
1694  "Set String 0-2 to NULL... ");
1695  test(cpl_table_set_column_invalid(table, "String", 5, 3),
1696  "Set String 5-7 to NULL... ");
1697  test(cpl_table_set_column_invalid(table, "String", 20, 20),
1698  "Set String 20 till end to NULL... ");
1699 
1701  cpl_table_fill_invalid_int(table, "Integer", 320);
1702  cpl_table_fill_invalid_int(table, "AInt", 320);
1703  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1704  cpl_table_delete(table);
1705  table = cpl_table_load("test_table.tfits", 1, 1);
1706 
1707 
1708  test_ivalue(11, cpl_table_count_invalid(table, "String"),
1709  "Count written NULLs... ");
1710 
1711  error = 0;
1712 
1713  for (i = 0; i < 25; i++) {
1714  if (cpl_table_get_string(table, "String", i)) {
1715  if (strcmp(cpl_table_get_string(table, "String", i), scheck[i])) {
1716  error = 1;
1717  break;
1718  }
1719  }
1720  else if ((i > 2 && i < 5) || (i > 7 && i < 20)) {
1721  error = 1;
1722  break;
1723  }
1724  }
1725 
1726  if (error) {
1727  printf("Check String column... ");
1728  printf("Failure\n");
1729 
1730  return 1;
1731  }
1732 
1733  test(cpl_table_erase_window(table, 21, 4), "Delete last 4 table rows... ");
1734 
1735  test(cpl_table_erase_window(table, 7, 4),
1736  "Delete table rows from 7 to 10... ");
1737 
1738  test(cpl_table_erase_window(table, 3, 3),
1739  "Delete table rows from 3 to 5... ");
1740 
1741  test(cpl_table_erase_window(table, 0, 2), "Delete first two table rows... ");
1742 
1743  test_ivalue(12, cpl_table_get_nrow(table), "Check table length (4)... ");
1744 
1745  test_ivalue(3, cpl_table_count_invalid(table, "Integer"),
1746  "Count Integer NULLs... ");
1747 
1748  test_ivalue(3, cpl_table_count_invalid(table, "Double"),
1749  "Count Double NULLs... ");
1750 
1751  test_ivalue(3, cpl_table_count_invalid(table, "String"),
1752  "Count String NULLs... ");
1753 
1754  test_ivalue(3, cpl_table_count_invalid(table, "Float"),
1755  "Count Float NULLs... ");
1756 
1757  test_ivalue(3, cpl_table_count_invalid(table, "AInt"),
1758  "Count AInt NULLs... ");
1759 
1760  test_ivalue(0, cpl_table_count_invalid(table, "ADouble"),
1761  "Count ADouble NULLs... ");
1762 
1763  test_ivalue(0, cpl_table_count_invalid(table, "AFloat"),
1764  "Count AFloat NULLs... ");
1765 
1766  test(cpl_table_insert_window(table, 20, 5),
1767  "Append 5 NULLs at table end... ");
1768 
1769  test(cpl_table_insert_window(table, 6, 4),
1770  "Insert segment of 4 NULLs at row 6... ");
1771 
1772  test(cpl_table_insert_window(table, 1, 2),
1773  "Insert segment of 2 NULLs at row 1... ");
1774 
1775  test_ivalue(23, cpl_table_get_nrow(table), "Check table length (5)... ");
1776 
1777  test_ivalue(14, cpl_table_count_invalid(table, "Integer"),
1778  "Count Integer NULLs... ");
1779 
1780  test_ivalue(14, cpl_table_count_invalid(table, "Double"),
1781  "Count Double NULLs... ");
1782 
1783  test_ivalue(14, cpl_table_count_invalid(table, "String"),
1784  "Count String NULLs... ");
1785 
1786  test_ivalue(14, cpl_table_count_invalid(table, "Float"),
1787  "Count Float NULLs... ");
1788 
1789  test(cpl_table_fill_column_window_int(table, "Integer", 0, 2, 999),
1790  "Write 999 in \"Integer\" column from 0 to 1... ");
1791 
1792  test(cpl_table_fill_column_window_int(table, "Integer", 3, 3, 999),
1793  "Write 999 in \"Integer\" column from 3 to 5... ");
1794 
1795  test(cpl_table_fill_column_window_int(table, "Integer", 7, 4, 999),
1796  "Write 999 in \"Integer\" column from 7 to 10... ");
1797 
1798  test(cpl_table_fill_column_window_int(table, "Integer", 20, 7, 999),
1799  "Write 999 in \"Integer\" column from 20 to end... ");
1800 
1801  test(cpl_table_fill_column_window_float(table, "Float", 0, 2, 999.99),
1802  "Write 999.99 in \"Float\" column from 0 to 1... ");
1803 
1804  test(cpl_table_fill_column_window_float(table, "Float", 3, 3, 999.99),
1805  "Write 999.99 in \"Float\" column from 3 to 5... ");
1806 
1807  test(cpl_table_fill_column_window_float(table, "Float", 7, 4, 999.99),
1808  "Write 999.99 in \"Float\" column from 7 to 10... ");
1809 
1810  test(cpl_table_fill_column_window_float(table, "Float", 20, 7, 999.99),
1811  "Write 999.99 in \"Float\" column from 20 to end... ");
1812 
1813  test(cpl_table_fill_column_window_double(table, "Double", 0, 2, 999.88),
1814  "Write 999.88 in \"Double\" column from 0 to 1... ");
1815 
1816  test(cpl_table_fill_column_window_double(table, "Double", 3, 3, 999.88),
1817  "Write 999.88 in \"Double\" column from 3 to 5... ");
1818 
1819  test(cpl_table_fill_column_window_double(table, "Double", 7, 4, 999.88),
1820  "Write 999.88 in \"Double\" column from 7 to 10... ");
1821 
1822  test(cpl_table_fill_column_window_double(table, "Double", 20, 7, 999.88),
1823  "Write 999.88 in \"Double\" column from 20 to end... ");
1824 
1825  test(cpl_table_fill_column_window_string(table, "String", 0, 2, "999"),
1826  "Write \"999\" in \"String\" column from 0 to 1... ");
1827 
1828  test(cpl_table_fill_column_window_string(table, "String", 3, 3, "999"),
1829  "Write \"999\" in \"String\" column from 3 to 5... ");
1830 
1831  test(cpl_table_fill_column_window_string(table, "String", 7, 4, "999"),
1832  "Write \"999\" in \"String\" column from 7 to 10... ");
1833 
1834  test(cpl_table_fill_column_window_string(table, "String", 20, 7, "999"),
1835  "Write \"999\" in \"String\" column from 20 to end... ");
1836 
1838  cpl_table_fill_invalid_int(table, "Integer", 320);
1839  cpl_table_fill_invalid_int(table, "AInt", 320);
1840  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1841  cpl_table_delete(table);
1842  table = cpl_table_load("test_table.tfits", 1, 1);
1843 
1844 
1845  test_ivalue(23, cpl_table_get_nrow(table), "Check table length (6)... ");
1846 
1847  test_ivalue(5, cpl_table_count_invalid(table, "Integer"),
1848  "Count Integer NULLs... ");
1849 
1850  test_ivalue(5, cpl_table_count_invalid(table, "Float"),
1851  "Count Float NULLs... ");
1852 
1853  test_ivalue(5, cpl_table_count_invalid(table, "Double"),
1854  "Count Double NULLs... ");
1855 
1856  test_ivalue(5, cpl_table_count_invalid(table, "String"),
1857  "Count String NULLs... ");
1858 
1859  test_ivalue(14, cpl_table_count_invalid(table, "AInt"),
1860  "Count AInt NULLs... ");
1861 
1862  test_ivalue(11, cpl_table_count_invalid(table, "AFloat"),
1863  "Count AFloat NULLs... ");
1864 
1865  test_ivalue(11, cpl_table_count_invalid(table, "ADouble"),
1866  "Count ADouble NULLs... ");
1867 
1868  test_ivalue(0, cpl_table_is_valid(table, "Integer", 2),
1869  "Check that third element of \"Integer\" is NULL... ");
1870 
1871  test_ivalue(1, cpl_table_is_valid(table, "Double", 0),
1872  "Check that first element of \"Double\" is not NULL... ");
1873 
1874  test_ivalue(1, cpl_table_is_valid(table, "String", 0),
1875  "Check that first element of \"String\" is not NULL... ");
1876 
1877  test_ivalue(0, cpl_table_is_valid(table, "String", 2),
1878  "Check that third element of \"String\" is NULL... ");
1879 
1880  test_ivalue(0, cpl_table_is_valid(table, "AInt", 17),
1881  "Check that third element of \"AInt\" is NULL... ");
1882 
1883  test_ivalue(1, cpl_table_is_valid(table, "ADouble", 17),
1884  "Check that first element of \"ADouble\" is not NULL... ");
1885 
1886  test_ivalue(1, cpl_table_is_valid(table, "AFloat", 17),
1887  "Check that third element of \"AFloat\" is NULL... ");
1888 
1889  test_data(copia, cpl_table_duplicate(table), "Duplicate table... ");
1890 
1891  test(cpl_table_duplicate_column(table, "New Integer", table, "Integer"),
1892  "Duplicate \"Integer\" column within same table... ");
1893 
1894  test(cpl_table_duplicate_column(table, "New Float", table, "Float"),
1895  "Duplicate \"Float\" column within same table... ");
1896 
1897  test(cpl_table_duplicate_column(table, "New Double", table, "Double"),
1898  "Duplicate \"Double\" column within same table... ");
1899 
1900  test(cpl_table_duplicate_column(table, "New String", table, "String"),
1901  "Duplicate \"String\" column within same table... ");
1902 
1903  test(cpl_table_duplicate_column(table, "New AInt", table, "AInt"),
1904  "Duplicate \"AInt\" column within same table... ");
1905 
1906  test(cpl_table_duplicate_column(table, "New AFloat", table, "AFloat"),
1907  "Duplicate \"AFloat\" column within same table... ");
1908 
1909  test(cpl_table_duplicate_column(table, "New ADouble", table, "ADouble"),
1910  "Duplicate \"ADouble\" column within same table... ");
1911 
1912  test_ivalue(5, cpl_table_count_invalid(table, "New Integer"),
1913  "Count New Integer NULLs... ");
1914 
1915  test_ivalue(5, cpl_table_count_invalid(table, "New Float"),
1916  "Count New Float NULLs... ");
1917 
1918  test_ivalue(5, cpl_table_count_invalid(table, "New Double"),
1919  "Count New Double NULLs... ");
1920 
1921  test_ivalue(5, cpl_table_count_invalid(table, "New String"),
1922  "Count New String NULLs... ");
1923 
1924  test_ivalue(14, cpl_table_count_invalid(table, "New AInt"),
1925  "Count New AInt NULLs... ");
1926 
1927  test_ivalue(11, cpl_table_count_invalid(table, "New AFloat"),
1928  "Count New AFloat NULLs... ");
1929 
1930  test_ivalue(11, cpl_table_count_invalid(table, "New ADouble"),
1931  "Count New ADouble NULLs... ");
1932 
1933  test(cpl_table_move_column(copia, "New Integer", table),
1934  "Moving column \"New Integer\" to another table... ");
1935 
1936  test(cpl_table_move_column(copia, "New Float", table),
1937  "Moving column \"New Float\" to another table... ");
1938 
1939  test(cpl_table_move_column(copia, "New Double", table),
1940  "Moving column \"New Double\" to another table... ");
1941 
1942  test(cpl_table_move_column(copia, "New String", table),
1943  "Moving column \"New String\" to another table... ");
1944 
1945  test_failure(CPL_ERROR_ILLEGAL_OUTPUT,
1946  cpl_table_name_column(copia, "New String", "String"),
1947  "Try illegal column renaming... ");
1948 
1949  test(cpl_table_name_column(copia, "New Integer", "Old Integer"),
1950  "Try legal column renaming... ");
1951 
1953  cpl_table_fill_invalid_int(table, "Integer", 320);
1954  cpl_table_fill_invalid_int(table, "AInt", 320);
1955  cpl_table_fill_invalid_int(table, "New AInt", 320);
1956  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
1957  cpl_table_delete(table);
1958  table = cpl_table_load("test_table.tfits", 1, 1);
1959 
1960 
1961  test_ivalue(!0, cpl_table_has_column(copia, "Old Integer"),
1962  "Check if column \"Old Integer\" exists... ");
1963 
1964  test_svalue("Integer", cpl_table_get_column_name(copia),
1965  "Check name column 1... ");
1966 
1967  test_svalue("Double", cpl_table_get_column_name(NULL),
1968  "Check name column 2... ");
1969 
1970  test_svalue("String", cpl_table_get_column_name(NULL),
1971  "Check name column 3... ");
1972 
1973  test_svalue("Float", cpl_table_get_column_name(NULL),
1974  "Check name column 4... ");
1975 
1976  test_svalue("AInt", cpl_table_get_column_name(NULL),
1977  "Check name column 5... ");
1978 
1979  test_svalue("AFloat", cpl_table_get_column_name(NULL),
1980  "Check name column 6... ");
1981 
1982  test_svalue("ADouble", cpl_table_get_column_name(NULL),
1983  "Check name column 7... ");
1984 
1985  test_svalue("Old Integer", cpl_table_get_column_name(NULL),
1986  "Check name column 8... ");
1987 
1988  test_svalue("New Float", cpl_table_get_column_name(NULL),
1989  "Check name column 9... ");
1990 
1991  test_svalue("New Double", cpl_table_get_column_name(NULL),
1992  "Check name column 10... ");
1993 
1994  test_svalue("New String", cpl_table_get_column_name(NULL),
1995  "Check name column 11... ");
1996 
1997  test_pvalue(NULL, (void *)cpl_table_get_column_name(NULL),
1998  "Check if no more colums... ");
1999 
2000  cpl_table_delete(copia);
2001 
2002 
2003  test(cpl_table_set_size(table, 30), "Expanding table to 30 rows... ");
2004 
2005 /*
2006  * The following would do the same as cpl_table_set_size(table, 30), in
2007  * case cpl_table_set_size() would be crossed out...
2008 
2009  test(cpl_table_insert_window(table, 24, 7), "Expanding table to 30 rows... ");
2010 */
2011 
2012  test_ivalue(12, cpl_table_count_invalid(table, "Integer"),
2013  "Count \"Integer\" NULLs... ");
2014 
2015  test_ivalue(12, cpl_table_count_invalid(table, "String"),
2016  "Count \"String\" NULLs... ");
2017 
2018  test(cpl_table_set_size(table, 22), "Truncating table to 22 rows... ");
2019 
2020 /*
2021  * The following would do the same as cpl_table_set_size(table, 30), in
2022  * case cpl_table_set_size() would be crossed out...
2023 
2024  test(cpl_table_erase_window(table, 22, 1000),
2025  "Truncating table to 22 rows... ");
2026 */
2027 
2029  cpl_table_fill_invalid_int(table, "Integer", 320);
2030  cpl_table_fill_invalid_int(table, "AInt", 320);
2031  cpl_table_fill_invalid_int(table, "New AInt", 320);
2032  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
2033  cpl_table_delete(table);
2034  table = cpl_table_load("test_table.tfits", 1, 1);
2035 
2036 
2037  test_ivalue(5, cpl_table_count_invalid(table, "Integer"),
2038  "Count \"Integer\" NULLs (2)... ");
2039 
2040  test_ivalue(5, cpl_table_count_invalid(table, "String"),
2041  "Count \"String\" NULLs (2)... ");
2042 
2043  test_data(copia, cpl_table_extract(table, 0, 5),
2044  "Creating subtable from rows 0-5 of original... ");
2045 
2046  test_ivalue(1, cpl_table_count_invalid(copia, "Integer"),
2047  "Count \"Integer\" NULLs... ");
2048 
2049  test_ivalue(1, cpl_table_count_invalid(copia, "String"),
2050  "Count \"String\" NULLs... ");
2051 
2052  cpl_table_delete(copia);
2053 
2054  test_data(copia, cpl_table_extract(table, 8, 5),
2055  "Creating subtable from rows 8-5 of original... ");
2056 
2057  test_ivalue(1, cpl_table_count_invalid(copia, "Float"),
2058  "Count \"Float\" NULLs... ");
2059 
2060  test_ivalue(1, cpl_table_count_invalid(copia, "String"),
2061  "Count \"String\" NULLs... ");
2062 
2063  cpl_table_delete(copia);
2064 
2065  test_data(copia, cpl_table_extract(table, 15, 30),
2066  "Creating subtable from rows 15 till end of original... ");
2067 
2068  test_ivalue(3, cpl_table_count_invalid(copia, "Double"),
2069  "Count \"Double\" NULLs... ");
2070 
2071  test_ivalue(3, cpl_table_count_invalid(copia, "String"),
2072  "Count \"String\" NULLs... ");
2073 
2074  cpl_table_delete(copia);
2075 
2076  test(cpl_table_cast_column(table, "Float", "FloatToInt", CPL_TYPE_INT),
2077  "Casting float column to integer colum... ");
2078 
2080  cpl_table_fill_invalid_int(table, "Integer", 320);
2081  cpl_table_fill_invalid_int(table, "FloatToInt", -2);
2082  cpl_table_fill_invalid_int(table, "AInt", 320);
2083  cpl_table_fill_invalid_int(table, "New AInt", 320);
2084  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
2085  cpl_table_delete(table);
2086  table = cpl_table_load("test_table.tfits", 1, 1);
2087 
2088 
2089  test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 0, NULL),
2090  "Check element 1 of casted column... ");
2091  test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 1, NULL),
2092  "Check element 2 of casted column... ");
2093  test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 2),
2094  "Check element 3 of casted column... ");
2095  test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 3, NULL),
2096  "Check element 4 of casted column... ");
2097  test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 4, NULL),
2098  "Check element 5 of casted column... ");
2099  test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 5, NULL),
2100  "Check element 6 of casted column... ");
2101  test_ivalue(-1, cpl_table_get_int(table, "FloatToInt", 6, NULL),
2102  "Check element 7 of casted column... ");
2103  test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 7, NULL),
2104  "Check element 8 of casted column... ");
2105  test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 8, NULL),
2106  "Check element 9 of casted column... ");
2107  test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 9, NULL),
2108  "Check element 10 of casted column... ");
2109  test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 10, NULL),
2110  "Check element 11 of casted column... ");
2111  test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 11),
2112  "Check element 12 of casted column... ");
2113  test_ivalue(3, cpl_table_get_int(table, "FloatToInt", 12, NULL),
2114  "Check element 13 of casted column... ");
2115  test_ivalue(7, cpl_table_get_int(table, "FloatToInt", 13, NULL),
2116  "Check element 14 of casted column... ");
2117  test_ivalue(1, cpl_table_get_int(table, "FloatToInt", 14, NULL),
2118  "Check element 15 of casted column... ");
2119  test_ivalue(4, cpl_table_get_int(table, "FloatToInt", 15, NULL),
2120  "Check element 16 of casted column... ");
2121  test_ivalue(6, cpl_table_get_int(table, "FloatToInt", 16, NULL),
2122  "Check element 17 of casted column... ");
2123  test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 17),
2124  "Check element 18 of casted column... ");
2125  test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 18),
2126  "Check element 19 of casted column... ");
2127  test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 19),
2128  "Check element 20 of casted column... ");
2129  test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 20, NULL),
2130  "Check element 21 of casted column... ");
2131  test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 21, NULL),
2132  "Check element 22 of casted column... ");
2133 
2134  test(cpl_table_erase_column(table, "FloatToInt"),
2135  "Delete casted column... ");
2136 
2137  test(cpl_table_cast_column(table, "Integer", "IntToFloat", CPL_TYPE_FLOAT),
2138  "Casting integer column to float colum... ");
2139 
2141  cpl_table_fill_invalid_int(table, "Integer", 320);
2142  cpl_table_fill_invalid_int(table, "AInt", 320);
2143  cpl_table_fill_invalid_int(table, "New AInt", 320);
2144  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
2145  cpl_table_delete(table);
2146  table = cpl_table_load("test_table.tfits", 1, 1);
2147 
2148 
2149  test_fvalue(999.0, 0.00001,
2150  cpl_table_get_float(table, "IntToFloat", 0, NULL),
2151  "Check element 1 of casted column (2)... ");
2152  test_fvalue(999.0, 0.00001,
2153  cpl_table_get_float(table, "IntToFloat", 1, NULL),
2154  "Check element 2 of casted column (2)... ");
2155  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2),
2156  "Check element 3 of casted column (2)... ");
2157  test_fvalue(999.0, 0.00001,
2158  cpl_table_get_float(table, "IntToFloat", 3, NULL),
2159  "Check element 4 of casted column (2)... ");
2160  test_fvalue(999.0, 0.00001,
2161  cpl_table_get_float(table, "IntToFloat", 4, NULL),
2162  "Check element 5 of casted column (2)... ");
2163  test_fvalue(999.0, 0.00001,
2164  cpl_table_get_float(table, "IntToFloat", 5, NULL),
2165  "Check element 6 of casted column (2)... ");
2166  test_fvalue(-1.0, 0.00001,
2167  cpl_table_get_float(table, "IntToFloat", 6, NULL),
2168  "Check element 7 of casted column (2)... ");
2169  test_fvalue(999.0, 0.00001,
2170  cpl_table_get_float(table, "IntToFloat", 7, NULL),
2171  "Check element 8 of casted column (2)... ");
2172  test_fvalue(999.0, 0.00001,
2173  cpl_table_get_float(table, "IntToFloat", 8, NULL),
2174  "Check element 9 of casted column (2)... ");
2175  test_fvalue(999.0, 0.00001,
2176  cpl_table_get_float(table, "IntToFloat", 9, NULL),
2177  "Check element 10 of casted column (2)... ");
2178  test_fvalue(999.0, 0.00001,
2179  cpl_table_get_float(table, "IntToFloat", 10, NULL),
2180  "Check element 11 of casted column (2)... ");
2181  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11),
2182  "Check element 12 of casted column (2)... ");
2183  test_fvalue(3.0, 0.00001,
2184  cpl_table_get_float(table, "IntToFloat", 12, NULL),
2185  "Check element 13 of casted column (2)... ");
2186  test_fvalue(7.0, 0.00001,
2187  cpl_table_get_float(table, "IntToFloat", 13, NULL),
2188  "Check element 14 of casted column (2)... ");
2189  test_fvalue(1.0, 0.00001,
2190  cpl_table_get_float(table, "IntToFloat", 14, NULL),
2191  "Check element 15 of casted column (2)... ");
2192  test_fvalue(4.0, 0.00001,
2193  cpl_table_get_float(table, "IntToFloat", 15, NULL),
2194  "Check element 16 of casted column (2)... ");
2195  test_fvalue(6.0, 0.00001,
2196  cpl_table_get_float(table, "IntToFloat", 16, NULL),
2197  "Check element 17 of casted column (2)... ");
2198  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17),
2199  "Check element 18 of casted column (2)... ");
2200  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18),
2201  "Check element 19 of casted column (2)... ");
2202  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19),
2203  "Check element 20 of casted column (2)... ");
2204  test_fvalue(999.0, 0.00001,
2205  cpl_table_get_float(table, "IntToFloat", 20, NULL),
2206  "Check element 21 of casted column (2)... ");
2207  test_fvalue(999.0, 0.00001,
2208  cpl_table_get_float(table, "IntToFloat", 21, NULL),
2209  "Check element 22 of casted column (2)... ");
2210 
2211  test(cpl_table_shift_column(table, "IntToFloat", 1),
2212  "Shift new column one position down... ");
2213 
2214  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0),
2215  "Check element 1 of shifted column... ");
2216  test_fvalue(999.0, 0.00001,
2217  cpl_table_get_float(table, "IntToFloat", 1, NULL),
2218  "Check element 2 of shifted column... ");
2219  test_fvalue(999.0, 0.00001,
2220  cpl_table_get_float(table, "IntToFloat", 2, NULL),
2221  "Check element 3 of shifted column... ");
2222  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3),
2223  "Check element 4 of shifted column... ");
2224  test_fvalue(999.0, 0.00001,
2225  cpl_table_get_float(table, "IntToFloat", 4, NULL),
2226  "Check element 5 of shifted column... ");
2227  test_fvalue(999.0, 0.00001,
2228  cpl_table_get_float(table, "IntToFloat", 5, NULL),
2229  "Check element 6 of shifted column... ");
2230  test_fvalue(999.0, 0.00001,
2231  cpl_table_get_float(table, "IntToFloat", 6, NULL),
2232  "Check element 7 of shifted column... ");
2233  test_fvalue(-1.0, 0.00001,
2234  cpl_table_get_float(table, "IntToFloat", 7, NULL),
2235  "Check element 8 of shifted column... ");
2236  test_fvalue(999.0, 0.00001,
2237  cpl_table_get_float(table, "IntToFloat", 8, NULL),
2238  "Check element 9 of shifted column... ");
2239  test_fvalue(999.0, 0.00001,
2240  cpl_table_get_float(table, "IntToFloat", 9, NULL),
2241  "Check element 10 of shifted column... ");
2242  test_fvalue(999.0, 0.00001,
2243  cpl_table_get_float(table, "IntToFloat", 10, NULL),
2244  "Check element 11 of shifted column... ");
2245  test_fvalue(999.0, 0.00001,
2246  cpl_table_get_float(table, "IntToFloat", 11, NULL),
2247  "Check element 12 of shifted column... ");
2248  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12),
2249  "Check element 13 of shifted column... ");
2250  test_fvalue(3.0, 0.00001,
2251  cpl_table_get_float(table, "IntToFloat", 13, NULL),
2252  "Check element 14 of shifted column... ");
2253  test_fvalue(7.0, 0.00001,
2254  cpl_table_get_float(table, "IntToFloat", 14, NULL),
2255  "Check element 15 of shifted column... ");
2256  test_fvalue(1.0, 0.00001,
2257  cpl_table_get_float(table, "IntToFloat", 15, NULL),
2258  "Check element 16 of shifted column... ");
2259  test_fvalue(4.0, 0.00001,
2260  cpl_table_get_float(table, "IntToFloat", 16, NULL),
2261  "Check element 17 of shifted column... ");
2262  test_fvalue(6.0, 0.00001,
2263  cpl_table_get_float(table, "IntToFloat", 17, NULL),
2264  "Check element 18 of shifted column... ");
2265  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18),
2266  "Check element 19 of shifted column... ");
2267  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19),
2268  "Check element 20 of shifted column... ");
2269  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20),
2270  "Check element 21 of shifted column... ");
2271  test_fvalue(999.0, 0.00001,
2272  cpl_table_get_float(table, "IntToFloat", 21, NULL),
2273  "Check element 22 of shifted column... ");
2274 
2275  test(cpl_table_add_columns(table, "Integer", "IntToFloat"),
2276  "Sum \"IntToFloat\" to \"Integer\"... ");
2277 
2279  cpl_table_fill_invalid_int(table, "Integer", 320);
2280  cpl_table_fill_invalid_int(table, "AInt", 320);
2281  cpl_table_fill_invalid_int(table, "New AInt", 320);
2282  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
2283  cpl_table_delete(table);
2284  table = cpl_table_load("test_table.tfits", 1, 1);
2285 
2286 
2287  test_ivalue(0, cpl_table_is_valid(table, "Integer", 0),
2288  "Check element 1 of \"Integer\" += \"IntToFloat\"... ");
2289  test_ivalue(1998, cpl_table_get_int(table, "Integer", 1, NULL),
2290  "Check element 2 of \"Integer\" += \"IntToFloat\"... ");
2291  test_ivalue(0, cpl_table_is_valid(table, "Integer", 2),
2292  "Check element 3 of \"Integer\" += \"IntToFloat\"... ");
2293  test_ivalue(0, cpl_table_is_valid(table, "Integer", 3),
2294  "Check element 4 of \"Integer\" += \"IntToFloat\"... ");
2295  test_ivalue(1998, cpl_table_get_int(table, "Integer", 4, NULL),
2296  "Check element 5 of \"Integer\" += \"IntToFloat\"... ");
2297  test_ivalue(1998, cpl_table_get_int(table, "Integer", 5, NULL),
2298  "Check element 6 of \"Integer\" += \"IntToFloat\"... ");
2299  test_ivalue(998, cpl_table_get_int(table, "Integer", 6, NULL),
2300  "Check element 7 of \"Integer\" += \"IntToFloat\"... ");
2301  test_ivalue(998, cpl_table_get_int(table, "Integer", 7, NULL),
2302  "Check element 8 of \"Integer\" += \"IntToFloat\"... ");
2303  test_ivalue(1998, cpl_table_get_int(table, "Integer", 8, NULL),
2304  "Check element 9 of \"Integer\" += \"IntToFloat\"... ");
2305  test_ivalue(1998, cpl_table_get_int(table, "Integer", 9, NULL),
2306  "Check element 10 of \"Integer\" += \"IntToFloat\"... ");
2307  test_ivalue(1998, cpl_table_get_int(table, "Integer", 10, NULL),
2308  "Check element 11 of \"Integer\" += \"IntToFloat\"... ");
2309  test_ivalue(0, cpl_table_is_valid(table, "Integer", 11),
2310  "Check element 12 of \"Integer\" += \"IntToFloat\"... ");
2311  test_ivalue(0, cpl_table_is_valid(table, "Integer", 12),
2312  "Check element 13 of \"Integer\" += \"IntToFloat\"... ");
2313  test_ivalue(10, cpl_table_get_int(table, "Integer", 13, NULL),
2314  "Check element 14 of \"Integer\" += \"IntToFloat\"... ");
2315  test_ivalue(8, cpl_table_get_int(table, "Integer", 14, NULL),
2316  "Check element 15 of \"Integer\" += \"IntToFloat\"... ");
2317  test_ivalue(5, cpl_table_get_int(table, "Integer", 15, NULL),
2318  "Check element 16 of \"Integer\" += \"IntToFloat\"... ");
2319  test_ivalue(10, cpl_table_get_int(table, "Integer", 16, NULL),
2320  "Check element 17 of \"Integer\" += \"IntToFloat\"... ");
2321  test_ivalue(0, cpl_table_is_valid(table, "Integer", 17),
2322  "Check element 18 of \"Integer\" += \"IntToFloat\"... ");
2323  test_ivalue(0, cpl_table_is_valid(table, "Integer", 18),
2324  "Check element 19 of \"Integer\" += \"IntToFloat\"... ");
2325  test_ivalue(0, cpl_table_is_valid(table, "Integer", 19),
2326  "Check element 20 of \"Integer\" += \"IntToFloat\"... ");
2327  test_ivalue(0, cpl_table_is_valid(table, "Integer", 20),
2328  "Check element 21 of \"Integer\" += \"IntToFloat\"... ");
2329  test_ivalue(1998, cpl_table_get_int(table, "Integer", 21, NULL),
2330  "Check element 22 of \"Integer\" += \"IntToFloat\"... ");
2331 
2332  test(cpl_table_subtract_columns(table, "Integer", "IntToFloat"),
2333  "Subtract \"IntToFloat\" from \"Integer\"... ");
2334 
2335  test(cpl_table_subtract_columns(table, "IntToFloat", "Integer"),
2336  "Subtract \"Integer\" from \"IntToFloat\"... ");
2337 
2338  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0),
2339  "Check element 1 of \"IntToFloat\" -= \"Integer\"... ");
2340  test_fvalue(0.0, 0.00001,
2341  cpl_table_get_float(table, "IntToFloat", 1, NULL),
2342  "Check element 2 of \"IntToFloat\" -= \"Integer\"... ");
2343  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2),
2344  "Check element 3 of \"IntToFloat\" -= \"Integer\"... ");
2345  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3),
2346  "Check element 4 of \"IntToFloat\" -= \"Integer\"... ");
2347  test_fvalue(0.0, 0.00001,
2348  cpl_table_get_float(table, "IntToFloat", 4, NULL),
2349  "Check element 5 of \"IntToFloat\" -= \"Integer\"... ");
2350  test_fvalue(0.0, 0.00001,
2351  cpl_table_get_float(table, "IntToFloat", 5, NULL),
2352  "Check element 6 of \"IntToFloat\" -= \"Integer\"... ");
2353  test_fvalue(1000.0, 0.00001,
2354  cpl_table_get_float(table, "IntToFloat", 6, NULL),
2355  "Check element 7 of \"IntToFloat\" -= \"Integer\"... ");
2356  test_fvalue(-1000.0, 0.00001,
2357  cpl_table_get_float(table, "IntToFloat", 7, NULL),
2358  "Check element 8 of \"IntToFloat\" -= \"Integer\"... ");
2359  test_fvalue(0.0, 0.00001,
2360  cpl_table_get_float(table, "IntToFloat", 8, NULL),
2361  "Check element 9 of \"IntToFloat\" -= \"Integer\"... ");
2362  test_fvalue(0.0, 0.00001,
2363  cpl_table_get_float(table, "IntToFloat", 9, NULL),
2364  "Check element 10 of \"IntToFloat\" -= \"Integer\"... ");
2365  test_fvalue(0.0, 0.00001,
2366  cpl_table_get_float(table, "IntToFloat", 10, NULL),
2367  "Check element 11 of \"IntToFloat\" -= \"Integer\"... ");
2368  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11),
2369  "Check element 12 of \"IntToFloat\" -= \"Integer\"... ");
2370  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12),
2371  "Check element 13 of \"IntToFloat\" -= \"Integer\"... ");
2372  test_fvalue(-4.0, 0.00001,
2373  cpl_table_get_float(table, "IntToFloat", 13, NULL),
2374  "Check element 14 of \"IntToFloat\" -= \"Integer\"... ");
2375  test_fvalue(6.0, 0.00001,
2376  cpl_table_get_float(table, "IntToFloat", 14, NULL),
2377  "Check element 15 of \"IntToFloat\" -= \"Integer\"... ");
2378  test_fvalue(-3.0, 0.00001,
2379  cpl_table_get_float(table, "IntToFloat", 15, NULL),
2380  "Check element 16 of \"IntToFloat\" -= \"Integer\"... ");
2381  test_fvalue(-2.0, 0.00001,
2382  cpl_table_get_float(table, "IntToFloat", 16, NULL),
2383  "Check element 17 of \"IntToFloat\" -= \"Integer\"... ");
2384  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17),
2385  "Check element 18 of \"IntToFloat\" -= \"Integer\"... ");
2386  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18),
2387  "Check element 19 of \"IntToFloat\" -= \"Integer\"... ");
2388  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19),
2389  "Check element 20 of \"IntToFloat\" -= \"Integer\"... ");
2390  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20),
2391  "Check element 21 of \"IntToFloat\" -= \"Integer\"... ");
2392  test_fvalue(0.0, 0.00001,
2393  cpl_table_get_float(table, "IntToFloat", 21, NULL),
2394  "Check element 22 of \"IntToFloat\" -= \"Integer\"... ");
2395 
2396  test(cpl_table_multiply_columns(table, "IntToFloat", "Double"),
2397  "Multiply double column with float column... ");
2398 
2399  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0),
2400  "Check element 1 of \"IntToFloat\" *= \"Double\"... ");
2401  test_fvalue(0.0, 0.00001,
2402  cpl_table_get_float(table, "IntToFloat", 1, NULL),
2403  "Check element 2 of \"IntToFloat\" *= \"Double\"... ");
2404  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2),
2405  "Check element 3 of \"IntToFloat\" *= \"Double\"... ");
2406  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3),
2407  "Check element 4 of \"IntToFloat\" *= \"Double\"... ");
2408  test_fvalue(0.0, 0.00001,
2409  cpl_table_get_float(table, "IntToFloat", 4, NULL),
2410  "Check element 5 of \"IntToFloat\" *= \"Double\"... ");
2411  test_fvalue(0.0, 0.00001,
2412  cpl_table_get_float(table, "IntToFloat", 5, NULL),
2413  "Check element 6 of \"IntToFloat\" *= \"Double\"... ");
2414  test_fvalue(-1110.0, 0.00001,
2415  cpl_table_get_float(table, "IntToFloat", 6, NULL),
2416  "Check element 7 of \"IntToFloat\" *= \"Double\"... ");
2417  test_fvalue(-999880.0, 0.00001,
2418  cpl_table_get_float(table, "IntToFloat", 7, NULL),
2419  "Check element 8 of \"IntToFloat\" *= \"Double\"... ");
2420  test_fvalue(0.0, 0.00001,
2421  cpl_table_get_float(table, "IntToFloat", 8, NULL),
2422  "Check element 9 of \"IntToFloat\" *= \"Double\"... ");
2423  test_fvalue(0.0, 0.00001,
2424  cpl_table_get_float(table, "IntToFloat", 9, NULL),
2425  "Check element 10 of \"IntToFloat\" *= \"Double\"... ");
2426  test_fvalue(0.0, 0.00001,
2427  cpl_table_get_float(table, "IntToFloat", 10, NULL),
2428  "Check element 11 of \"IntToFloat\" *= \"Double\"... ");
2429  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11),
2430  "Check element 12 of \"IntToFloat\" *= \"Double\"... ");
2431  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12),
2432  "Check element 13 of \"IntToFloat\" *= \"Double\"... ");
2433  test_fvalue(-28.44, 0.00001,
2434  cpl_table_get_float(table, "IntToFloat", 13, NULL),
2435  "Check element 14 of \"IntToFloat\" *= \"Double\"... ");
2436  test_fvalue(6.66, 0.00001,
2437  cpl_table_get_float(table, "IntToFloat", 14, NULL),
2438  "Check element 15 of \"IntToFloat\" *= \"Double\"... ");
2439  test_fvalue(-12.33, 0.00001,
2440  cpl_table_get_float(table, "IntToFloat", 15, NULL),
2441  "Check element 16 of \"IntToFloat\" *= \"Double\"... ");
2442  test_fvalue(-12.22, 0.00001,
2443  cpl_table_get_float(table, "IntToFloat", 16, NULL),
2444  "Check element 17 of \"IntToFloat\" *= \"Double\"... ");
2445  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17),
2446  "Check element 18 of \"IntToFloat\" *= \"Double\"... ");
2447  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18),
2448  "Check element 19 of \"IntToFloat\" *= \"Double\"... ");
2449  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19),
2450  "Check element 20 of \"IntToFloat\" *= \"Double\"... ");
2451  test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20),
2452  "Check element 21 of \"IntToFloat\" *= \"Double\"... ");
2453  test_fvalue(0.0, 0.00001,
2454  cpl_table_get_float(table, "IntToFloat", 21, NULL),
2455  "Check element 22 of \"IntToFloat\" *= \"Double\"... ");
2456 
2457  test(cpl_table_divide_columns(table, "Float", "IntToFloat"),
2458  "Divide float column with float column... ");
2459 
2460  test_ivalue(0, cpl_table_is_valid(table, "Float", 0),
2461  "Check element 1 of \"Float\" /= \"IntToFloat\"... ");
2462  test_ivalue(0, cpl_table_is_valid(table, "Float", 1),
2463  "Check element 2 of \"Float\" /= \"IntToFloat\"... ");
2464  test_ivalue(0, cpl_table_is_valid(table, "Float", 2),
2465  "Check element 3 of \"Float\" /= \"IntToFloat\"... ");
2466  test_ivalue(0, cpl_table_is_valid(table, "Float", 3),
2467  "Check element 4 of \"Float\" /= \"IntToFloat\"... ");
2468  test_ivalue(0, cpl_table_is_valid(table, "Float", 4),
2469  "Check element 5 of \"Float\" /= \"IntToFloat\"... ");
2470  test_ivalue(0, cpl_table_is_valid(table, "Float", 5),
2471  "Check element 6 of \"Float\" /= \"IntToFloat\"... ");
2472  test_fvalue(0.000991, 0.0000001,
2473  cpl_table_get_float(table, "Float", 6, NULL),
2474  "Check element 7 of \"Float\" /= \"IntToFloat\"... ");
2475  test_fvalue(-0.0010001, 0.0000001,
2476  cpl_table_get_float(table, "Float", 7, NULL),
2477  "Check element 8 of \"Float\" /= \"IntToFloat\"... ");
2478  test_ivalue(0, cpl_table_is_valid(table, "Float", 8),
2479  "Check element 9 of \"Float\" /= \"IntToFloat\"... ");
2480  test_ivalue(0, cpl_table_is_valid(table, "Float", 9),
2481  "Check element 10 of \"Float\" /= \"IntToFloat\"... ");
2482  test_ivalue(0, cpl_table_is_valid(table, "Float", 10),
2483  "Check element 11 of \"Float\" /= \"IntToFloat\"... ");
2484  test_ivalue(0, cpl_table_is_valid(table, "Float", 11),
2485  "Check element 12 of \"Float\" /= \"IntToFloat\"... ");
2486  test_ivalue(0, cpl_table_is_valid(table, "Float", 12),
2487  "Check element 13 of \"Float\" /= \"IntToFloat\"... ");
2488  test_fvalue(-0.2496484, 0.0000001,
2489  cpl_table_get_float(table, "Float", 13, NULL),
2490  "Check element 14 of \"Float\" /= \"IntToFloat\"... ");
2491  test_fvalue(0.1651652, 0.0000001,
2492  cpl_table_get_float(table, "Float", 14, NULL),
2493  "Check element 15 of \"Float\" /= \"IntToFloat\"... ");
2494  test_fvalue(-0.3325223, 0.0000001,
2495  cpl_table_get_float(table, "Float", 15, NULL),
2496  "Check element 16 of \"Float\" /= \"IntToFloat\"... ");
2497  test_fvalue(-0.4991817, 0.0000001,
2498  cpl_table_get_float(table, "Float", 16, NULL),
2499  "Check element 17 of \"Float\" /= \"IntToFloat\"... ");
2500  test_ivalue(0, cpl_table_is_valid(table, "Float", 17),
2501  "Check element 18 of \"Float\" /= \"IntToFloat\"... ");
2502  test_ivalue(0, cpl_table_is_valid(table, "Float", 18),
2503  "Check element 19 of \"Float\" /= \"IntToFloat\"... ");
2504  test_ivalue(0, cpl_table_is_valid(table, "Float", 19),
2505  "Check element 20 of \"Float\" /= \"IntToFloat\"... ");
2506  test_ivalue(0, cpl_table_is_valid(table, "Float", 20),
2507  "Check element 21 of \"Float\" /= \"IntToFloat\"... ");
2508  test_ivalue(0, cpl_table_is_valid(table, "Float", 21),
2509  "Check element 22 of \"Float\" /= \"IntToFloat\"... ");
2510 
2511  test(cpl_table_add_scalar(table, "Float", 1),
2512  "Add integer constant to \"Float\"... ");
2513 
2514  test_ivalue(0, cpl_table_is_valid(table, "Float", 0),
2515  "Check element 1 of adding 1 to \"Float\"... ");
2516  test_ivalue(0, cpl_table_is_valid(table, "Float", 1),
2517  "Check element 2 of adding 1 to \"Float\"... ");
2518  test_ivalue(0, cpl_table_is_valid(table, "Float", 2),
2519  "Check element 3 of adding 1 to \"Float\"... ");
2520  test_ivalue(0, cpl_table_is_valid(table, "Float", 3),
2521  "Check element 4 of adding 1 to \"Float\"... ");
2522  test_ivalue(0, cpl_table_is_valid(table, "Float", 4),
2523  "Check element 5 of adding 1 to \"Float\"... ");
2524  test_ivalue(0, cpl_table_is_valid(table, "Float", 5),
2525  "Check element 6 of adding 1 to \"Float\"... ");
2526  test_fvalue(1.000991, 0.0000001,
2527  cpl_table_get_float(table, "Float", 6, NULL),
2528  "Check element 7 of adding 1 to \"Float\"... ");
2529  test_fvalue(1-0.0010001, 0.0000001,
2530  cpl_table_get_float(table, "Float", 7, NULL),
2531  "Check element 8 of adding 1 to \"Float\"... ");
2532  test_ivalue(0, cpl_table_is_valid(table, "Float", 8),
2533  "Check element 9 of adding 1 to \"Float\"... ");
2534  test_ivalue(0, cpl_table_is_valid(table, "Float", 9),
2535  "Check element 10 of adding 1 to \"Float\"... ");
2536  test_ivalue(0, cpl_table_is_valid(table, "Float", 10),
2537  "Check element 11 of adding 1 to \"Float\"... ");
2538  test_ivalue(0, cpl_table_is_valid(table, "Float", 11),
2539  "Check element 12 of adding 1 to \"Float\"... ");
2540  test_ivalue(0, cpl_table_is_valid(table, "Float", 12),
2541  "Check element 13 of adding 1 to \"Float\"... ");
2542  test_fvalue(1-0.2496484, 0.0000001,
2543  cpl_table_get_float(table, "Float", 13, NULL),
2544  "Check element 14 of adding 1 to \"Float\"... ");
2545  test_fvalue(1.1651652, 0.0000001,
2546  cpl_table_get_float(table, "Float", 14, NULL),
2547  "Check element 15 of adding 1 to \"Float\"... ");
2548  test_fvalue(1-0.3325223, 0.0000001,
2549  cpl_table_get_float(table, "Float", 15, NULL),
2550  "Check element 16 of adding 1 to \"Float\"... ");
2551  test_fvalue(1-0.4991817, 0.0000001,
2552  cpl_table_get_float(table, "Float", 16, NULL),
2553  "Check element 17 of adding 1 to \"Float\"... ");
2554  test_ivalue(0, cpl_table_is_valid(table, "Float", 17),
2555  "Check element 18 of adding 1 to \"Float\"... ");
2556  test_ivalue(0, cpl_table_is_valid(table, "Float", 18),
2557  "Check element 19 of adding 1 to \"Float\"... ");
2558  test_ivalue(0, cpl_table_is_valid(table, "Float", 19),
2559  "Check element 20 of adding 1 to \"Float\"... ");
2560  test_ivalue(0, cpl_table_is_valid(table, "Float", 20),
2561  "Check element 21 of adding 1 to \"Float\"... ");
2562  test_ivalue(0, cpl_table_is_valid(table, "Float", 21),
2563  "Check element 22 of adding 1 to \"Float\"... ");
2564 
2565  test(cpl_table_set_column_invalid(table, "Float", 0,
2566  cpl_table_get_nrow(table)),
2567  "Set \"Float\" column to NULL... ");
2568 
2569  test_data(copia, cpl_table_duplicate(table), "Duplicate table... ");
2570 
2571  test(cpl_table_erase_invalid_rows(table), "Pruning table... ");
2572 
2573  test_ivalue(18, cpl_table_get_nrow(table),
2574  "Checking table length after pruning... ");
2575 
2576  test_ivalue(10, cpl_table_get_ncol(table),
2577  "Checking table width after pruning... ");
2578 
2579  test(cpl_table_erase_invalid(copia), "Cleaning table... ");
2580 
2581  test_ivalue(8, cpl_table_get_nrow(copia),
2582  "Checking table length after cleaning... ");
2583 
2584  test_ivalue(10, cpl_table_get_ncol(copia),
2585  "Checking table width after cleaning... ");
2586 
2587  cpl_table_delete(copia);
2588 
2589  test(cpl_table_name_column(table, "IntToFloat", "Float"),
2590  "Renaming \"IntToFloat\" to \"Float\"... ");
2591 
2592  test(cpl_table_set_column_invalid(table, "Integer", 7, 2),
2593  "Set NULLs in \"Integer\" column... ");
2594 
2595  test(cpl_table_set_invalid(table, "Float", 7),
2596  "Set NULL in \"Float\" column... ");
2597 
2598  test(cpl_table_set_invalid(table, "Float", 9),
2599  "Set another NULL in \"Float\" column... ");
2600 
2601  test(cpl_table_set_invalid(table, "Double", 7),
2602  "Set NULL in \"Double\" column... ");
2603 
2604  test(cpl_table_set_invalid(table, "String", 7),
2605  "Set NULL in \"String\" column... ");
2606 
2607  test(cpl_table_new_column(table, "Sequence", CPL_TYPE_INT),
2608  "Creating the \"Sequence\" column... ");
2609 
2610  for (i = 0; i < 18; i++) {
2611  sprintf(message, "Writing to row %d of the \"Sequence\" column... ", i);
2612  test(cpl_table_set_int(table, "Sequence", i, i), message);
2613  }
2614 /*
2615  cpl_table_dump_structure(table);
2616  cpl_table_dump(table, 0, cpl_table_get_nrow(table));
2617 */
2618  names[0] = "Integer";
2619 
2620  reflist = uves_propertylist_new();
2621  uves_propertylist_append_bool(reflist, names[0], 0);
2622 /* %$% */
2623 /*
2624 cpl_table_dump_structure(table, NULL);
2625 cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
2626 */
2627 
2628  test(uves_table_sort(table, reflist),
2629  "Sorting by increasing values of the \"Integer\" column... ");
2630 
2631  uves_propertylist_delete(reflist);
2632 
2634  cpl_table_fill_invalid_int(table, "Integer", 320);
2635  cpl_table_fill_invalid_int(table, "AInt", 320);
2636  cpl_table_fill_invalid_int(table, "New AInt", 320);
2637  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
2638  cpl_table_delete(table);
2639  table = cpl_table_load("test_table.tfits", 1, 1);
2640 
2641 
2642  test_ivalue(18, cpl_table_get_nrow(table),
2643  "Checking table length after sorting... ");
2644 
2645  test_ivalue(11, cpl_table_get_ncol(table),
2646  "Checking table width after sorting... ");
2647 
2648  test_ivalue(7, cpl_table_count_invalid(table, "Integer"),
2649  "Count \"Integer\" NULLs after sorting... ");
2650 
2651  test_ivalue(7, cpl_table_count_invalid(table, "Float"),
2652  "Count \"Float\" NULLs after sorting... ");
2653 
2654  test_ivalue(2, cpl_table_count_invalid(table, "Double"),
2655  "Count \"Double\" NULLs after sorting... ");
2656 
2657  test_ivalue(2, cpl_table_count_invalid(table, "String"),
2658  "Count \"String\" NULLs after sorting... ");
2659 
2660  for (i = 0; i < 7; i++) {
2661  sprintf(message, "Check element %d of sorted \"Integer\"... ", i + 1);
2662  test_ivalue(0, cpl_table_is_valid(table, "Integer", i), message);
2663  }
2664 
2665  test_ivalue(-1, cpl_table_get_int(table, "Integer", 7, NULL),
2666  "Check element 7 of sorted \"Integer\"... ");
2667 
2668  test_ivalue(1, cpl_table_get_int(table, "Integer", 8, NULL),
2669  "Check element 8 of sorted \"Integer\"... ");
2670 
2671  test_ivalue(4, cpl_table_get_int(table, "Integer", 9, NULL),
2672  "Check element 9 of sorted \"Integer\"... ");
2673 
2674  test_ivalue(6, cpl_table_get_int(table, "Integer", 10, NULL),
2675  "Check element 10 of sorted \"Integer\"... ");
2676 
2677  test_ivalue(7, cpl_table_get_int(table, "Integer", 11, NULL),
2678  "Check element 11 of sorted \"Integer\"... ");
2679 
2680  for (i = 12; i < 18; i++) {
2681  sprintf(message, "Check element %d of sorted \"Integer\"... ", i + 1);
2682  test_ivalue(999, cpl_table_get_int(table, "Integer", i, NULL),
2683  message);
2684  }
2685 
2686  test_fvalue(999.88, 0.00001,
2687  cpl_table_get_double(table, "Double", 0, NULL),
2688  "Check element 1 of sorted \"Double\"... ");
2689 
2690  test_fvalue(999.88, 0.00001,
2691  cpl_table_get_double(table, "Double", 1, NULL),
2692  "Check element 2 of sorted \"Double\"... ");
2693 
2694  test_ivalue(0, cpl_table_is_valid(table, "Double", 2),
2695  "Check element 3 of sorted \"Double\"... ");
2696 
2697  test_fvalue(999.88, 0.00001,
2698  cpl_table_get_double(table, "Double", 3, NULL),
2699  "Check element 4 of sorted \"Double\"... ");
2700 
2701  test_fvalue(3.11, 0.00001,
2702  cpl_table_get_double(table, "Double", 4, NULL),
2703  "Check element 5 of sorted \"Double\"... ");
2704 
2705  test_ivalue(0, cpl_table_is_valid(table, "Double", 5),
2706  "Check element 6 of sorted \"Double\"... ");
2707 
2708  test_fvalue(999.88, 0.00001,
2709  cpl_table_get_double(table, "Double", 6, NULL),
2710  "Check element 7 of sorted \"Double\"... ");
2711 
2712  test_fvalue(-1.11, 0.00001,
2713  cpl_table_get_double(table, "Double", 7, NULL),
2714  "Check element 8 of sorted \"Double\"... ");
2715 
2716  test_fvalue(1.11, 0.00001,
2717  cpl_table_get_double(table, "Double", 8, NULL),
2718  "Check element 9 of sorted \"Double\"... ");
2719 
2720  test_fvalue(4.11, 0.00001,
2721  cpl_table_get_double(table, "Double", 9, NULL),
2722  "Check element 10 of sorted \"Double\"... ");
2723 
2724  test_fvalue(6.11, 0.00001,
2725  cpl_table_get_double(table, "Double", 10, NULL),
2726  "Check element 11 of sorted \"Double\"... ");
2727 
2728  test_fvalue(7.11, 0.00001,
2729  cpl_table_get_double(table, "Double", 11, NULL),
2730  "Check element 12 of sorted \"Double\"... ");
2731 
2732  for (i = 12; i < 18; i++) {
2733  sprintf(message, "Check element %d of sorted \"Double\"... ", i + 1);
2734  test_fvalue(999.88, 0.00001,
2735  cpl_table_get_double(table, "Double", i, NULL), message);
2736  }
2737 
2738  test_svalue("999", cpl_table_get_string(table, "String", 0),
2739  "Check element 1 of sorted \"String\"... ");
2740 
2741  test_svalue("999", cpl_table_get_string(table, "String", 1),
2742  "Check element 2 of sorted \"String\"... ");
2743 
2744  test_ivalue(0, cpl_table_is_valid(table, "String", 2),
2745  "Check element 3 of sorted \"String\"... ");
2746 
2747  test_svalue("999", cpl_table_get_string(table, "String", 3),
2748  "Check element 4 of sorted \"String\"... ");
2749 
2750  test_svalue("baaa", cpl_table_get_string(table, "String", 4),
2751  "Check element 5 of sorted \"String\"... ");
2752 
2753  test_ivalue(0, cpl_table_is_valid(table, "String", 5),
2754  "Check element 6 of sorted \"String\"... ");
2755 
2756  test_svalue("999", cpl_table_get_string(table, "String", 6),
2757  "Check element 7 of sorted \"String\"... ");
2758 
2759  test_svalue("extra", cpl_table_get_string(table, "String", 7),
2760  "Check element 8 of sorted \"String\"... ");
2761 
2762  test_svalue("acde", cpl_table_get_string(table, "String", 8),
2763  "Check element 9 of sorted \"String\"... ");
2764 
2765  test_svalue(" sss", cpl_table_get_string(table, "String", 9),
2766  "Check element 10 of sorted \"String\"... ");
2767 
2768  test_svalue("daaa", cpl_table_get_string(table, "String", 10),
2769  "Check element 11 of sorted \"String\"... ");
2770 
2771  test_svalue("aaaa", cpl_table_get_string(table, "String", 11),
2772  "Check element 11 of sorted \"String\"... ");
2773 
2774  for (i = 12; i < 18; i++) {
2775  sprintf(message, "Check element %d of sorted \"String\"... ", i + 1);
2776  test_svalue("999", cpl_table_get_string(table, "String", i), message);
2777  }
2778 
2779 
2780  test_ivalue(0, cpl_table_is_valid(table, "Float", 0),
2781  "Check element 1 of sorted \"Float\"... ");
2782 
2783  test_ivalue(0, cpl_table_is_valid(table, "Float", 1),
2784  "Check element 2 of sorted \"Float\"... ");
2785 
2786  test_ivalue(0, cpl_table_is_valid(table, "Float", 2),
2787  "Check element 3 of sorted \"Float\"... ");
2788 
2789  test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 3, NULL),
2790  "Check element 4 of sorted \"Float\"... ");
2791 
2792  test_ivalue(0, cpl_table_is_valid(table, "Float", 4),
2793  "Check element 5 of sorted \"Float\"... ");
2794 
2795  test_ivalue(0, cpl_table_is_valid(table, "Float", 5),
2796  "Check element 6 of sorted \"Float\"... ");
2797 
2798  test_ivalue(0, cpl_table_is_valid(table, "Float", 6),
2799  "Check element 7 of sorted \"Float\"... ");
2800 
2801  test_fvalue(-1110.0, 0.00001,
2802  cpl_table_get_float(table, "Float", 7, NULL),
2803  "Check element 8 of sorted \"Float\"... ");
2804 
2805  test_fvalue(6.66, 0.00001,
2806  cpl_table_get_float(table, "Float", 8, NULL),
2807  "Check element 9 of sorted \"Float\"... ");
2808 
2809  test_fvalue(-12.33, 0.00001,
2810  cpl_table_get_float(table, "Float", 9, NULL),
2811  "Check element 10 of sorted \"Float\"... ");
2812 
2813  test_fvalue(-12.22, 0.00001,
2814  cpl_table_get_float(table, "Float", 10, NULL),
2815  "Check element 11 of sorted \"Float\"... ");
2816 
2817  test_fvalue(-28.44, 0.00001,
2818  cpl_table_get_float(table, "Float", 11, NULL),
2819  "Check element 12 of sorted \"Float\"... ");
2820 
2821  test_fvalue(0.0, 0.00001,
2822  cpl_table_get_float(table, "Float", 12, NULL),
2823  "Check element 13 of sorted \"Float\"... ");
2824 
2825  test_fvalue(0.0, 0.00001,
2826  cpl_table_get_float(table, "Float", 13, NULL),
2827  "Check element 14 of sorted \"Float\"... ");
2828 
2829  test_fvalue(0.0, 0.00001,
2830  cpl_table_get_float(table, "Float", 14, NULL),
2831  "Check element 15 of sorted \"Float\"... ");
2832 
2833  test_fvalue(-999880.0, 0.00001,
2834  cpl_table_get_float(table, "Float", 15, NULL),
2835  "Check element 16 of sorted \"Float\"... ");
2836 
2837  test_ivalue(0, cpl_table_is_valid(table, "Float", 16),
2838  "Check element 17 of sorted \"Float\"... ");
2839 
2840  test_fvalue(0.0, 0.00001,
2841  cpl_table_get_float(table, "Float", 17, NULL),
2842  "Check element 18 of sorted \"Float\"... ");
2843 
2844  names[0] = "Sequence";
2845 
2846  reflist = uves_propertylist_new();
2847  uves_propertylist_append_bool(reflist, names[0], 0);
2848 
2849  test(uves_table_sort(table, reflist), "Undo table sorting... ");
2850 
2851  uves_propertylist_delete(reflist);
2852 
2853  names[0] = "Integer";
2854  reverse[0] = 1;
2855 
2856  reflist = uves_propertylist_new();
2857  uves_propertylist_append_bool(reflist, names[0], 1);
2858 
2859  test(uves_table_sort(table, reflist),
2860  "Sorting by decreasing values of the \"Integer\" column... ");
2861 
2862 /* %$% */
2863 /*
2864 cpl_table_dump_structure(table, NULL);
2865 cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
2866 */
2867 
2868  uves_propertylist_delete(reflist);
2869 
2870 /*
2871  cpl_table_dump_structure(table, NULL);
2872  cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
2873 
2874  printf("Median of Integer: %d\n", cpl_table_median_int(table, "Integer"));
2875  printf("Median of Float: %f\n", cpl_table_median_float(table, "Float"));
2876  printf("Median of Double: %f\n", cpl_table_median_double(table, "Double"));
2877  printf("Median of Sequence: %d\n", cpl_table_median_int(table, "Sequence"));
2878 */
2879 
2880 /*
2881 
2882 cpl_table_dump_structure(table, NULL);
2883 cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
2884 
2885 */
2886 
2887  test_fvalue(999.000000, 0.001, cpl_table_get_column_median(table, "Integer"),
2888  "Median of Integer...");
2889  test_fvalue(0.000000, 0.001, cpl_table_get_column_median(table, "Float"),
2890  "Median of Float...");
2891  test_fvalue(999.880000, 0.001, cpl_table_get_column_median(table, "Double"),
2892  "Median of Double...");
2893  test_fvalue(8.000000, 0.001, cpl_table_get_column_median(table, "Sequence"),
2894  "Median of Sequence...");
2895  test_fvalue(546.454545, 0.001, cpl_table_get_column_mean(table, "Integer"),
2896  "Mean of Integer...");
2897  test_fvalue(-91003.302727, 0.001, cpl_table_get_column_mean(table, "Float"),
2898  "Mean of Float...");
2899  test_fvalue(626.202500, 0.001, cpl_table_get_column_mean(table, "Double"),
2900  "Mean of Double...");
2901  test_fvalue(8.500000, 0.001, cpl_table_get_column_mean(table, "Sequence"),
2902  "Mean of Sequence...");
2903  test_fvalue(519.939489, 0.001, cpl_table_get_column_stdev(table, "Integer"),
2904  "Stdev of Integer...");
2905  test_fvalue(301440.480937, 0.001, cpl_table_get_column_stdev(table, "Float"),
2906  "Stdev of Float...");
2907  test_fvalue(498.239830, 0.001, cpl_table_get_column_stdev(table, "Double"),
2908  "Stdev of Double...");
2909  test_fvalue(5.338539, 0.001, cpl_table_get_column_stdev(table, "Sequence"),
2910  "Stdev of Sequence...");
2911 
2912 /*
2913 
2914  printf("median of Integer: %f\n", cpl_table_get_column_median(table, "Integer"));
2915  printf("median of Float: %f\n", cpl_table_get_column_median(table, "Float"));
2916  printf("median of Double: %f\n", cpl_table_get_column_median(table, "Double"));
2917  printf("median of Sequence: %f\n", cpl_table_get_column_median(table, "Sequence"));
2918  printf("mean of Integer: %f\n", cpl_table_get_column_mean(table, "Integer"));
2919  printf("mean of Float: %f\n", cpl_table_get_column_mean(table, "Float"));
2920  printf("mean of Double: %f\n", cpl_table_get_column_mean(table, "Double"));
2921  printf("mean of Sequence: %f\n", cpl_table_get_column_mean(table, "Sequence"));
2922  printf("Stdev of Integer: %f\n", cpl_table_get_column_stdev(table, "Integer"));
2923  printf("Stdev of Float: %f\n", cpl_table_get_column_stdev(table, "Float"));
2924  printf("Stdev of Double: %f\n", cpl_table_get_column_stdev(table, "Double"));
2925  printf("Stdev of Sequence: %f\n", cpl_table_get_column_stdev(table, "Sequence"));
2926 */
2927 
2929  cpl_table_fill_invalid_int(table, "Integer", 320);
2930  cpl_table_fill_invalid_int(table, "AInt", 320);
2931  cpl_table_fill_invalid_int(table, "New AInt", 320);
2932  check_nomsg(cpl_table_save(table, NULL, NULL, "test_table.tfits", CPL_IO_DEFAULT));
2933  cpl_table_delete(table);
2934  table = cpl_table_load("test_table.tfits", 1, 1);
2935 
2936 
2937  test_ivalue(18, cpl_table_get_nrow(table),
2938  "Checking table length after decreasing sorting... ");
2939 
2940  test_ivalue(11, cpl_table_get_ncol(table),
2941  "Checking table width after decreasing sorting... ");
2942 
2943  test_ivalue(7, cpl_table_count_invalid(table, "Integer"),
2944  "Count \"Integer\" NULLs after decreasing sorting... ");
2945 
2946  test_ivalue(7, cpl_table_count_invalid(table, "Float"),
2947  "Count \"Float\" NULLs after decreasing sorting... ");
2948 
2949  test_ivalue(2, cpl_table_count_invalid(table, "Double"),
2950  "Count \"Double\" NULLs after decreasing sorting... ");
2951 
2952  test_ivalue(2, cpl_table_count_invalid(table, "String"),
2953  "Count \"String\" NULLs after decreasing sorting... ");
2954 
2955  for (i = 0; i < 7; i++) {
2956  sprintf(message, "Check element %d of sorted \"Integer\"... ", i + 1);
2957  test_ivalue(0, cpl_table_is_valid(table, "Integer", i), message);
2958  }
2959 
2960  for (i = 7; i < 13; i++) {
2961  sprintf(message, "Check element %d of sorted \"Integer\"... ", i + 1);
2962  test_ivalue(999, cpl_table_get_int(table, "Integer", i, NULL),
2963  message);
2964  }
2965 
2966  test_ivalue(7, cpl_table_get_int(table, "Integer", 13, NULL),
2967  "Check element 13 of sorted \"Integer\"... ");
2968 
2969  test_ivalue(6, cpl_table_get_int(table, "Integer", 14, NULL),
2970  "Check element 14 of sorted \"Integer\"... ");
2971 
2972  test_ivalue(4, cpl_table_get_int(table, "Integer", 15, NULL),
2973  "Check element 15 of sorted \"Integer\"... ");
2974 
2975  test_ivalue(1, cpl_table_get_int(table, "Integer", 16, NULL),
2976  "Check element 16 of sorted \"Integer\"... ");
2977 
2978  test_ivalue(-1, cpl_table_get_int(table, "Integer", 17, NULL),
2979  "Check element 17 of sorted \"Integer\"... ");
2980 
2981 
2982  test_fvalue(999.88, 0.00001,
2983  cpl_table_get_double(table, "Double", 0, NULL),
2984  "Check element 1 of sorted \"Double\"... ");
2985 
2986  test_fvalue(999.88, 0.00001,
2987  cpl_table_get_double(table, "Double", 1, NULL),
2988  "Check element 2 of sorted \"Double\"... ");
2989 
2990  test_ivalue(0, cpl_table_is_valid(table, "Double", 2),
2991  "Check element 3 of sorted \"Double\"... ");
2992 
2993  test_fvalue(999.88, 0.00001,
2994  cpl_table_get_double(table, "Double", 3, NULL),
2995  "Check element 4 of sorted \"Double\"... ");
2996 
2997  test_fvalue(3.11, 0.00001,
2998  cpl_table_get_double(table, "Double", 4, NULL),
2999  "Check element 5 of sorted \"Double\"... ");
3000 
3001  test_ivalue(0, cpl_table_is_valid(table, "Double", 5),
3002  "Check element 6 of sorted \"Double\"... ");
3003 
3004  test_fvalue(999.88, 0.00001,
3005  cpl_table_get_double(table, "Double", 6, NULL),
3006  "Check element 7 of sorted \"Double\"... ");
3007 
3008  for (i = 7; i < 13; i++) {
3009  sprintf(message, "Check element %d of sorted \"Double\"... ", i + 1);
3010  test_fvalue(999.88, 0.00001,
3011  cpl_table_get_double(table, "Double", i, NULL), message);
3012  }
3013 
3014  test_fvalue(7.11, 0.00001,
3015  cpl_table_get_double(table, "Double", 13, NULL),
3016  "Check element 14 of sorted \"Double\"... ");
3017 
3018  test_fvalue(6.11, 0.00001,
3019  cpl_table_get_double(table, "Double", 14, NULL),
3020  "Check element 15 of sorted \"Double\"... ");
3021 
3022  test_fvalue(4.11, 0.00001,
3023  cpl_table_get_double(table, "Double", 15, NULL),
3024  "Check element 16 of sorted \"Double\"... ");
3025 
3026  test_fvalue(1.11, 0.00001,
3027  cpl_table_get_double(table, "Double", 16, NULL),
3028  "Check element 17 of sorted \"Double\"... ");
3029 
3030  test_fvalue(-1.11, 0.00001,
3031  cpl_table_get_double(table, "Double", 17, NULL),
3032  "Check element 18 of sorted \"Double\"... ");
3033 
3034 
3035  test_svalue("999", cpl_table_get_string(table, "String", 0),
3036  "Check element 1 of sorted \"String\"... ");
3037 
3038  test_svalue("999", cpl_table_get_string(table, "String", 1),
3039  "Check element 2 of sorted \"String\"... ");
3040 
3041  test_ivalue(0, cpl_table_is_valid(table, "String", 2),
3042  "Check element 3 of sorted \"String\"... ");
3043 
3044  test_svalue("999", cpl_table_get_string(table, "String", 3),
3045  "Check element 4 of sorted \"String\"... ");
3046 
3047  test_svalue("baaa", cpl_table_get_string(table, "String", 4),
3048  "Check element 5 of sorted \"String\"... ");
3049 
3050  test_ivalue(0, cpl_table_is_valid(table, "String", 5),
3051  "Check element 6 of sorted \"String\"... ");
3052 
3053  test_svalue("999", cpl_table_get_string(table, "String", 6),
3054  "Check element 7 of sorted \"String\"... ");
3055 
3056  for (i = 7; i < 13; i++) {
3057  sprintf(message, "Check element %d of sorted \"String\"... ", i + 1);
3058  test_svalue("999", cpl_table_get_string(table, "String", i), message);
3059  }
3060 
3061  test_svalue("aaaa", cpl_table_get_string(table, "String", 13),
3062  "Check element 14 of sorted \"String\"... ");
3063 
3064  test_svalue("daaa", cpl_table_get_string(table, "String", 14),
3065  "Check element 15 of sorted \"String\"... ");
3066 
3067  test_svalue(" sss", cpl_table_get_string(table, "String", 15),
3068  "Check element 16 of sorted \"String\"... ");
3069 
3070  test_svalue("acde", cpl_table_get_string(table, "String", 16),
3071  "Check element 17 of sorted \"String\"... ");
3072 
3073  test_svalue("extra", cpl_table_get_string(table, "String", 17),
3074  "Check element 18 of sorted \"String\"... ");
3075 
3076 
3077  test_ivalue(0, cpl_table_is_valid(table, "Float", 0),
3078  "Check element 1 of sorted \"Float\"... ");
3079 
3080  test_ivalue(0, cpl_table_is_valid(table, "Float", 1),
3081  "Check element 2 of sorted \"Float\"... ");
3082 
3083  test_ivalue(0, cpl_table_is_valid(table, "Float", 2),
3084  "Check element 3 of sorted \"Float\"... ");
3085 
3086  test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 3, NULL),
3087  "Check element 4 of sorted \"Float\"... ");
3088 
3089  test_ivalue(0, cpl_table_is_valid(table, "Float", 4),
3090  "Check element 5 of sorted \"Float\"... ");
3091 
3092  test_ivalue(0, cpl_table_is_valid(table, "Float", 5),
3093  "Check element 6 of sorted \"Float\"... ");
3094 
3095  test_ivalue(0, cpl_table_is_valid(table, "Float", 6),
3096  "Check element 7 of sorted \"Float\"... ");
3097 
3098  test_fvalue(0.0, 0.00001,
3099  cpl_table_get_float(table, "Float", 7, NULL),
3100  "Check element 8 of sorted \"Float\"... ");
3101 
3102  test_fvalue(0.0, 0.00001,
3103  cpl_table_get_float(table, "Float", 8, NULL),
3104  "Check element 9 of sorted \"Float\"... ");
3105 
3106  test_fvalue(0.0, 0.00001,
3107  cpl_table_get_float(table, "Float", 9, NULL),
3108  "Check element 10 of sorted \"Float\"... ");
3109 
3110  test_fvalue(-999880.0, 0.00001,
3111  cpl_table_get_float(table, "Float", 10, NULL),
3112  "Check element 11 of sorted \"Float\"... ");
3113 
3114  test_ivalue(0, cpl_table_is_valid(table, "Float", 11),
3115  "Check element 12 of sorted \"Float\"... ");
3116 
3117  test_fvalue(0.0, 0.00001,
3118  cpl_table_get_float(table, "Float", 12, NULL),
3119  "Check element 13 of sorted \"Float\"... ");
3120 
3121  test_fvalue(-28.44, 0.00001,
3122  cpl_table_get_float(table, "Float", 13, NULL),
3123  "Check element 14 of sorted \"Float\"... ");
3124 
3125  test_fvalue(-12.22, 0.00001,
3126  cpl_table_get_float(table, "Float", 14, NULL),
3127  "Check element 15 of sorted \"Float\"... ");
3128 
3129  test_fvalue(-12.33, 0.00001,
3130  cpl_table_get_float(table, "Float", 15, NULL),
3131  "Check element 16 of sorted \"Float\"... ");
3132 
3133  test_fvalue(6.66, 0.00001,
3134  cpl_table_get_float(table, "Float", 16, NULL),
3135  "Check element 17 of sorted \"Float\"... ");
3136 
3137  test_fvalue(-1110.0, 0.00001,
3138  cpl_table_get_float(table, "Float", 17, NULL),
3139  "Check element 18 of sorted \"Float\"... ");
3140 
3141  cpl_table_delete(table);
3142  cpl_free(fArray);
3143 
3144  /*
3145  * Powers
3146  */
3147 
3148  nrows = 7;
3149 
3150  table = cpl_table_new(nrows);
3151  cpl_table_new_column(table, "Int", CPL_TYPE_INT);
3152  cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT);
3153  cpl_table_new_column(table, "Double", CPL_TYPE_DOUBLE);
3154 
3155  for (i = 0; i < nrows; i++) {
3156  cpl_table_set_int(table, "Int", i, i);
3157  cpl_table_set_float(table, "Float", i, i);
3158  cpl_table_set_double(table, "Double", i, i);
3159  }
3160 
3161  cpl_table_exponential_column(table, "Int", 2);
3162  cpl_table_exponential_column(table, "Float", 2);
3163  cpl_table_exponential_column(table, "Double", 2);
3164 
3165  pp = 1;
3166  for (i = 0; i < nrows; i++) {
3167  test_ivalue(pp, cpl_table_get_int(table,
3168  "Int", i, NULL), "Check expo Int... ");
3169  test_fvalue((float)pp, 0.00001, cpl_table_get_float(table,
3170  "Float", i, NULL), "Check expo Float... ");
3171  test_fvalue((float)pp, 0.00001, cpl_table_get_double(table,
3172  "Double", i, NULL), "Check expo Double... ");
3173  pp *= 2;
3174  }
3175 
3176  cpl_table_logarithm_column(table, "Int", 2);
3177  cpl_table_logarithm_column(table, "Float", 2);
3178  cpl_table_logarithm_column(table, "Double", 2);
3179 
3180  for (i = 0; i < nrows; i++) {
3181  test_ivalue(i, cpl_table_get_int(table,
3182  "Int", i, NULL), "Check log Int... ");
3183  test_fvalue((float)i, 0.00001, cpl_table_get_float(table,
3184  "Float", i, NULL), "Check log Float... ");
3185  test_fvalue((float)i, 0.00001, cpl_table_get_double(table,
3186  "Double", i, NULL), "Check log Double... ");
3187  }
3188 
3189  cpl_table_power_column(table, "Int", 2);
3190  cpl_table_power_column(table, "Float", 2);
3191  cpl_table_power_column(table, "Double", 2);
3192 
3193  for (i = 0; i < nrows; i++) {
3194  test_ivalue(i*i, cpl_table_get_int(table,
3195  "Int", i, NULL), "Check pow Int... ");
3196  test_fvalue((float)i*i, 0.00001, cpl_table_get_float(table,
3197  "Float", i, NULL), "Check pow Float... ");
3198  test_fvalue((float)i*i, 0.00001, cpl_table_get_double(table,
3199  "Double", i, NULL), "Check pow Double... ");
3200  }
3201 
3202  cpl_table_power_column(table, "Int", 0.5);
3203  cpl_table_power_column(table, "Float", 0.5);
3204  cpl_table_power_column(table, "Double", 0.5);
3205 
3206  for (i = 0; i < nrows; i++) {
3207  test_ivalue(i, cpl_table_get_int(table,
3208  "Int", i, NULL), "Check sqrt Int... ");
3209  test_fvalue((float)i, 0.00001, cpl_table_get_float(table,
3210  "Float", i, NULL), "Check sqrt Float... ");
3211  test_fvalue((float)i, 0.00001, cpl_table_get_double(table,
3212  "Double", i, NULL), "Check sqrt Double... ");
3213  }
3214 
3215  cpl_table_delete(table);
3216 
3217 
3218  /*
3219  * Testing the selection functions
3220  */
3221 
3222  nrows = 7;
3223 
3224  table = cpl_table_new(nrows);
3225  cpl_table_new_column(table, "Int", CPL_TYPE_INT);
3226  cpl_table_new_column(table, "String", CPL_TYPE_STRING);
3227 
3228  unit = "abcd\0efgh\0ijkl\0mnop\0qrst\0uvwx\0yz";
3229 
3230  for (i = 0; i < nrows; i++) {
3231  cpl_table_set_int(table, "Int", i, i);
3232  cpl_table_set_string(table, "String", i, unit + i*5);
3233  }
3234 
3235  cpl_table_duplicate_column(table, "Int2", table, "Int");
3236  cpl_table_multiply_columns(table, "Int2", "Int2");
3237  cpl_table_cast_column(table, "Int", "Float", CPL_TYPE_FLOAT);
3238 
3239 #ifdef VERBOSE
3240 
3241  printf("\nThis is the test table:\n\n");
3242  cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
3243 
3244  printf("\nNow erase all selected:\n\n");
3245 
3246 #endif
3247 
3248  copia = cpl_table_duplicate(table);
3249  test_ivalue(7, cpl_table_count_selected(copia), "Check all selected... ");
3250  cpl_table_erase_selected(copia);
3251 #ifdef VERBOSE
3252  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3253 #endif
3254  test_ivalue(0, cpl_table_get_nrow(copia),
3255  "Check length erase all selected... ");
3256  cpl_table_delete(copia);
3257 
3258 #ifdef VERBOSE
3259 
3260  printf("\nThis is the test table:\n\n");
3261  cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
3262 
3263  printf("\nNow delete all Int >= Int2:\n\n");
3264 
3265 #endif
3266 
3267  copia = cpl_table_duplicate(table);
3268  cpl_table_and_selected(copia, "Int", CPL_NOT_LESS_THAN, "Int2");
3269  test_ivalue(2, cpl_table_count_selected(copia),
3270  "Check Int >= Int2 selected... ");
3271  cpl_table_erase_selected(copia);
3272 #ifdef VERBOSE
3273  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3274 #endif
3275  test_ivalue(5, cpl_table_get_nrow(copia),
3276  "Check length erase all Int >= Int2... ");
3277  cpl_table_delete(copia);
3278 
3279 #ifdef VERBOSE
3280 
3281  printf("\nThis is the test table:\n\n");
3282  cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
3283 
3284  printf("\nNow delete all Int > 3:\n\n");
3285 
3286 #endif
3287 
3288  copia = cpl_table_duplicate(table);
3289  cpl_table_and_selected_int(copia, "Int", CPL_GREATER_THAN, 3);
3290  test_ivalue(3, cpl_table_count_selected(copia),
3291  "Check Int > 3 selected... ");
3292  cpl_table_erase_selected(copia);
3293 #ifdef VERBOSE
3294  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3295 #endif
3296  test_ivalue(4, cpl_table_get_nrow(copia),
3297  "Check length erase all Int > 3... ");
3298  cpl_table_delete(copia);
3299 
3300 #ifdef VERBOSE
3301 
3302  printf("\nThis is the test table:\n\n");
3303  cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
3304 
3305  printf("\nNow delete all Int2 > Float:\n\n");
3306 
3307 #endif
3308 
3309  copia = cpl_table_duplicate(table);
3310  cpl_table_and_selected(copia, "Int2", CPL_GREATER_THAN, "Float");
3311  test_ivalue(5, cpl_table_count_selected(copia),
3312  "Check Int2 > Float selected... ");
3313  cpl_table_erase_selected(copia);
3314 #ifdef VERBOSE
3315  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3316 #endif
3317  test_ivalue(2, cpl_table_get_nrow(copia),
3318  "Check length erase all Int2 > Float... ");
3319  cpl_table_delete(copia);
3320 
3321 #ifdef VERBOSE
3322 
3323  printf("\nThis is the test table:\n\n");
3324  cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
3325 
3326  printf("\nNow delete all String == \"^[a-l].*\":\n\n");
3327 
3328 #endif
3329 
3330  copia = cpl_table_duplicate(table);
3331  cpl_table_and_selected_string(copia, "String", CPL_EQUAL_TO, "^[a-l].*");
3332  test_ivalue(3, cpl_table_count_selected(copia),
3333  "Check String == \"^[a-l].*\" selected... ");
3334  cpl_table_erase_selected(copia);
3335 #ifdef VERBOSE
3336  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3337 #endif
3338  test_ivalue(4, cpl_table_get_nrow(copia),
3339  "Check length erase all String == \"^[a-l].*\"... ");
3340  cpl_table_delete(copia);
3341 
3342 #ifdef VERBOSE
3343 
3344  printf("\nThis is the test table:\n\n");
3345  cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
3346 
3347  printf("\nNow delete all String > \"carlo\":\n\n");
3348 
3349 #endif
3350 
3351  copia = cpl_table_duplicate(table);
3352  cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "carlo");
3353  test_ivalue(6, cpl_table_count_selected(copia),
3354  "Check String > \"carlo\" selected... ");
3355  cpl_table_erase_selected(copia);
3356 #ifdef VERBOSE
3357  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3358 #endif
3359  test_ivalue(1, cpl_table_get_nrow(copia),
3360  "Check length erase all String > \"carlo\"... ");
3361  cpl_table_delete(copia);
3362 
3363 #ifdef VERBOSE
3364 
3365  printf("\nThis is the test table:\n\n");
3366  cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
3367 
3368  printf("\nNow delete all String > \"tattoo\" and Int == 3:\n\n");
3369 
3370 #endif
3371 
3372  copia = cpl_table_duplicate(table);
3373  cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "tattoo");
3374  cpl_table_or_selected_int(copia, "Int", CPL_EQUAL_TO, 3);
3375  test_ivalue(3, cpl_table_count_selected(copia),
3376  "Check String > \"tattoo\" and Int == 3 selected... ");
3377  cpl_table_erase_selected(copia);
3378 #ifdef VERBOSE
3379  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3380 #endif
3381  test_ivalue(4, cpl_table_get_nrow(copia),
3382  "Check length erase all String > \"tattoo\" and Int == 3... ");
3383  cpl_table_delete(copia);
3384 
3385 #ifdef VERBOSE
3386 
3387  printf("\nNow keep all String > \"tattoo\" and Int == 3:\n\n");
3388 
3389 #endif
3390 
3391  copia = cpl_table_duplicate(table);
3392  cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "tattoo");
3393  cpl_table_or_selected_int(copia, "Int", CPL_EQUAL_TO, 3);
3394  cpl_table_not_selected(copia);
3395  test_ivalue(4, cpl_table_count_selected(copia),
3396  "Check String > \"tattoo\" and Int == 3 rejected... ");
3397  cpl_table_erase_selected(copia);
3398 #ifdef VERBOSE
3399  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3400 #endif
3401  test_ivalue(3, cpl_table_get_nrow(copia),
3402  "Check length keep all String > \"tattoo\" and Int == 3... ");
3403  cpl_table_delete(copia);
3404 
3405 #ifdef VERBOSE
3406 
3407  printf("\nThis is the test table:\n\n");
3408  cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
3409 
3410  printf("\nNow delete rows 0, 2, and 6:\n\n");
3411 
3412 #endif
3413 
3414  copia = cpl_table_duplicate(table);
3415  cpl_table_unselect_all(copia);
3416  cpl_table_select_row(copia, 0);
3417  cpl_table_select_row(copia, 2);
3418  cpl_table_select_row(copia, 6);
3419  test_ivalue(3, cpl_table_count_selected(copia),
3420  "Check rows 0, 2, and 6 selected... ");
3421  cpl_table_erase_selected(copia);
3422 #ifdef VERBOSE
3423  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3424 #endif
3425  test_ivalue(4, cpl_table_get_nrow(copia),
3426  "Check length erase rows 0, 2, and 6... ");
3427  cpl_table_delete(copia);
3428 
3429 #ifdef VERBOSE
3430 
3431  printf("\nNow keep rows 0, 2, and 6:\n\n");
3432 
3433 #endif
3434 
3435  copia = cpl_table_duplicate(table);
3436  cpl_table_unselect_row(copia, 0);
3437  cpl_table_unselect_row(copia, 2);
3438  cpl_table_unselect_row(copia, 6);
3439  test_ivalue(4, cpl_table_count_selected(copia),
3440  "Check rows 0, 2, and 6 rejected... ");
3441  cpl_table_erase_selected(copia);
3442 #ifdef VERBOSE
3443  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3444 #endif
3445  test_ivalue(3, cpl_table_get_nrow(copia),
3446  "Check length erase rows 0, 2, and 6... ");
3447  cpl_table_delete(copia);
3448 
3449 #ifdef VERBOSE
3450 
3451  printf("\nThis is the test table:\n\n");
3452  cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
3453 
3454  printf("\nNow delete first 3 rows:\n\n");
3455 
3456 #endif
3457 
3458  copia = cpl_table_duplicate(table);
3459  cpl_table_and_selected_window(copia, 0, 3);
3460  test_ivalue(3, cpl_table_count_selected(copia),
3461  "Check first 3 rows selected... ");
3462  cpl_table_erase_selected(copia);
3463 #ifdef VERBOSE
3464  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3465 #endif
3466  test_ivalue(4, cpl_table_get_nrow(copia),
3467  "Check length erase first 3 rows... ");
3468  cpl_table_delete(copia);
3469 
3470 #ifdef VERBOSE
3471 
3472  printf("\nNow delete last 2 rows:\n\n");
3473 
3474 #endif
3475 
3476  copia = cpl_table_duplicate(table);
3477  cpl_table_and_selected_window(copia, 5, 2);
3478  test_ivalue(2, cpl_table_count_selected(copia),
3479  "Check last 2 rows selected... ");
3480  cpl_table_erase_selected(copia);
3481 #ifdef VERBOSE
3482  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3483 #endif
3484  test_ivalue(5, cpl_table_get_nrow(copia),
3485  "Check length erase last 2 rows... ");
3486  cpl_table_delete(copia);
3487 
3488 #ifdef VERBOSE
3489 
3490  printf("\nNow delete rows from 2 to 3:\n\n");
3491 
3492 #endif
3493 
3494  copia = cpl_table_duplicate(table);
3495  cpl_table_and_selected_window(copia, 2, 2);
3496  test_ivalue(2, cpl_table_count_selected(copia),
3497  "Check middle 2 rows selected... ");
3498  cpl_table_erase_selected(copia);
3499 #ifdef VERBOSE
3500  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3501 #endif
3502  test_ivalue(5, cpl_table_get_nrow(copia),
3503  "Check length erase rows from 2 to 3... ");
3504  cpl_table_delete(copia);
3505 
3506 #ifdef VERBOSE
3507 
3508  printf("\nNow delete rows from 1 to 3 and row 6:\n\n");
3509 
3510 #endif
3511 
3512  copia = cpl_table_duplicate(table);
3513  cpl_table_and_selected_window(copia, 1, 3);
3514  cpl_table_or_selected_window(copia, 6, 1);
3515  test_ivalue(4, cpl_table_count_selected(copia),
3516  "Check rows 1 to 3 and row 6 rejected... ");
3517  cpl_table_erase_selected(copia);
3518 #ifdef VERBOSE
3519  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3520 #endif
3521  test_ivalue(3, cpl_table_get_nrow(copia),
3522  "Check length erase rows from 1 to 3 and row 6... ");
3523  cpl_table_delete(copia);
3524 
3525  /* Erase only invalid elements */
3526  copia = cpl_table_duplicate(table);
3527  for (i = 0; i < nrows; i++) {
3528  cpl_table_set_invalid(copia, "Int", i);
3529  }
3530 
3531  cpl_table_unselect_row(copia, nrows-1);
3532 
3533  cpl_table_erase_selected(copia);
3534 #ifdef VERBOSE
3535  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3536 #endif
3537  test_ivalue(1, cpl_table_get_nrow(copia),
3538  "Check length erase last row, only invalid values... ");
3539  cpl_table_delete(copia);
3540 
3541  /* Erase array column with valid/invalid values */
3542  copia = cpl_table_duplicate(table);
3543 
3544  cpl_table_cast_column(copia, "Int", "Double", CPL_TYPE_DOUBLE);
3545 
3546  test(cpl_table_new_column_array(copia, "ADouble",
3547  CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 2),
3548  "Creating the ArrayDouble column... ");
3549 
3550  array = cpl_array_new(2, CPL_TYPE_DOUBLE);
3551  test(cpl_table_set_array(copia, "ADouble", 1, array),
3552  "Set a valid array to ADouble 1... ");
3553  test(cpl_table_set_array(copia, "ADouble", 2, array),
3554  "Set a valid array to ADouble 2... ");
3555  cpl_array_delete(array);
3556 
3557  cpl_table_unselect_row(copia, 0);
3558  cpl_table_unselect_row(copia, 2);
3559  cpl_table_set_invalid(copia, "Int", 6);
3560  cpl_table_set_invalid(copia, "Int2", 0);
3561  cpl_table_set_invalid(copia, "Int2", 1);
3562  cpl_table_set_invalid(copia, "Double", 0);
3563  cpl_table_set_invalid(copia, "Double", 1);
3564 
3565  cpl_table_erase_selected(copia);
3566 #ifdef VERBOSE
3567  cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
3568 #endif
3569  test_ivalue(2, cpl_table_get_nrow(copia),
3570  "Check length erase valid/invalid values... ");
3571  test_ivalue(0, cpl_table_is_valid(copia, "Int2", 0),
3572  "Check that first element of \"Int2\" is still NULL... ");
3573  test_ivalue(1, cpl_table_is_valid(copia, "Int2", 1),
3574  "Check that first element of \"Int2\" is now valid... ");
3575 
3576  cpl_table_unselect_row(copia, 0);
3577  cpl_table_unselect_row(copia, 1);
3578  cpl_table_erase_selected(copia);
3579  test_ivalue(2, cpl_table_count_selected(copia),
3580  "Check that rows are selected... ");
3581 
3582  cpl_table_delete(copia);
3583 
3584  cpl_table_delete(table);
3585 
3586 
3587 
3588  table = cpl_table_new(4);
3589  cpl_table_new_column(table, "S", CPL_TYPE_STRING);
3590  cpl_table_new_column(table, "D", CPL_TYPE_DOUBLE);
3591 
3592  cpl_table_set_double(table, "D", 0, 43.04);
3593  cpl_table_set_double(table, "D", 1, 43.04);
3594  cpl_table_set_double(table, "D", 2, 43.04);
3595  cpl_table_set_double(table, "D", 3, 43.04);
3596  cpl_table_set_invalid(table, "D", 3);
3597 
3598  cpl_table_set_string(table, "S", 0, "type");
3599  cpl_table_set_string(table, "S", 1, "type");
3600  cpl_table_set_string(table, "S", 2, "type");
3601  cpl_table_set_string(table, "S", 3, "type");
3602  cpl_table_set_invalid(table, "S", 1);
3603 
3604 #ifdef VERBOSE
3605  cpl_table_dump(table, 0, 4, stdout);
3606 #endif
3607 
3608  cpl_table_select_all(table);
3609  test_ivalue(4, cpl_table_count_selected(table), "A...");
3610  cpl_table_and_selected_invalid(table, "D");
3611  test_ivalue(1, cpl_table_count_selected(table), "B...");
3612 
3613  cpl_table_select_all(table);
3614  test_ivalue(4, cpl_table_count_selected(table), "C...");
3615 
3616 //fails: cpl_table_and_selected_invalid(table, "S");
3617  uves_table_and_selected_invalid(table, "S");
3618 
3619  test_ivalue(1, cpl_table_count_selected(table), "D...");
3620 
3621  cpl_table_delete(table);
3622 
3623 
3624  /*
3625  * Test case: dividing a double column by integer
3626  */
3627 
3628  nrows = 100;
3629 
3630  table = cpl_table_new(nrows);
3631  cpl_table_new_column(table, "Int", CPL_TYPE_INT);
3632 
3633  for (i = 0; i < nrows; i++)
3634  cpl_table_set_int(table, "Int", i, i + 1);
3635 
3636  cpl_table_cast_column(table, "Int", "Double", CPL_TYPE_DOUBLE);
3637 
3638  test(cpl_table_divide_columns(table, "Double", "Int"),
3639  "Divide double column with integer column... ");
3640 
3641  for (i = 0; i < nrows; i++) {
3642  sprintf(message, "Check element %d of result column... ", i);
3643  test_fvalue(1.0, 0.00001, cpl_table_get_double(table, "Double", i, NULL),
3644  message);
3645  }
3646 
3647 #ifdef VERBOSE
3648  cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
3649 #endif
3650 
3651  cpl_table_delete(table);
3652 
3653 /*
3654  table = cpl_table_load("/home/cizzo/qfits/qfits/test/asciitable.tfits", 1, 1);
3655  table = cpl_table_load("/home/cizzo/qfits/qfits/test/bintable.tfits", 1, 1);
3656 
3657  names[0] = "IDENT";
3658  names[1] = "Mag";
3659  reverse[0] = 0;
3660  reverse[1] = 1;
3661  uves_table_sort(table, names, 2, reverse);
3662 
3663  cpl_table_dump_structure(table);
3664  cpl_table_dump(table, 0, cpl_table_get_nrow(table));
3665 */
3666  cleanup:
3667  return cpl_error_get_code();
3668 
3669 }
3670 
3671 
3672 
3673 /*----------------------------------------------------------------------------*/
3677 /*----------------------------------------------------------------------------*/
3678 
3679 int main(void)
3680 {
3681  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
3682 
3683  cpl_test_eq(0, table_erase_selected());
3684  uves_find_property_test();
3685  uves_average_reject_test();
3686  uves_polynomial_fit_2d_test();
3687 
3688  //uves_filter_cosmic_test();
3689 
3690  return cpl_test_end(0);
3691 }
3692 
void uves_polynomial_delete(polynomial **p)
Delete a polynomial.
cpl_error_code uves_rcosmic(cpl_image *ima, cpl_image **flt, cpl_image **out, cpl_image **msk, const double sky, const double ron, const double gain, const int ns, const double rc)
Remove cosmic ray events on single ccd exposure and replace them by interpolation on neighbourhood pi...
Definition: uves_utils.c:162
#define check_nomsg(CMD)
Definition: uves_error.h:204
double uves_average_reject(cpl_table *t, const char *column, const char *residual2, double kappa)
Get average with iterative rejection.
Definition: uves_utils.c:2513
uves_propertylist * uves_propertylist_new(void)
Create an empty property list.
double uves_gaussrand(void)
Pseudo-random gaussian distributed number.
Definition: uves_utils.c:3645
int main(void)
Test utility functions.
double uves_polynomial_evaluate_2d(const polynomial *p, double x1, double x2)
Evaluate a 2d polynomial.
static int table_erase_selected(void)
#define uves_error_reset()
Definition: uves_error.h:215
void uves_propertylist_delete(const uves_propertylist *self)
Destroy a property list.
polynomial * uves_polynomial_fit_2d(const cpl_bivector *xy_pos, const cpl_vector *values, const cpl_vector *sigmas, int poly_deg1, int poly_deg2, double *mse, double *red_chisq, polynomial **variance)
Fit a 2d surface with a polynomial in x and y.