uves_utils-test.c

00001 /*                                                                              *
00002  *   This file is part of the ESO UVES Pipeline                                 *
00003  *   Copyright (C) 2004,2005 European Southern Observatory                      *
00004  *                                                                              *
00005  *   This library is free software; you can redistribute it and/or modify       *
00006  *   it under the terms of the GNU General Public License as published by       *
00007  *   the Free Software Foundation; either version 2 of the License, or          *
00008  *   (at your option) any later version.                                        *
00009  *                                                                              *
00010  *   This program is distributed in the hope that it will be useful,            *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
00013  *   GNU General Public License for more details.                               *
00014  *                                                                              *
00015  *   You should have received a copy of the GNU General Public License          *
00016  *   along with this program; if not, write to the Free Software                *
00017  *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA       *
00018  *                                                                              */
00019  
00020 /*
00021  * $Author: amodigli $
00022  * $Date: 2007/08/30 07:56:05 $
00023  * $Revision: 1.5 $
00024  * $Name: uves-3_4_5 $
00025  * $Log: uves_utils-test.c,v $
00026  * Revision 1.5  2007/08/30 07:56:05  amodigli
00027  * fixed some doxygen warnings
00028  *
00029  * Revision 1.4  2007/05/23 06:43:23  jmlarsen
00030  * Removed unused variables
00031  *
00032  * Revision 1.3  2007/04/24 12:50:29  jmlarsen
00033  * Replaced cpl_propertylist -> uves_propertylist which is much faster
00034  *
00035  * Revision 1.2  2007/03/19 13:52:10  jmlarsen
00036  * Added tests of CPL table workarounds
00037  *
00038  * Revision 1.1  2007/03/15 12:27:18  jmlarsen
00039  * Moved unit tests to ./uves/tests and ./flames/tests
00040  *
00041  * Revision 1.2  2007/03/05 09:42:34  jmlarsen
00042  * Added tests
00043  *
00044  * Revision 1.1  2007/02/27 14:10:53  jmlarsen
00045  * Added test
00046  *
00047  *
00048  */
00049 
00050 /*-----------------------------------------------------------------------------
00051                                 Includes
00052  -----------------------------------------------------------------------------*/
00053 
00054 #ifdef HAVE_CONFIG_H
00055 #  include <config.h>
00056 #endif
00057 
00058 #include <uves_utils.h>
00059 #include <uves_utils_cpl.h>
00060 #include <uves_utils_polynomial.h>
00061 #include <uves_utils_wrappers.h>
00062 #include <uves_error.h>
00063 
00064 #include <irplib_test.h>
00065 #include <cpl.h>
00066 
00067 #include <stdlib.h>
00068 
00069 /*-----------------------------------------------------------------------------
00070                             Defines
00071  -----------------------------------------------------------------------------*/
00072 
00073 /*
00074  *   The following is duplicated from CPL's unit test
00075  *   to test the workaround for cpl_table_erase_selected()
00076  */
00077 
00078 
00079 
00080 
00081 #ifdef VERBOSE
00082 
00083 #define test_data(r,f,m)    \
00084 printf(m);                  \
00085 fflush(stdout);             \
00086 fflush(stderr);             \
00087 r = f;                      \
00088 if (!r) {                   \
00089   printf("Failure\n");      \
00090                   \
00091   return 1;                 \
00092 }                           \
00093 printf("OK\n")
00094 
00095 #else
00096 
00097 #define test_data(r,f,m)    \
00098 r = f;                      \
00099 if (!r) {                   \
00100   printf(m);                \
00101   printf("Failure\n");      \
00102                   \
00103   return 1;                 \
00104 }
00105 
00106 #endif
00107 
00108 
00109 /*
00110  * Test for functions returning 0 on success.
00111  *
00112  * f = function call
00113  * m = message
00114  */
00115 
00116 #ifdef VERBOSE
00117 
00118 #define test(f,m)           \
00119 printf(m);                  \
00120 fflush(stdout);             \
00121 fflush(stderr);             \
00122 if (f) {                    \
00123   printf("Failure\n");      \
00124                   \
00125   return 1;                 \
00126 }                           \
00127 printf("OK\n")
00128 
00129 #else
00130 
00131 #define test(f,m)           \
00132 if (f) {                    \
00133   printf(m);                \
00134   printf("Failure\n");      \
00135                   \
00136   return 1;                 \
00137 }
00138 
00139 #endif
00140 
00141 /*
00142  * Test for expected failure in functions returning 0 on success.
00143  *
00144  * e = expected error code
00145  * f = function call
00146  * m = message
00147  */
00148 
00149 #ifdef VERBOSE
00150 
00151 #define test_failure(e,f,m)                                         \
00152 printf(m);                                                          \
00153 fflush(stdout);                                                     \
00154 fflush(stderr);                                                     \
00155 if (f != e) {                                                       \
00156   printf("\n");                                                     \
00157   printf("     Received error: \"%s\"\n", cpl_error_get_message()); \
00158   cpl_error_set("cpl_table-test", e);                               \
00159   printf("     Expected error: \"%s\"\n", cpl_error_get_message()); \
00160                   \
00161   return 1;                                                         \
00162 }                                                                   \
00163 cpl_error_reset();                                                  \
00164 printf("OK\n")
00165 
00166 #else
00167 
00168 #define test_failure(e,f,m)                                         \
00169 if (f != e) {                                                       \
00170   printf(m);                                                        \
00171   printf("\n");                                                     \
00172   printf("     Received error: \"%s\"\n", cpl_error_get_message()); \
00173   cpl_error_set("cpl_table-test", e);                               \
00174   printf("     Expected error: \"%s\"\n", cpl_error_get_message()); \
00175                   \
00176   return 1;                                                         \
00177 }                                                                   \
00178 cpl_error_reset()
00179 
00180 #endif
00181 
00182 
00183 /*
00184  * Test for functions returning an expected integer value.
00185  *
00186  * e = expected value
00187  * f = function call
00188  * m = message
00189  */
00190 
00191 #ifdef VERBOSE
00192 
00193 #define test_ivalue(e,f,m)                        \
00194 printf(m);                                        \
00195 fflush(stdout);                                   \
00196 fflush(stderr);                                   \
00197 itest = f;                                        \
00198 if (itest != e) {                                 \
00199   printf("Received %d, expected %d\n", itest, e); \
00200                   \
00201   return 1;                                       \
00202 }                                                 \
00203 printf("OK\n")
00204 
00205 #else
00206 
00207 #define test_ivalue(e,f,m)                        \
00208 itest = f;                                        \
00209 if (itest != e) {                                 \
00210   printf(m);                                      \
00211   printf("Received %d, expected %d\n", itest, e); \
00212                   \
00213   return 1;                                       \
00214 }
00215 
00216 #endif
00217 
00218 
00219 /*
00220  * Test for functions returning an expected pointer value.
00221  *
00222  * e = expected value
00223  * f = function call
00224  * m = message
00225  */
00226 
00227 #ifdef VERBOSE
00228 
00229 #define test_pvalue(e,f,m)                        \
00230 printf(m);                                        \
00231 fflush(stdout);             \
00232 fflush(stderr);             \
00233 ptest = f;                                        \
00234 if (ptest != e) {                                 \
00235   printf("Received %p, expected %p\n", ptest, e); \
00236                   \
00237   return 1;                                       \
00238 }                                                 \
00239 printf("OK\n")
00240 
00241 #else
00242 
00243 #define test_pvalue(e,f,m)                        \
00244 ptest = f;                                        \
00245 if (ptest != e) {                                 \
00246   printf(m);                                      \
00247   printf("Received %p, expected %p\n", ptest, e); \
00248                   \
00249   return 1;                                       \
00250 }
00251 
00252 #endif
00253 
00254 /*
00255  * Test for functions returning an expected floating point value.
00256  *
00257  * e = expected value
00258  * t = tolerance on expected value
00259  * f = function call
00260  * m = message
00261  */
00262   
00263 #ifdef VERBOSE
00264 
00265 #define test_fvalue(e,t,f,m)                      \
00266 printf(m);                                        \
00267 fflush(stdout);             \
00268 fflush(stderr);             \
00269 ftest = f;                                        \
00270 if (fabs(ftest - (e)) > t) {                        \
00271   printf("Received %f, expected %f\n", ftest, e); \
00272                   \
00273   return 1;                                       \
00274 }                                                 \
00275 printf("OK\n")
00276 
00277 #else
00278 
00279 #define test_fvalue(e,t,f,m)                      \
00280 ftest = f;                                        \
00281 if (fabs(ftest - (e)) > t) {                        \
00282   printf(m);                                      \
00283   printf("Received %f, expected %f\n", ftest, e); \
00284                   \
00285   return 1;                                       \
00286 }
00287 
00288 #endif
00289 
00290 /*
00291  * Test for functions returning an expected character string.
00292  *
00293  * e = expected value
00294  * f = function call
00295  * m = message
00296  */
00297 
00298 #ifdef VERBOSE
00299 
00300 #define test_svalue(e,f,m)                        \
00301 printf(m);                                        \
00302 fflush(stdout);             \
00303 fflush(stderr);             \
00304 stest = f;                                        \
00305 if (strcmp(e,stest)) {                            \
00306   printf("Received %s, expected %s\n", stest, e); \
00307                   \
00308   return 1;                                       \
00309 }                                                 \
00310 printf("OK\n")
00311 
00312 #else
00313 
00314 #define test_svalue(e,f,m)                        \
00315 stest = f;                                        \
00316 if (strcmp(e,stest)) {                            \
00317   printf(m);                                      \
00318   printf("Received %s, expected %s\n", stest, e); \
00319                   \
00320   return 1;                                       \
00321 }
00322 
00323 #endif
00324 
00325 
00326 
00327 /*-----------------------------------------------------------------------------
00328                             Functions prototypes
00329  -----------------------------------------------------------------------------*/
00330 
00331 /*-----------------------------------------------------------------------------
00332                             Implementation
00333  -----------------------------------------------------------------------------*/
00334 
00335 
00336 
00337 /*----------------------------------------------------------------------------*/
00341 /*----------------------------------------------------------------------------*/
00345 static void
00346 uves_find_property_test(void)
00347 {
00348     uves_propertylist *header = uves_propertylist_new();
00349 
00350     uves_propertylist_append_int(header, "INTVAL", 3);
00351     uves_propertylist_append_double(header, "HELLO", 98.12);
00352     uves_propertylist_append_int(header, "INTVAL", 3);
00353     uves_propertylist_append_double(header, "HELLO", 98.12);
00354     uves_propertylist_append_int(header, "INTVAL", 3);
00355 
00356     irplib_test( uves_find_property(header, "INTVAL", 0) != NULL);
00357     irplib_test( uves_find_property(header, "INTVAL", 1) != NULL);
00358     irplib_test( uves_find_property(header, "INTVAL", 2) != NULL);
00359     irplib_test( uves_find_property(header, "INTVAL", 3) == NULL);
00360     irplib_test( uves_find_property(header, "INTVAL", 4) == NULL);
00361 
00362     uves_free_propertylist(&header);
00363 
00364     return;
00365 }
00366 
00367 static void
00368 uves_average_reject_test(void)
00369 {
00370     cpl_table *table = cpl_table_new(100);
00371     int i;
00372 
00373     cpl_table_new_column(table, "X", CPL_TYPE_DOUBLE);
00374     cpl_table_set_double(table, "X", 0, 100);
00375     cpl_table_set_double(table, "X", 1, 101);
00376     cpl_table_set_double(table, "X", 2, 2000); /* Outlier here */
00377     cpl_table_set_double(table, "X", 3,  98);
00378     cpl_table_set_double(table, "X", 4, 103);
00379     cpl_table_set_double(table, "X", 5, 102);
00380     cpl_table_set_double(table, "X", 6, 100);
00381     cpl_table_set_double(table, "X", 7, 103);
00382     cpl_table_set_double(table, "X", 8, 100);
00383     cpl_table_set_double(table, "X", 9, 99);
00384 
00385     srand(0); /* For reproducability */
00386     for (i = 10; i < 100; i++)
00387         {
00388             cpl_table_set_double(table, "X", i, 100 + 3*uves_gaussrand());
00389             
00390         }
00391     {
00392         double kappa = 4.0;
00393         double expected_avg = 100;
00394         double tolerance = 3.0;
00395         
00396         irplib_test( 2000 - 100 > kappa * cpl_table_get_column_stdev(table, "X"));
00397 
00398         irplib_test_abs( uves_average_reject(table, "X", "temp", kappa),
00399                          expected_avg, tolerance);
00400     }
00401     irplib_test_eq( cpl_table_get_nrow(table), 99);
00402     irplib_test_abs( cpl_table_get_double(table, "X", 0, NULL), 100, 0.1);
00403     irplib_test_abs( cpl_table_get_double(table, "X", 1, NULL), 101, 0.1);
00404     irplib_test_abs( cpl_table_get_double(table, "X", 2, NULL),  98, 0.1);
00405     irplib_test_abs( cpl_table_get_double(table, "X", 3, NULL), 103, 0.1);
00406 
00407     uves_free_table(&table);
00408 
00409     return;
00410 }                     
00411 
00412 static void
00413 uves_polynomial_fit_2d_test(void)
00414 {
00415     unsigned size = 4;
00416     cpl_bivector *xy_pos = cpl_bivector_new(size);
00417     cpl_vector *values = cpl_vector_new(size);
00418     cpl_vector *sigmas = NULL;
00419     int deg1 = 0;
00420     int deg2 = 0;
00421     polynomial *solution;
00422 
00423     /* "good" input */
00424     cpl_bivector_get_x_data(xy_pos)[0] = 1;
00425     cpl_bivector_get_x_data(xy_pos)[1] = 2;
00426     cpl_bivector_get_x_data(xy_pos)[2] = 3;
00427     cpl_bivector_get_x_data(xy_pos)[3] = 4;
00428 
00429     cpl_bivector_get_y_data(xy_pos)[0] = 4;
00430     cpl_bivector_get_y_data(xy_pos)[1] = 3;
00431     cpl_bivector_get_y_data(xy_pos)[2] = 2;
00432     cpl_bivector_get_y_data(xy_pos)[3] = 1;
00433 
00434     cpl_vector_get_data(values)[0] = 17;
00435     cpl_vector_get_data(values)[1] = 17;
00436     cpl_vector_get_data(values)[2] = 17;
00437     cpl_vector_get_data(values)[3] = 17;
00438 
00439     solution = uves_polynomial_fit_2d(xy_pos, values, sigmas,
00440                                       deg1, deg2,
00441                                       NULL, NULL, NULL); /* mse, red_chisq, variance */
00442 
00443     irplib_test(solution != NULL);
00444     irplib_test_abs(uves_polynomial_evaluate_2d(solution, 1, 1), 17, 0.001);
00445 
00446 
00447     /* Degenerate input */
00448     deg1 = 1;
00449     deg2 = 1;
00450     cpl_bivector_get_x_data(xy_pos)[0] = 1;
00451     cpl_bivector_get_x_data(xy_pos)[1] = 1;
00452     cpl_bivector_get_x_data(xy_pos)[2] = 1;
00453     cpl_bivector_get_x_data(xy_pos)[3] = 1;
00454 
00455     cpl_bivector_get_y_data(xy_pos)[0] = 1;
00456     cpl_bivector_get_y_data(xy_pos)[1] = 1;
00457     cpl_bivector_get_y_data(xy_pos)[2] = 1;
00458     cpl_bivector_get_y_data(xy_pos)[3] = 1;
00459 
00460 
00461     uves_polynomial_delete(&solution);
00462     solution = uves_polynomial_fit_2d(xy_pos, values, sigmas,
00463                                       deg1, deg2,
00464                                       NULL, NULL, NULL); /* mse, red_chisq, variance */
00465 
00466     irplib_test(cpl_error_get_code() == CPL_ERROR_SINGULAR_MATRIX);
00467     uves_error_reset();
00468     irplib_test(solution == NULL);
00469     
00470 
00471 
00472     uves_polynomial_delete(&solution);
00473     uves_free_bivector(&xy_pos);
00474     uves_free_vector(&values);
00475 
00476     return;
00477 }
00478 
00479 
00480 
00481 static int table_erase_selected(void)
00482 {
00483 
00484   int         nrows = 10;
00485   int         i, j, k, null, error;
00486   int         pp;
00487   int         itest;
00488   double      ftest;
00489   const char *stest;
00490   void       *ptest;
00491   char        message[80];
00492 
00493   int        *iArray;
00494   float      *fArray;
00495   double     *dArray;
00496   double     *ddArray;
00497   char      **sArray;
00498 
00499   int        icheck[25];
00500   float      fcheck[25];
00501   double     dcheck[25];
00502   const char      *scheck[25];
00503 
00504   const char      *unit;
00505   const char      *names[2];
00506   int        reverse[2];
00507 
00508   cpl_table  *table;
00509   cpl_table  *copia;
00510   cpl_array  *array;
00511 
00512   uves_propertylist  *reflist;
00513 
00514 /*
00515   uves_propertylist  *list1;
00516   uves_propertylist  *list2;
00517 */
00518 
00519   iArray = cpl_malloc(nrows * sizeof(int));
00520   fArray = cpl_malloc(nrows * sizeof(float));
00521   dArray = cpl_malloc(nrows * sizeof(double));
00522   ddArray = cpl_malloc(nrows * sizeof(double));
00523   sArray = cpl_malloc(nrows * sizeof(char *));
00524 
00525   iArray[0] = 5;
00526   iArray[1] = 0;
00527   iArray[2] = 2;
00528   iArray[3] = 8;
00529   iArray[4] = 9;
00530   iArray[5] = 3;
00531   iArray[6] = 7;
00532   iArray[7] = 1;
00533   iArray[8] = 4;
00534   iArray[9] = 6;
00535 
00536   fArray[0] = 5.1;
00537   fArray[1] = 0.1;
00538   fArray[2] = 2.1;
00539   fArray[3] = 8.1;
00540   fArray[4] = 9.1;
00541   fArray[5] = 3.1;
00542   fArray[6] = 7.1;
00543   fArray[7] = 1.1;
00544   fArray[8] = 4.1;
00545   fArray[9] = 6.1;
00546 
00547   ddArray[0] = dArray[0] = 5.11;
00548   ddArray[1] = dArray[1] = 0.11;
00549   ddArray[2] = dArray[2] = 2.11;
00550   ddArray[3] = dArray[3] = 8.11;
00551   ddArray[4] = dArray[4] = 9.11;
00552   ddArray[5] = dArray[5] = 3.11;
00553   ddArray[6] = dArray[6] = 7.11;
00554   ddArray[7] = dArray[7] = 1.11;
00555   ddArray[8] = dArray[8] = 4.11;
00556   ddArray[9] = dArray[9] = 6.11;
00557 
00558   sArray[0] = cpl_strdup("caaa");
00559   sArray[1] = cpl_strdup("abcd");
00560   sArray[2] = cpl_strdup("aaaa");
00561   sArray[3] = cpl_strdup("daaa");
00562   sArray[4] = cpl_strdup("acde");
00563   sArray[5] = cpl_strdup("baaa");
00564   sArray[6] = cpl_strdup("aaaa");
00565   sArray[7] = cpl_strdup("acde");
00566   sArray[8] = cpl_strdup(" sss");
00567   sArray[9] = cpl_strdup("daaa");
00568 
00569 
00570   /*
00571    *  Testing begins here
00572    */
00573 
00574   /*
00575    *  Testing tables with zero rows.
00576    */
00577 
00578   test_data(table, cpl_table_new(0), "Creating a table without rows... ");
00579 
00580   test(cpl_table_new_column(table, "Int", CPL_TYPE_INT), 
00581                             "Creating empty Integer column... ");
00582   test(cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT), 
00583                             "Creating empty Float column... ");
00584   test(cpl_table_new_column(table, "Double", CPL_TYPE_DOUBLE), 
00585                             "Creating empty Double column... ");
00586   test(cpl_table_new_column(table, "String", CPL_TYPE_STRING), 
00587                             "Creating empty String column... ");
00588   test(cpl_table_new_column_array(table, "AInt", 
00589                                   CPL_TYPE_INT | CPL_TYPE_POINTER, 0),
00590                                   "Creating empty IntegerArray column... ");
00591   test(cpl_table_new_column_array(table, "AFloat", 
00592                                   CPL_TYPE_FLOAT | CPL_TYPE_POINTER, 0),
00593                                   "Creating empty FloatArray column... ");
00594   test(cpl_table_new_column_array(table, "ADouble", 
00595                                   CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 0),
00596                                   "Creating empty DoubleArray column... ");
00597 
00598   test_ivalue(0, cpl_table_get_nrow(table), "Check zero table length... ");
00599   test_ivalue(7, cpl_table_get_ncol(table), "Check zero table width... ");
00600 
00601   test_ivalue(0, cpl_table_get_column_depth(table, "Double"), 
00602               "Check \"Double\" depth... ");
00603 
00604   test_ivalue(0, cpl_table_get_column_depth(table, "AInt"), 
00605               "Check \"AInt\" depth... ");
00606 
00607   test(cpl_table_set_size(table, 1), "Expanding table to one row... ");
00608 
00609   test_ivalue(1, cpl_table_get_nrow(table), "Check table with one row... ");
00610 
00611   test(cpl_table_set_size(table, 0), "Deleting all rows from table... ");
00612 
00613   test_ivalue(0, cpl_table_get_nrow(table), 
00614               "Check again zero table length... ");
00615 
00616   test(cpl_table_erase_column(table, "Double"),
00617                               "Delete zero-column \"Double\"... ");
00618 
00619   test_ivalue(6, cpl_table_get_ncol(table), "Check zero-column removal... ");
00620 
00621   test(cpl_table_erase_column(table, "AInt"),
00622                               "Delete zero-column \"AInt\"... ");
00623 
00624   test_ivalue(5, cpl_table_get_ncol(table), 
00625               "Check zero-column array removal... ");
00626 
00627   test_pvalue(NULL, cpl_table_get_data_float(table, "Float"),
00628                             "Check NULL pointer to column Float... ");
00629 
00630   test_failure(CPL_ERROR_NULL_INPUT, 
00631                uves_table_erase_selected_dfs02356(NULL),
00632                "Erase selected on NULL table... ");
00633 
00634   test(uves_table_erase_selected_dfs02356(table),
00635        "Erase selected on empty table... ");
00636 
00637   test_failure(CPL_ERROR_NULL_INPUT, 
00638                cpl_table_set_column_unit(NULL, "Float", "arcsec"),
00639                "Try to assign unit to NULL table... ");
00640 
00641   test_failure(CPL_ERROR_NULL_INPUT, 
00642                cpl_table_set_column_unit(table, NULL, "arcsec"),
00643                "Try to assign unit to NULL column... ");
00644 
00645   test_failure(CPL_ERROR_DATA_NOT_FOUND, 
00646                cpl_table_set_column_unit(table, "Double", "arcsec"),
00647                "Try to assign unit to non existing column... ");
00648 
00649   test(cpl_table_set_column_unit(table, "Float", "arcsec"),
00650                "Assign unit 'arcsec' to column Float... ");
00651 
00652   if (strcmp(unit = (char *)cpl_table_get_column_unit(table, "Float"), 
00653       "arcsec")) {
00654     printf("Check column unit... ");
00655     printf("Expected \"arcsec\", obtained \"%s\"\n", unit);
00656     
00657     return 1;
00658   }
00659 
00660   test(cpl_table_set_column_unit(table, "Float", NULL),
00661                "Assign unit NULL to column Float... ");
00662 
00663   test_pvalue(NULL, (char *)cpl_table_get_column_unit(table, "Float"),
00664               "Get unit NULL from column Float... ");
00665 
00666   test(cpl_table_set_size(table, 1), "Expanding again table to one row... ");
00667 
00668   test(cpl_table_erase_invalid_rows(table), "Pruning table to zero... ");
00669 
00670   test_ivalue(1, cpl_table_get_nrow(table),
00671                        "Checking zero-table length after pruning... ");
00672 
00673   test_ivalue(0, cpl_table_get_ncol(table),
00674                        "Checking zero-table width after pruning... ");
00675 
00676   cpl_table_delete(table);
00677 
00678 /* %%% */
00679 
00680   /*
00681    *  Testing tables with more rows
00682    */
00683 
00684   test_data(table, cpl_table_new(nrows), "Creating the test table... ");
00685 
00686   test(cpl_table_wrap_int(table, iArray, "Integer"), 
00687                                          "Wrapping the Integer column... ");
00688 
00689 //  test_pvalue(iArray, cpl_table_unwrap(table, "Integer"),
00690 //                                         "Unwrap the Integer column data... ");
00691   cpl_table_unwrap(table, "Integer");
00692 
00693   test(cpl_table_wrap_int(table, iArray, "Integer"), 
00694                                          "Creating the Integer column... ");
00695 
00696   test(cpl_table_wrap_double(table, dArray, "Double"), 
00697                                          "Creating the Double column... ");
00698 
00699   test(cpl_table_wrap_double(table, ddArray, "DoubleDouble"), 
00700                                   "Creating the DoubleDouble column... ");
00701 
00702   test(cpl_table_wrap_string(table, sArray, "String"),
00703                                          "Creating the String column... ");
00704 
00705   test(cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT),
00706                                          "Creating the Float column... ");
00707 
00708   for (i = 0; i < nrows; i++) {
00709     sprintf(message, "Writing to row %d of the Float column... ", i);
00710     test(cpl_table_set_float(table, "Float", i, fArray[i]), message);
00711   }
00712 
00713   test(cpl_table_new_column_array(table, "AInt", 
00714                                   CPL_TYPE_INT | CPL_TYPE_POINTER, 2),
00715                                   "Creating the ArrayInt column... ");
00716 
00717   test(cpl_table_new_column_array(table, "AFloat", CPL_TYPE_FLOAT, 2),
00718                                   "Creating the ArrayFloat column... ");
00719 
00720   test(cpl_table_new_column_array(table, "ADouble", 
00721                                   CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 2),
00722                                   "Creating the ArrayDouble column... ");
00723 
00724   test_ivalue(2, cpl_table_get_column_depth(table, "AInt"), 
00725               "Check \"AInt\" depth (2)... ");
00726 
00727   k = 0;
00728   array = cpl_array_new(2, CPL_TYPE_INT);
00729   for (i = 0; i < nrows; i++) {
00730     for (j = 0; j < 2; j++) {
00731       sprintf(message, 
00732               "Writing element %d of array %d of the AInt column... ", j, i);
00733       k++;
00734       test(cpl_array_set_int(array, j, k), message);
00735     }
00736     sprintf(message, "Setting array at position %d of the AInt column... ", i);
00737     test(cpl_table_set_array(table, "AInt", i, array), message);
00738   }
00739   cpl_array_delete(array);
00740 
00741   k = 0;
00742   for (i = 0; i < nrows; i++) {
00743     sprintf(message, "Getting array %d of the AInt column... ", i);
00744     test_data(array, (cpl_array *)cpl_table_get_array(table, "AInt", i), 
00745               message);
00746     for (j = 0; j < 2; j++) {
00747       sprintf(message,
00748               "Reading element %d of array %d of the AInt column... ", j, i);
00749       k++;
00750       test_ivalue(k, cpl_array_get_int(array, j, NULL), message);
00751     }
00752   }
00753 
00754   k = 0;
00755   array = cpl_array_new(2, CPL_TYPE_FLOAT);
00756   for (i = 0; i < nrows; i++) {
00757     for (j = 0; j < 2; j++) {
00758       sprintf(message, 
00759               "Writing element %d of array %d of the AFloat column... ", j, i);
00760       k++;
00761       test(cpl_array_set_float(array, j, k), message);
00762     }
00763     sprintf(message, 
00764             "Setting array at position %d of the AFloat column... ", i);
00765     test(cpl_table_set_array(table, "AFloat", i, array), message);
00766   }
00767   cpl_array_delete(array);
00768   
00769   k = 0;
00770   for (i = 0; i < nrows; i++) {
00771     sprintf(message, "Getting array %d of the AFloat column... ", i);
00772     test_data(array, (cpl_array *)cpl_table_get_array(table, "AFloat", i),  
00773               message);
00774     for (j = 0; j < 2; j++) {
00775       sprintf(message,
00776               "Reading element %d of array %d of the AFloat column... ", j, i);
00777       k++;
00778       test_fvalue((float)k, 0.0001, 
00779             cpl_array_get_float(array, j, NULL), message);
00780     }
00781   }
00782 
00783   k = 0;
00784   array = cpl_array_new(2, CPL_TYPE_DOUBLE);
00785   for (i = 0; i < nrows; i++) {
00786     for (j = 0; j < 2; j++) {
00787       sprintf(message, 
00788               "Writing element %d of array %d of the ADouble column... ", j, i);
00789       k++;
00790       test(cpl_array_set_double(array, j, k), message);
00791     }
00792     sprintf(message, 
00793             "Setting array at position %d of the ADouble column... ", i);
00794     test(cpl_table_set_array(table, "ADouble", i, array), message);
00795   }
00796   cpl_array_delete(array);
00797   
00798   k = 0;
00799   for (i = 0; i < nrows; i++) {
00800     sprintf(message, "Getting array %d of the ADouble column... ", i);
00801     test_data(array, (cpl_array *)cpl_table_get_array(table, "ADouble", i),
00802               message);
00803     for (j = 0; j < 2; j++) {
00804       sprintf(message,
00805               "Reading element %d of array %d of the ADouble column... ", j, i);
00806       k++;
00807       test_fvalue((float)k, 0.0001, 
00808             cpl_array_get_double(array, j, NULL), message);
00809     }
00810   }
00811 
00812   test_ivalue(2, cpl_table_get_column_depth(table, "AInt"), 
00813               "Check \"AInt\" depth (3)... ");
00814 
00815   test_data(array, (cpl_array *)cpl_table_get_array(table, "AInt", 0), 
00816             "Get AInt array");
00817   test_ivalue(CPL_TYPE_INT, cpl_array_get_type(array),
00818               "Array AInt must be int... ");
00819 
00820 /**** %%%
00821   list1 = uves_propertylist_new();
00822   uves_propertylist_append_bool(list1, "hierarch eso ins bool", 0);
00823   uves_propertylist_append_bool(list1, "hierarch eso ins bool", 0);
00824   uves_propertylist_set_comment(list1, "hierarch eso ins bool", "This is a comment");
00825   uves_propertylist_append_int(list1, "NAXIS", 111);
00826   uves_propertylist_set_comment(list1, "NAXIS", "This is a comment");
00827   uves_propertylist_append_long(list1, "long", 111111111);
00828   uves_propertylist_set_comment(list1, "long", "This is a comment");
00829   uves_propertylist_append_float(list1, "float", 4.4);
00830   uves_propertylist_set_comment(list1, "float", "This is a comment");
00831   uves_propertylist_append_double(list1, "double", 8.8);
00832   uves_propertylist_set_comment(list1, "double", "This is a comment");
00833   uves_propertylist_append_char(list1, "char", 'D');
00834   uves_propertylist_set_comment(list1, "char", "This is a comment");
00835   list2 = uves_propertylist_new();
00836   uves_propertylist_append_string(list2, "hierarch eso det string", "This is a test");
00837   uves_propertylist_set_comment(list2, "hierarch eso det string", "This is a comment");
00838   uves_propertylist_append_int(list2, "TFIELDS", 3000);
00839   uves_propertylist_set_comment(list2, "TFIELDS", "This is a comment");
00840   uves_propertylist_append_string(list2, "TUNIT2", "This is a test");
00841   uves_propertylist_set_comment(list2, "TUNIT2", "This is a comment");
00842   uves_propertylist_append_string(list2, "TFORM1", "This is a test");
00843   uves_propertylist_set_comment(list2, "TFORM1", "This is a comment");
00844   uves_propertylist_append_string(list2, "TTYPE3", "This is a test");
00845   uves_propertylist_set_comment(list2, "TTYPE3", "This is a comment");
00846   uves_propertylist_append_bool(list2, "hierarch eso ins bool", 0);
00847   uves_propertylist_set_comment(list2, "hierarch eso ins bool", "This is a comment");
00848   uves_propertylist_append_int(list2, "hierarch eso det int", 111);
00849   uves_propertylist_set_comment(list2, "hierarch eso det int", "This is a comment");
00850   uves_propertylist_append_long(list2, "long", 111111111);
00851   uves_propertylist_set_comment(list2, "long", "This is a comment");
00852   uves_propertylist_append_float(list2, "float", 4.4);
00853   uves_propertylist_set_comment(list2, "float", "This is a comment");
00854   uves_propertylist_append_double(list2, "double", 8.8);
00855   uves_propertylist_set_comment(list2, "double", "This is a comment");
00856   uves_propertylist_append_char(list2, "char", 'D');
00857   uves_propertylist_set_comment(list2, "char", "This is a comment");
00858 ****/
00859 
00866 /****
00867   uves_propertylist_delete(list1);
00868   uves_propertylist_delete(list2);
00869 ****/
00870 
00871   test_ivalue(10, cpl_table_get_nrow(table), "Check table length (1)... ");
00872   test_ivalue(8, cpl_table_get_ncol(table), "Check table width... ");
00873 
00874   test_failure(CPL_ERROR_DATA_NOT_FOUND, 
00875                cpl_table_erase_column(table, "Diable"), 
00876                "Trying to delete a not existing column... ");
00877 
00878   test(cpl_table_erase_column(table, "DoubleDouble"), 
00879                                 "Delete column \"DoubleDouble\"... ");
00880 
00881   test_ivalue(7, cpl_table_get_ncol(table), "Check again table width... ");
00882 
00883   test_ivalue(CPL_TYPE_INT, cpl_table_get_column_type(table, "Integer"),
00884                                 "Column Integer must be int... ");
00885   test_ivalue(CPL_TYPE_DOUBLE, cpl_table_get_column_type(table, "Double"),
00886                                 "Column Double must be double... ");
00887   test_ivalue(CPL_TYPE_STRING, cpl_table_get_column_type(table, "String"),
00888                                 "Column String must be char*... ");
00889   test_ivalue(CPL_TYPE_FLOAT, cpl_table_get_column_type(table, "Float"),
00890                                 "Column Float must be float... ");
00891   test_ivalue((CPL_TYPE_INT | CPL_TYPE_POINTER), 
00892               cpl_table_get_column_type(table, "AInt"),
00893               "Column AInt must be arrays of int... ");
00894   test_ivalue((CPL_TYPE_DOUBLE | CPL_TYPE_POINTER), 
00895               cpl_table_get_column_type(table, "ADouble"),
00896               "Column Double must be arrays of double... ");
00897   test_ivalue((CPL_TYPE_FLOAT | CPL_TYPE_POINTER), 
00898               cpl_table_get_column_type(table, "AFloat"),
00899               "Column Float must be arrays of float... ");
00900 
00901 //  test_pvalue(iArray, cpl_table_get_data_int(table, "Integer"),
00902 //                                "Check pointer to column Integer data... ");
00903 //  test_pvalue(dArray, cpl_table_get_data_double(table, "Double"),
00904 //                                "Check pointer to column Double data... ");
00905 //  test_pvalue(sArray, cpl_table_get_data_string(table, "String"),
00906 //                                "Check pointer to column String data... ");
00907 
00908 
00909   copia = cpl_table_new(5);
00910 
00911   test(cpl_table_copy_structure(copia, table),
00912        "Creating a new cpl_table modeled on an existing cpl_table... ");
00913 
00914   test_ivalue(5, cpl_table_get_nrow(copia), "Check table length (2)... ");
00915   test_ivalue(7, cpl_table_get_ncol(copia), "Check table width... ");
00916 
00917   test(cpl_table_compare_structure(table, copia), 
00918                                  "Tables must have the same structure... ");
00919   cpl_table_erase_column(copia, "Double");
00920   test_ivalue(1, cpl_table_compare_structure(table, copia), 
00921     "Deleting column Double - now tables must have different structure... ");
00922   test(cpl_table_new_column(copia, "Double", CPL_TYPE_DOUBLE),
00923                                  "Creating again the Double column... ");
00924   test(cpl_table_compare_structure(table, copia), 
00925                          "Tables must have the same structure again... ");
00926 
00927   test(cpl_table_fill_column_window_int(copia, "Integer", 0, 5, -1),
00928                                  "Fill column Integer of new table... ");
00929   test(cpl_table_fill_column_window_double(copia, "Double", 0, 5, -1.11),
00930                                  "Fill column Double of new table... ");
00931   test(cpl_table_fill_column_window_float(copia, "Float", 0, 5, -1.1),
00932                                  "Fill column Float of new table... ");
00933   test(cpl_table_fill_column_window_string(copia, "String", 0, 5, "extra"),
00934                                  "Fill column String of new table... ");
00935 
00936   array = cpl_array_new(2, CPL_TYPE_INT);
00937   for (j = 0; j < 2; j++)
00938     cpl_array_set_int(array, j, j);
00939   test(cpl_table_fill_column_window_array(copia, "AInt", 0, 5, array),
00940                                  "Fill column AInt of new table... ");
00941   cpl_array_delete(array);
00942 
00943   array = cpl_array_new(2, CPL_TYPE_FLOAT);
00944   for (j = 0; j < 2; j++) 
00945     cpl_array_set_float(array, j, j);
00946   test(cpl_table_fill_column_window_array(copia, "AFloat", 0, 5, array),
00947                                  "Fill column AFloat of new table... ");
00948   cpl_array_delete(array);
00949 
00950   array = cpl_array_new(2, CPL_TYPE_DOUBLE);
00951   for (j = 0; j < 2; j++) 
00952     cpl_array_set_double(array, j, j);
00953   test(cpl_table_fill_column_window_array(copia, "ADouble", 0, 5, array),
00954                                  "Fill column ADouble of new table... ");
00955   cpl_array_delete(array);
00956 
00957   test(cpl_table_insert(table, copia, 15), 
00958                                  "Appending new table to old table... ");
00959   test(cpl_table_insert(table, copia, 5), 
00960                                  "Inserting new table in old table... ");
00961   test(cpl_table_insert(table, copia, 0), 
00962                                  "Prepending new table to old table... ");
00963 
00964   cpl_table_delete(copia);
00965 
00967   cpl_table_fill_invalid_int(table, "Integer", 320);
00968   cpl_table_fill_invalid_int(table, "AInt", 320);
00969   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
00970   cpl_table_delete(table);
00971   table = cpl_table_load("test_table.tfits", 1, 1);
00972 
00973   
00974   test_ivalue(25, cpl_table_get_nrow(table), "Check table length (3)... ");
00975 
00976   icheck[0] = -1;
00977   icheck[1] = -1;
00978   icheck[2] = -1;
00979   icheck[3] = -1;
00980   icheck[4] = -1;
00981   icheck[5] = 5;
00982   icheck[6] = 0;
00983   icheck[7] = 2;
00984   icheck[8] = 8;
00985   icheck[9] = 9;
00986   icheck[10] = -1;
00987   icheck[11] = -1;
00988   icheck[12] = -1;
00989   icheck[13] = -1;
00990   icheck[14] = -1;
00991   icheck[15] = 3;
00992   icheck[16] = 7;
00993   icheck[17] = 1;
00994   icheck[18] = 4;
00995   icheck[19] = 6;
00996   icheck[20] = -1;
00997   icheck[21] = -1;
00998   icheck[22] = -1;
00999   icheck[23] = -1;
01000   icheck[24] = -1;
01001 
01002   error = 0;
01003 
01004   for (i = 0; i < 25; i++) {
01005     if (cpl_table_get_int(table, "Integer", i, NULL) != icheck[i]) {
01006       error = 1;
01007       break;
01008     }
01009   }
01010 
01011   if (error) {
01012     printf("Check Integer column... ");
01013     printf("Failure\n");
01014     
01015     return 1;
01016   }
01017 
01018   dcheck[0] = -1.1100;
01019   dcheck[1] = -1.1100;
01020   dcheck[2] = -1.1100;
01021   dcheck[3] = -1.1100;
01022   dcheck[4] = -1.1100;
01023   dcheck[5] = 5.1100;
01024   dcheck[6] = 0.1100;
01025   dcheck[7] = 2.1100;
01026   dcheck[8] = 8.1100;
01027   dcheck[9] = 9.1100;
01028   dcheck[10] = -1.1100;
01029   dcheck[11] = -1.1100;
01030   dcheck[12] = -1.1100;
01031   dcheck[13] = -1.1100;
01032   dcheck[14] = -1.1100;
01033   dcheck[15] = 3.1100;
01034   dcheck[16] = 7.1100;
01035   dcheck[17] = 1.1100;
01036   dcheck[18] = 4.1100;
01037   dcheck[19] = 6.1100;
01038   dcheck[20] = -1.1100;
01039   dcheck[21] = -1.1100;
01040   dcheck[22] = -1.1100;
01041   dcheck[23] = -1.1100;
01042   dcheck[24] = -1.1100;
01043 
01044   error = 0;
01045 
01046   for (i = 0; i < 25; i++) {
01047     if (fabs(cpl_table_get_double(table, "Double", i, NULL) - dcheck[i]) 
01048                                                                   > 0.00001) {
01049       error = 1;
01050       break;
01051     }
01052   }
01053 
01054   if (error) {
01055     printf("Check Double column... ");
01056     printf("Failure\n");
01057     
01058     return 1;
01059   }
01060 
01061   scheck[0] = "extra";
01062   scheck[1] = "extra";
01063   scheck[2] = "extra";
01064   scheck[3] = "extra";
01065   scheck[4] = "extra";
01066   scheck[5] = "caaa";
01067   scheck[6] = "abcd";
01068   scheck[7] = "aaaa";
01069   scheck[8] = "daaa";
01070   scheck[9] = "acde";
01071   scheck[10] = "extra";
01072   scheck[11] = "extra";
01073   scheck[12] = "extra";
01074   scheck[13] = "extra";
01075   scheck[14] = "extra";
01076   scheck[15] = "baaa";
01077   scheck[16] = "aaaa";
01078   scheck[17] = "acde";
01079   scheck[18] = " sss";
01080   scheck[19] = "daaa";
01081   scheck[20] = "extra";
01082   scheck[21] = "extra";
01083   scheck[22] = "extra";
01084   scheck[23] = "extra";
01085   scheck[24] = "extra";
01086 
01087   error = 0;
01088 
01089   for (i = 0; i < 25; i++) {
01090     if (strcmp(cpl_table_get_string(table, "String", i), scheck[i])) {
01091       error = 1;
01092       break;
01093     }
01094   }
01095 
01096   if (error) {
01097     printf("Check String column... ");
01098     printf("Failure\n");
01099     
01100     return 1;
01101   }
01102 
01103   fcheck[0] = -1.10;
01104   fcheck[1] = -1.10;
01105   fcheck[2] = -1.10;
01106   fcheck[3] = -1.10;
01107   fcheck[4] = -1.10;
01108   fcheck[5] = 5.10;
01109   fcheck[6] = 0.10;
01110   fcheck[7] = 2.10;
01111   fcheck[8] = 8.10;
01112   fcheck[9] = 9.10;
01113   fcheck[10] = -1.10;
01114   fcheck[11] = -1.10;
01115   fcheck[12] = -1.10;
01116   fcheck[13] = -1.10;
01117   fcheck[14] = -1.10;
01118   fcheck[15] = 3.10;
01119   fcheck[16] = 7.10;
01120   fcheck[17] = 1.10;
01121   fcheck[18] = 4.10;
01122   fcheck[19] = 6.10;
01123   fcheck[20] = -1.10;
01124   fcheck[21] = -1.10;
01125   fcheck[22] = -1.10;
01126   fcheck[23] = -1.10;
01127   fcheck[24] = -1.10;
01128 
01129   error = 0;
01130 
01131   for (i = 0; i < 25; i++) {
01132     if (fabs(cpl_table_get_float(table, "Float", i, NULL) - fcheck[i])
01133                                                                   > 0.00001) {
01134       error = 1;
01135       break;
01136     }
01137   }
01138 
01139   if (error) {
01140     printf("Check Float column... ");
01141     printf("Failure\n");
01142     
01143     return 1;
01144   }
01145 
01146   test(cpl_table_set_invalid(table, "Integer", 0), 
01147                              "Set Integer 0 to NULL... ");
01148   test(cpl_table_set_invalid(table, "Integer", 5), 
01149                              "Set Integer 5 to NULL... ");
01150   test(cpl_table_set_invalid(table, "Integer", 24), 
01151                              "Set Integer 24 to NULL... ");
01152 
01153   test(cpl_table_set_invalid(table, "AInt", 0),
01154                              "Set AInt 0 to NULL... ");
01155   test(cpl_table_set_invalid(table, "AFloat", 5),
01156                              "Set AFloat 5 to NULL... ");
01157   test(cpl_table_set_invalid(table, "ADouble", 24),
01158                              "Set ADouble 24 to NULL... ");
01159 
01161   cpl_table_fill_invalid_int(table, "Integer", 320);
01162   cpl_table_fill_invalid_int(table, "AInt", 320);
01163   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01164   cpl_table_delete(table);
01165   table = cpl_table_load("test_table.tfits", 1, 1);
01166 
01167 
01168   test_ivalue(3, cpl_table_count_invalid(table, "Integer"), 
01169               "Count Integer written NULLs... ");
01170   test_ivalue(1, cpl_table_count_invalid(table, "AInt"),
01171               "Count AInt written NULLs... ");
01172   test_ivalue(1, cpl_table_count_invalid(table, "AFloat"),
01173               "Count AFloat written NULLs... ");
01174   test_ivalue(1, cpl_table_count_invalid(table, "ADouble"),
01175               "Count ADouble written NULLs... ");
01176 
01177   error = 0;
01178 
01179   for (i = 0; i < 25; i++) {
01180     cpl_table_get_int(table, "Integer", i, &null);
01181     if (!null) {
01182       if (cpl_table_get_int(table, "Integer", i, &null) != icheck[i]) {
01183         error = 1;
01184         break;
01185       }
01186     }
01187     else if (i != 0 && i != 5 && i != 24) {
01188       error = 1;
01189       break;
01190     }
01191   }
01192 
01193   if (error) {
01194     printf("Check Integer column... ");
01195     printf("Failure\n");
01196     
01197     return 1;
01198   }
01199 
01200   test(cpl_table_set_int(table, "Integer", 0, -1), 
01201                                               "Set Integer 0 to -1... ");
01202   test(cpl_table_set_int(table, "Integer", 5, 5), 
01203                                               "Set Integer 5 to 5... ");
01204   test(cpl_table_set_int(table, "Integer", 24, -1), 
01205                                               "Set Integer 24 to -1... ");
01206 
01207   array = cpl_array_new(2, CPL_TYPE_INT);
01208   for (j = 0; j < 2; j++)
01209     cpl_array_set_int(array, j, j);
01210   test(cpl_table_set_array(table, "AInt", 0, array),
01211                            "Set a valid array to AInt 0... ");
01212   cpl_array_delete(array);
01213   test_ivalue(0, cpl_table_count_invalid(table, "AInt"),
01214               "No invalid elements in AInt... ");
01215 
01216   array = cpl_array_new(2, CPL_TYPE_FLOAT);
01217   for (j = 0; j < 2; j++)
01218     cpl_array_set_float(array, j, j);
01219   test(cpl_table_set_array(table, "AFloat", 5, array),
01220                            "Set a valid array to AFloat 5... ");
01221   cpl_array_delete(array);
01222   test_ivalue(0, cpl_table_count_invalid(table, "AFloat"),
01223               "No invalid elements in AFloat... ");
01224 
01225   array = cpl_array_new(2, CPL_TYPE_DOUBLE);
01226   for (j = 0; j < 2; j++)
01227     cpl_array_set_double(array, j, j);
01228   test(cpl_table_set_array(table, "ADouble", 24, array),
01229                            "Set a valid array to ADouble 24... ");
01230   cpl_array_delete(array);
01231   test_ivalue(0, cpl_table_count_invalid(table, "ADouble"),
01232               "No invalid elements in ADouble... ");
01233 
01235   cpl_table_fill_invalid_int(table, "Integer", 320);
01236   cpl_table_fill_invalid_int(table, "AInt", 320);
01237   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01238   cpl_table_delete(table);
01239   table = cpl_table_load("test_table.tfits", 1, 1);
01240 
01241 
01242   test_ivalue(0, cpl_table_count_invalid(table, "Integer"), 
01243                                               "Count NULLs... ");
01244 
01245   error = 0;
01246 
01247   for (i = 0; i < 25; i++) {
01248     cpl_table_get_int(table, "Integer", i, &null);
01249     if (!null) {
01250       if (cpl_table_get_int(table, "Integer", i, &null) != icheck[i]) {
01251         error = 1;
01252         break;
01253       }
01254     }
01255     else {
01256       error = 1;
01257       break;
01258     }
01259   }
01260 
01261   if (error) {
01262     printf("Check Integer column... ");
01263     printf("Failure\n");
01264     
01265     return 1;
01266   }
01267 
01268   test(cpl_table_set_invalid(table, "Double", 0), "Set Double 0 to NULL... ");
01269   test(cpl_table_set_invalid(table, "Double", 5), "Set Double 5 to NULL... ");
01270   test(cpl_table_set_invalid(table, "Double", 24), "Set Double 24 to NULL... ");
01271 
01273   cpl_table_fill_invalid_int(table, "Integer", 320);
01274   cpl_table_fill_invalid_int(table, "AInt", 320);
01275   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01276   cpl_table_delete(table);
01277   table = cpl_table_load("test_table.tfits", 1, 1);
01278 
01279 
01280   test_ivalue(3, cpl_table_count_invalid(table, "Double"), 
01281                                                   "Count written NULLs... ");
01282 
01283   error = 0;
01284 
01285   for (i = 0; i < 25; i++) {
01286     cpl_table_get_double(table, "Double", i, &null);
01287     if (!null) {
01288       if (cpl_table_get_double(table, "Double", i, &null) != dcheck[i]) {
01289         error = 1;
01290         break;
01291       }
01292     }
01293     else if (i != 0 && i != 5 && i != 24) {
01294       error = 1;
01295       break;
01296     }
01297   }
01298 
01299   if (error) {
01300     printf("Check Double column... ");
01301     printf("Failure\n");
01302     
01303     return 1;
01304   }
01305 
01306   test(cpl_table_set_double(table, "Double", 0, -1.11), 
01307                                               "Set Double 0 to -1.11... ");
01308   test(cpl_table_set_double(table, "Double", 5, 5.11), 
01309                                               "Set Double 5 to 5.11... ");
01310   test(cpl_table_set_double(table, "Double", 24, -1.11), 
01311                                               "Set Double 24 to -1.11... ");
01312 
01314   cpl_table_fill_invalid_int(table, "Integer", 320);
01315   cpl_table_fill_invalid_int(table, "AInt", 320);
01316   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01317   cpl_table_delete(table);
01318   table = cpl_table_load("test_table.tfits", 1, 1);
01319 
01320 
01321   test_ivalue(0, cpl_table_count_invalid(table, "Double"), 
01322                                                   "Count NULLs... ");
01323 
01324   error = 0;
01325 
01326   for (i = 0; i < 25; i++) {
01327     cpl_table_get_double(table, "Double", i, &null);
01328     if (!null) {
01329       if (fabs(cpl_table_get_double(table, "Double", i, &null)-dcheck[i])
01330                                                               > 0.00001) {
01331         error = 1;
01332         break;
01333       }
01334     }
01335     else {
01336       error = 1;
01337       break;
01338     }
01339   }
01340 
01341   if (error) {
01342     printf("Check Double column... ");
01343     printf("Failure\n");
01344     
01345     return 1;
01346   }
01347 
01348 
01349   test(cpl_table_set_invalid(table, "String", 0), "Set String 0 to NULL... ");
01350   test(cpl_table_set_invalid(table, "String", 5), "Set String 5 to NULL... ");
01351   test(cpl_table_set_invalid(table, "String", 24), "Set String 24 to NULL... ");
01352 
01354   cpl_table_fill_invalid_int(table, "Integer", 320);
01355   cpl_table_fill_invalid_int(table, "AInt", 320);
01356   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01357   cpl_table_delete(table);
01358   table = cpl_table_load("test_table.tfits", 1, 1);
01359 
01360 
01361   test_ivalue(3, cpl_table_count_invalid(table, "String"), 
01362                                                   "Count written NULLs... ");
01363 
01364   error = 0;
01365 
01366   for (i = 0; i < 25; i++) {
01367     if (cpl_table_get_string(table, "String", i)) {
01368       if (strcmp(cpl_table_get_string(table, "String", i), scheck[i])) {
01369         error = 1;
01370         break;
01371       }
01372     }
01373     else if (i != 0 && i != 5 && i != 24) {
01374       error = 1;
01375       break;
01376     }
01377   }
01378 
01379   if (error) {
01380     printf("Check String column... ");
01381     printf("Failure\n");
01382     
01383     return 1;
01384   }
01385 
01386   test(cpl_table_set_string(table, "String", 0, "extra"),
01387                                               "Set String 0 to \"extra\"... ");
01388   test(cpl_table_set_string(table, "String", 5, "caaa"), 
01389                                               "Set String 5 to \"caaa\"... ");
01390   test(cpl_table_set_string(table, "String", 24, "extra"), 
01391                                               "Set String 24 to \"extra\"... ");
01392 
01394   cpl_table_fill_invalid_int(table, "Integer", 320);
01395   cpl_table_fill_invalid_int(table, "AInt", 320);
01396   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01397   cpl_table_delete(table);
01398   table = cpl_table_load("test_table.tfits", 1, 1);
01399 
01400 
01401   test_ivalue(0, cpl_table_count_invalid(table, "String"), 
01402                                               "Count NULLs... ");
01403 
01404   error = 0;
01405 
01406   for (i = 0; i < 25; i++) {
01407     if (cpl_table_get_string(table, "String", i)) {
01408       if (strcmp(cpl_table_get_string(table, "String", i), scheck[i])) {
01409         error = 1;
01410         break;
01411       }
01412     }
01413     else {
01414       error = 1;
01415       break;
01416     }
01417   }
01418 
01419   if (error) {
01420     printf("Check String column... ");
01421     printf("Failure\n");
01422     
01423     return 1;
01424   }
01425 
01426 
01427   test(cpl_table_set_invalid(table, "Float", 0), "Set Float 0 to NULL... ");
01428   test(cpl_table_set_invalid(table, "Float", 5), "Set Float 5 to NULL... ");
01429   test(cpl_table_set_invalid(table, "Float", 24), "Set Float 24 to NULL... ");
01430 
01432   cpl_table_fill_invalid_int(table, "Integer", 320);
01433   cpl_table_fill_invalid_int(table, "AInt", 320);
01434   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01435   cpl_table_delete(table);
01436   table = cpl_table_load("test_table.tfits", 1, 1);
01437 
01438 
01439   test_ivalue(3, cpl_table_count_invalid(table, "Float"), 
01440                                                   "Count written NULLs... ");
01441 
01442   error = 0;
01443 
01444   for (i = 0; i < 25; i++) {
01445     cpl_table_get_float(table, "Float", i, &null);
01446     if (!null) {
01447       if (cpl_table_get_float(table, "Float", i, &null) != fcheck[i]) {
01448         error = 1;
01449         break;
01450       }
01451     }
01452     else if (i != 0 && i != 5 && i != 24) {
01453       error = 1;
01454       break;
01455     }
01456   }
01457 
01458   if (error) {
01459     printf("Check Float column... ");
01460     printf("Failure\n");
01461     
01462     return 1;
01463   }
01464 
01465   test(cpl_table_set_float(table, "Float", 0, -1.1), 
01466                                               "Set Float 0 to -1.1... ");
01467   test(cpl_table_set_float(table, "Float", 5, 5.1), 
01468                                               "Set Float 5 to 5.1... ");
01469   test(cpl_table_set_float(table, "Float", 24, -1.1), 
01470                                               "Set Float 24 to -1.1... ");
01471 
01473   cpl_table_fill_invalid_int(table, "Integer", 320);
01474   cpl_table_fill_invalid_int(table, "AInt", 320);
01475   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01476   cpl_table_delete(table);
01477   table = cpl_table_load("test_table.tfits", 1, 1);
01478 
01479 
01480   test_ivalue(0, cpl_table_count_invalid(table, "Float"), 
01481                                               "Count NULLs... ");
01482 
01483   error = 0;
01484 
01485   for (i = 0; i < 25; i++) {
01486     cpl_table_get_float(table, "Float", i, &null);
01487     if (!null) {
01488       if (fabs(cpl_table_get_float(table, "Float", i, &null)-fcheck[i])
01489                                                               > 0.00001) {
01490         error = 1;
01491         break;
01492       }
01493     }
01494     else {
01495       error = 1;
01496       break;
01497     }
01498   }
01499 
01500   if (error) {
01501     printf("Check Float column... ");
01502     printf("Failure\n");
01503     
01504     return 1;
01505   }
01506 
01507  /* %%% */
01508 
01509   test(cpl_table_set_column_invalid(table, "Integer", 0, 3), 
01510                                   "Set Integer 0-2 to NULL... ");
01511   test(cpl_table_set_column_invalid(table, "Integer", 5, 3), 
01512                                   "Set Integer 5-7 to NULL... ");
01513   test(cpl_table_set_column_invalid(table, "Integer", 20, 20), 
01514                                   "Set Integer 20 till end to NULL... ");
01515 
01516   test(cpl_table_set_column_invalid(table, "AInt", 0, 3),
01517                                   "Set AInt 0-2 to NULL... ");
01518   test(cpl_table_set_column_invalid(table, "AInt", 5, 3),
01519                                   "Set AInt 5-7 to NULL... ");
01520   test(cpl_table_set_column_invalid(table, "AInt", 20, 20),
01521                                   "Set AInt 20 till end to NULL... ");
01522 
01524   cpl_table_fill_invalid_int(table, "Integer", 320);
01525   cpl_table_fill_invalid_int(table, "AInt", 320);
01526   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01527   cpl_table_delete(table);
01528   table = cpl_table_load("test_table.tfits", 1, 1);
01529 
01530 
01531   test_ivalue(11, cpl_table_count_invalid(table, "Integer"), 
01532               "Count Integer NULLs... ");
01533 
01534   test_ivalue(11, cpl_table_count_invalid(table, "AInt"), 
01535               "Count AInt NULLs... ");
01536 
01537   error = 0;
01538 
01539   for (i = 0; i < 25; i++) {
01540     cpl_table_get_int(table, "Integer", i, &null);
01541     if (!null) {
01542       if (cpl_table_get_int(table, "Integer", i, &null) != icheck[i]) {
01543         error = 1;
01544         break;
01545       }
01546     }
01547     else if ((i > 2 && i < 5) || (i > 7 && i < 20)) {
01548       error = 1;
01549       break;
01550     }
01551   }
01552 
01553   if (error) {
01554     printf("Check Integer column... ");
01555     printf("Failure\n");
01556     
01557     return 1;
01558   }
01559 
01560   test(cpl_table_set_column_invalid(table, "Double", 0, 3),
01561                                   "Set Double 0-2 to NULL... ");
01562   test(cpl_table_set_column_invalid(table, "Double", 5, 3),
01563                                   "Set Double 5-7 to NULL... ");
01564   test(cpl_table_set_column_invalid(table, "Double", 20, 20),
01565                                   "Set Double 20 till end to NULL... ");
01566 
01568   cpl_table_fill_invalid_int(table, "Integer", 320);
01569   cpl_table_fill_invalid_int(table, "AInt", 320);
01570   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01571   cpl_table_delete(table);
01572   table = cpl_table_load("test_table.tfits", 1, 1);
01573 
01574 
01575   test_ivalue(11, cpl_table_count_invalid(table, "Double"),
01576                                                "Count written NULLs... ");
01577 
01578   error = 0;
01579 
01580   for (i = 0; i < 25; i++) {
01581     cpl_table_get_double(table, "Double", i, &null);
01582     if (!null) {
01583       if (fabs(cpl_table_get_double(table, "Double", i, &null)-dcheck[i])
01584                                                        > 0.000001) {
01585         error = 1;
01586         break;
01587       }
01588     }
01589     else if ((i > 2 && i < 5) || (i > 7 && i < 20)) {
01590       error = 1;
01591       break;
01592     }
01593   }
01594 
01595   if (error) {
01596     printf("Check Double column... ");
01597     printf("Failure\n");
01598     
01599     return 1;
01600   }
01601 
01602 
01603   test(cpl_table_set_column_invalid(table, "Float", 0, 3),
01604                                   "Set Float 0-2 to NULL... ");
01605   test(cpl_table_set_column_invalid(table, "Float", 5, 3),
01606                                   "Set Float 5-7 to NULL... ");
01607   test(cpl_table_set_column_invalid(table, "Float", 20, 20),
01608                                   "Set Float 20 till end to NULL... ");
01609 
01611   cpl_table_fill_invalid_int(table, "Integer", 320);
01612   cpl_table_fill_invalid_int(table, "AInt", 320);
01613   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01614   cpl_table_delete(table);
01615   table = cpl_table_load("test_table.tfits", 1, 1);
01616 
01617 
01618   test_ivalue(11, cpl_table_count_invalid(table, "Float"),
01619                                                "Count written NULLs... ");
01620 
01621   error = 0;
01622 
01623   for (i = 0; i < 25; i++) {
01624     cpl_table_get_float(table, "Float", i, &null);
01625     if (!null) {
01626       if (fabs(cpl_table_get_float(table, "Float", i, &null)-fcheck[i]) 
01627                                                            > 0.000001) {
01628         error = 1;
01629         break;
01630       }
01631     }
01632     else if ((i > 2 && i < 5) || (i > 7 && i < 20)) {
01633       error = 1;
01634       break;
01635     }
01636   }
01637 
01638   if (error) {
01639     printf("Check Float column... ");
01640     printf("Failure\n");
01641     
01642     return 1;
01643   }
01644 
01645 
01646   test(cpl_table_set_column_invalid(table, "String", 0, 3),
01647                                   "Set String 0-2 to NULL... ");
01648   test(cpl_table_set_column_invalid(table, "String", 5, 3),
01649                                   "Set String 5-7 to NULL... ");
01650   test(cpl_table_set_column_invalid(table, "String", 20, 20),
01651                                   "Set String 20 till end to NULL... ");
01652 
01654   cpl_table_fill_invalid_int(table, "Integer", 320);
01655   cpl_table_fill_invalid_int(table, "AInt", 320);
01656   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01657   cpl_table_delete(table);
01658   table = cpl_table_load("test_table.tfits", 1, 1);
01659 
01660 
01661   test_ivalue(11, cpl_table_count_invalid(table, "String"),
01662                                                "Count written NULLs... ");
01663 
01664   error = 0;
01665 
01666   for (i = 0; i < 25; i++) {
01667     if (cpl_table_get_string(table, "String", i)) {
01668       if (strcmp(cpl_table_get_string(table, "String", i), scheck[i])) {
01669         error = 1;
01670         break;
01671       }
01672     }
01673     else if ((i > 2 && i < 5) || (i > 7 && i < 20)) {
01674       error = 1;
01675       break;
01676     }
01677   }
01678 
01679   if (error) {
01680     printf("Check String column... ");
01681     printf("Failure\n");
01682     
01683     return 1;
01684   }
01685 
01686   test(cpl_table_erase_window(table, 21, 4), "Delete last 4 table rows... ");
01687 
01688   test(cpl_table_erase_window(table, 7, 4), 
01689                                "Delete table rows from 7 to 10... ");
01690 
01691   test(cpl_table_erase_window(table, 3, 3), 
01692                                "Delete table rows from 3 to 5... ");
01693 
01694   test(cpl_table_erase_window(table, 0, 2), "Delete first two table rows... ");
01695 
01696   test_ivalue(12, cpl_table_get_nrow(table), "Check table length (4)... ");
01697 
01698   test_ivalue(3, cpl_table_count_invalid(table, "Integer"), 
01699                                        "Count Integer NULLs... ");
01700 
01701   test_ivalue(3, cpl_table_count_invalid(table, "Double"), 
01702                                        "Count Double NULLs... ");
01703 
01704   test_ivalue(3, cpl_table_count_invalid(table, "String"), 
01705                                        "Count String NULLs... ");
01706 
01707   test_ivalue(3, cpl_table_count_invalid(table, "Float"), 
01708                                        "Count Float NULLs... ");
01709 
01710   test_ivalue(3, cpl_table_count_invalid(table, "AInt"),
01711                                        "Count AInt NULLs... ");
01712 
01713   test_ivalue(0, cpl_table_count_invalid(table, "ADouble"),
01714                                        "Count ADouble NULLs... ");
01715 
01716   test_ivalue(0, cpl_table_count_invalid(table, "AFloat"),
01717                                        "Count AFloat NULLs... ");
01718 
01719   test(cpl_table_insert_window(table, 20, 5),
01720                                 "Append 5 NULLs at table end... ");
01721 
01722   test(cpl_table_insert_window(table, 6, 4),
01723                                 "Insert segment of 4 NULLs at row 6... ");
01724 
01725   test(cpl_table_insert_window(table, 1, 2),
01726                                 "Insert segment of 2 NULLs at row 1... ");
01727 
01728   test_ivalue(23, cpl_table_get_nrow(table), "Check table length (5)... ");
01729 
01730   test_ivalue(14, cpl_table_count_invalid(table, "Integer"), 
01731                                        "Count Integer NULLs... ");
01732 
01733   test_ivalue(14, cpl_table_count_invalid(table, "Double"), 
01734                                        "Count Double NULLs... ");
01735 
01736   test_ivalue(14, cpl_table_count_invalid(table, "String"), 
01737                                        "Count String NULLs... ");
01738 
01739   test_ivalue(14, cpl_table_count_invalid(table, "Float"), 
01740                                        "Count Float NULLs... ");
01741 
01742   test(cpl_table_fill_column_window_int(table, "Integer", 0, 2, 999),
01743        "Write 999 in \"Integer\" column from 0 to 1... ");
01744 
01745   test(cpl_table_fill_column_window_int(table, "Integer", 3, 3, 999),
01746        "Write 999 in \"Integer\" column from 3 to 5... ");
01747 
01748   test(cpl_table_fill_column_window_int(table, "Integer", 7, 4, 999),
01749        "Write 999 in \"Integer\" column from 7 to 10... ");
01750 
01751   test(cpl_table_fill_column_window_int(table, "Integer", 20, 7, 999),
01752        "Write 999 in \"Integer\" column from 20 to end... ");
01753 
01754   test(cpl_table_fill_column_window_float(table, "Float", 0, 2, 999.99),
01755        "Write 999.99 in \"Float\" column from 0 to 1... ");
01756 
01757   test(cpl_table_fill_column_window_float(table, "Float", 3, 3, 999.99),
01758        "Write 999.99 in \"Float\" column from 3 to 5... ");
01759 
01760   test(cpl_table_fill_column_window_float(table, "Float", 7, 4, 999.99),
01761        "Write 999.99 in \"Float\" column from 7 to 10... ");
01762 
01763   test(cpl_table_fill_column_window_float(table, "Float", 20, 7, 999.99),
01764        "Write 999.99 in \"Float\" column from 20 to end... ");
01765 
01766   test(cpl_table_fill_column_window_double(table, "Double", 0, 2, 999.88),
01767        "Write 999.88 in \"Double\" column from 0 to 1... ");
01768 
01769   test(cpl_table_fill_column_window_double(table, "Double", 3, 3, 999.88),
01770        "Write 999.88 in \"Double\" column from 3 to 5... ");
01771 
01772   test(cpl_table_fill_column_window_double(table, "Double", 7, 4, 999.88),
01773        "Write 999.88 in \"Double\" column from 7 to 10... ");
01774 
01775   test(cpl_table_fill_column_window_double(table, "Double", 20, 7, 999.88),
01776        "Write 999.88 in \"Double\" column from 20 to end... ");
01777 
01778   test(cpl_table_fill_column_window_string(table, "String", 0, 2, "999"),
01779        "Write \"999\" in \"String\" column from 0 to 1... ");
01780 
01781   test(cpl_table_fill_column_window_string(table, "String", 3, 3, "999"),
01782        "Write \"999\" in \"String\" column from 3 to 5... ");
01783 
01784   test(cpl_table_fill_column_window_string(table, "String", 7, 4, "999"),
01785        "Write \"999\" in \"String\" column from 7 to 10... ");
01786 
01787   test(cpl_table_fill_column_window_string(table, "String", 20, 7, "999"),
01788        "Write \"999\" in \"String\" column from 20 to end... ");
01789 
01791   cpl_table_fill_invalid_int(table, "Integer", 320);
01792   cpl_table_fill_invalid_int(table, "AInt", 320);
01793   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01794   cpl_table_delete(table);
01795   table = cpl_table_load("test_table.tfits", 1, 1);
01796 
01797 
01798   test_ivalue(23, cpl_table_get_nrow(table), "Check table length (6)... ");
01799 
01800   test_ivalue(5, cpl_table_count_invalid(table, "Integer"), 
01801                                        "Count Integer NULLs... ");
01802 
01803   test_ivalue(5, cpl_table_count_invalid(table, "Float"), 
01804                                        "Count Float NULLs... ");
01805 
01806   test_ivalue(5, cpl_table_count_invalid(table, "Double"), 
01807                                        "Count Double NULLs... ");
01808 
01809   test_ivalue(5, cpl_table_count_invalid(table, "String"), 
01810                                        "Count String NULLs... ");
01811 
01812   test_ivalue(14, cpl_table_count_invalid(table, "AInt"),
01813                                        "Count AInt NULLs... ");
01814 
01815   test_ivalue(11, cpl_table_count_invalid(table, "AFloat"),
01816                                        "Count AFloat NULLs... ");
01817 
01818   test_ivalue(11, cpl_table_count_invalid(table, "ADouble"),
01819                                        "Count ADouble NULLs... ");
01820 
01821   test_ivalue(0, cpl_table_is_valid(table, "Integer", 2), 
01822                     "Check that third element of \"Integer\" is NULL... ");
01823 
01824   test_ivalue(1, cpl_table_is_valid(table, "Double", 0), 
01825                     "Check that first element of \"Double\" is not NULL... ");
01826 
01827   test_ivalue(1, cpl_table_is_valid(table, "String", 0), 
01828                     "Check that first element of \"String\" is not NULL... ");
01829 
01830   test_ivalue(0, cpl_table_is_valid(table, "String", 2), 
01831                     "Check that third element of \"String\" is NULL... ");
01832 
01833   test_ivalue(0, cpl_table_is_valid(table, "AInt", 17),
01834                     "Check that third element of \"AInt\" is NULL... ");
01835 
01836   test_ivalue(1, cpl_table_is_valid(table, "ADouble", 17),
01837                     "Check that first element of \"ADouble\" is not NULL... ");
01838 
01839   test_ivalue(1, cpl_table_is_valid(table, "AFloat", 17),
01840                     "Check that third element of \"AFloat\" is NULL... ");
01841 
01842   test_data(copia, cpl_table_duplicate(table), "Duplicate table... ");
01843 
01844   test(cpl_table_duplicate_column(table, "New Integer", table, "Integer"),
01845                         "Duplicate \"Integer\" column within same table... ");
01846 
01847   test(cpl_table_duplicate_column(table, "New Float", table, "Float"),
01848                         "Duplicate \"Float\" column within same table... ");
01849 
01850   test(cpl_table_duplicate_column(table, "New Double", table, "Double"),
01851                         "Duplicate \"Double\" column within same table... ");
01852 
01853   test(cpl_table_duplicate_column(table, "New String", table, "String"),
01854                         "Duplicate \"String\" column within same table... ");
01855 
01856   test(cpl_table_duplicate_column(table, "New AInt", table, "AInt"),
01857                         "Duplicate \"AInt\" column within same table... ");
01858 
01859   test(cpl_table_duplicate_column(table, "New AFloat", table, "AFloat"),
01860                         "Duplicate \"AFloat\" column within same table... ");
01861 
01862   test(cpl_table_duplicate_column(table, "New ADouble", table, "ADouble"),
01863                         "Duplicate \"ADouble\" column within same table... ");
01864 
01865   test_ivalue(5, cpl_table_count_invalid(table, "New Integer"), 
01866                                        "Count New Integer NULLs... ");
01867 
01868   test_ivalue(5, cpl_table_count_invalid(table, "New Float"), 
01869                                        "Count New Float NULLs... ");
01870 
01871   test_ivalue(5, cpl_table_count_invalid(table, "New Double"), 
01872                                        "Count New Double NULLs... ");
01873 
01874   test_ivalue(5, cpl_table_count_invalid(table, "New String"), 
01875                                        "Count New String NULLs... ");
01876 
01877   test_ivalue(14, cpl_table_count_invalid(table, "New AInt"),
01878                                        "Count New AInt NULLs... ");
01879 
01880   test_ivalue(11, cpl_table_count_invalid(table, "New AFloat"),
01881                                        "Count New AFloat NULLs... ");
01882 
01883   test_ivalue(11, cpl_table_count_invalid(table, "New ADouble"),
01884                                        "Count New ADouble NULLs... ");
01885 
01886   test(cpl_table_move_column(copia, "New Integer", table), 
01887            "Moving column \"New Integer\" to another table... ");
01888 
01889   test(cpl_table_move_column(copia, "New Float", table), 
01890            "Moving column \"New Float\" to another table... ");
01891 
01892   test(cpl_table_move_column(copia, "New Double", table), 
01893            "Moving column \"New Double\" to another table... ");
01894 
01895   test(cpl_table_move_column(copia, "New String", table), 
01896            "Moving column \"New String\" to another table... ");
01897 
01898   test_failure(CPL_ERROR_ILLEGAL_OUTPUT, 
01899                cpl_table_name_column(copia, "New String", "String"),
01900                "Try illegal column renaming... ");
01901 
01902   test(cpl_table_name_column(copia, "New Integer", "Old Integer"),
01903            "Try legal column renaming... ");
01904 
01906   cpl_table_fill_invalid_int(table, "Integer", 320);
01907   cpl_table_fill_invalid_int(table, "AInt", 320);
01908   cpl_table_fill_invalid_int(table, "New AInt", 320);
01909   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01910   cpl_table_delete(table);
01911   table = cpl_table_load("test_table.tfits", 1, 1);
01912 
01913 
01914   test_ivalue(!0, cpl_table_has_column(copia, "Old Integer"),
01915            "Check if column \"Old Integer\" exists... ");
01916 
01917   test_svalue("Integer", cpl_table_get_column_name(copia),
01918                                             "Check name column 1... ");
01919 
01920   test_svalue("Double", cpl_table_get_column_name(NULL),
01921                                             "Check name column 2... ");
01922 
01923   test_svalue("String", cpl_table_get_column_name(NULL),
01924                                             "Check name column 3... ");
01925 
01926   test_svalue("Float", cpl_table_get_column_name(NULL),
01927                                             "Check name column 4... ");
01928 
01929   test_svalue("AInt", cpl_table_get_column_name(NULL),
01930                                             "Check name column 5... ");
01931 
01932   test_svalue("AFloat", cpl_table_get_column_name(NULL),
01933                                             "Check name column 6... ");
01934   
01935   test_svalue("ADouble", cpl_table_get_column_name(NULL),
01936                                             "Check name column 7... ");
01937   
01938   test_svalue("Old Integer", cpl_table_get_column_name(NULL),
01939                                             "Check name column 8... ");
01940 
01941   test_svalue("New Float", cpl_table_get_column_name(NULL),
01942                                             "Check name column 9... ");
01943 
01944   test_svalue("New Double", cpl_table_get_column_name(NULL),
01945                                             "Check name column 10... ");
01946 
01947   test_svalue("New String", cpl_table_get_column_name(NULL),
01948                                             "Check name column 11... ");
01949 
01950   test_pvalue(NULL, (void *)cpl_table_get_column_name(NULL),
01951                                             "Check if no more colums... ");
01952 
01953   cpl_table_delete(copia);
01954 
01955 
01956   test(cpl_table_set_size(table, 30), "Expanding table to 30 rows... ");
01957 
01958 /*
01959  * The following would do the same as cpl_table_set_size(table, 30), in
01960  * case cpl_table_set_size() would be crossed out...
01961 
01962   test(cpl_table_insert_window(table, 24, 7), "Expanding table to 30 rows... ");
01963 */
01964 
01965   test_ivalue(12, cpl_table_count_invalid(table, "Integer"),
01966                                        "Count \"Integer\" NULLs... ");
01967 
01968   test_ivalue(12, cpl_table_count_invalid(table, "String"),
01969                                        "Count \"String\" NULLs... ");
01970 
01971   test(cpl_table_set_size(table, 22), "Truncating table to 22 rows... ");
01972 
01973 /*
01974  * The following would do the same as cpl_table_set_size(table, 30), in
01975  * case cpl_table_set_size() would be crossed out...
01976 
01977   test(cpl_table_erase_window(table, 22, 1000), 
01978                                "Truncating table to 22 rows... ");
01979 */
01980 
01982   cpl_table_fill_invalid_int(table, "Integer", 320);
01983   cpl_table_fill_invalid_int(table, "AInt", 320);
01984   cpl_table_fill_invalid_int(table, "New AInt", 320);
01985   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
01986   cpl_table_delete(table);
01987   table = cpl_table_load("test_table.tfits", 1, 1);
01988 
01989 
01990   test_ivalue(5, cpl_table_count_invalid(table, "Integer"),
01991                                        "Count \"Integer\" NULLs (2)... ");
01992 
01993   test_ivalue(5, cpl_table_count_invalid(table, "String"),
01994                                        "Count \"String\" NULLs (2)... ");
01995 
01996   test_data(copia, cpl_table_extract(table, 0, 5), 
01997                        "Creating subtable from rows 0-5 of original... ");
01998 
01999   test_ivalue(1, cpl_table_count_invalid(copia, "Integer"),
02000                                        "Count \"Integer\" NULLs... ");
02001 
02002   test_ivalue(1, cpl_table_count_invalid(copia, "String"),
02003                                        "Count \"String\" NULLs... ");
02004 
02005   cpl_table_delete(copia);
02006 
02007   test_data(copia, cpl_table_extract(table, 8, 5), 
02008                        "Creating subtable from rows 8-5 of original... ");
02009 
02010   test_ivalue(1, cpl_table_count_invalid(copia, "Float"),
02011                                        "Count \"Float\" NULLs... ");
02012 
02013   test_ivalue(1, cpl_table_count_invalid(copia, "String"),
02014                                        "Count \"String\" NULLs... ");
02015 
02016   cpl_table_delete(copia);
02017 
02018   test_data(copia, cpl_table_extract(table, 15, 30), 
02019               "Creating subtable from rows 15 till end of original... ");
02020 
02021   test_ivalue(3, cpl_table_count_invalid(copia, "Double"),
02022                                        "Count \"Double\" NULLs... ");
02023 
02024   test_ivalue(3, cpl_table_count_invalid(copia, "String"),
02025                                        "Count \"String\" NULLs... ");
02026 
02027   cpl_table_delete(copia);
02028 
02029   test(cpl_table_cast_column(table, "Float", "FloatToInt", CPL_TYPE_INT),
02030                       "Casting float column to integer colum... ");
02031 
02033   cpl_table_fill_invalid_int(table, "Integer", 320);
02034   cpl_table_fill_invalid_int(table, "FloatToInt", -2);
02035   cpl_table_fill_invalid_int(table, "AInt", 320);
02036   cpl_table_fill_invalid_int(table, "New AInt", 320);
02037   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
02038   cpl_table_delete(table);
02039   table = cpl_table_load("test_table.tfits", 1, 1);
02040 
02041 
02042   test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 0, NULL),
02043                        "Check element  1 of casted column... ");
02044   test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 1, NULL),
02045                        "Check element  2 of casted column... ");
02046   test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 2),
02047                        "Check element  3 of casted column... ");
02048   test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 3, NULL),
02049                        "Check element  4 of casted column... ");
02050   test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 4, NULL),
02051                        "Check element  5 of casted column... ");
02052   test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 5, NULL),
02053                        "Check element  6 of casted column... ");
02054   test_ivalue(-1, cpl_table_get_int(table, "FloatToInt", 6, NULL),
02055                        "Check element  7 of casted column... ");
02056   test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 7, NULL),
02057                        "Check element  8 of casted column... ");
02058   test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 8, NULL),
02059                        "Check element  9 of casted column... ");
02060   test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 9, NULL),
02061                        "Check element 10 of casted column... ");
02062   test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 10, NULL),
02063                        "Check element 11 of casted column... ");
02064   test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 11),
02065                        "Check element 12 of casted column... ");
02066   test_ivalue(3, cpl_table_get_int(table, "FloatToInt", 12, NULL),
02067                        "Check element 13 of casted column... ");
02068   test_ivalue(7, cpl_table_get_int(table, "FloatToInt", 13, NULL),
02069                        "Check element 14 of casted column... ");
02070   test_ivalue(1, cpl_table_get_int(table, "FloatToInt", 14, NULL),
02071                        "Check element 15 of casted column... ");
02072   test_ivalue(4, cpl_table_get_int(table, "FloatToInt", 15, NULL),
02073                        "Check element 16 of casted column... ");
02074   test_ivalue(6, cpl_table_get_int(table, "FloatToInt", 16, NULL),
02075                        "Check element 17 of casted column... ");
02076   test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 17),
02077                        "Check element 18 of casted column... ");
02078   test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 18),
02079                        "Check element 19 of casted column... ");
02080   test_ivalue(0, cpl_table_is_valid(table, "FloatToInt", 19),
02081                        "Check element 20 of casted column... ");
02082   test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 20, NULL),
02083                        "Check element 21 of casted column... ");
02084   test_ivalue(999, cpl_table_get_int(table, "FloatToInt", 21, NULL),
02085                        "Check element 22 of casted column... ");
02086 
02087   test(cpl_table_erase_column(table, "FloatToInt"),
02088                                       "Delete casted column... ");
02089 
02090   test(cpl_table_cast_column(table, "Integer", "IntToFloat", CPL_TYPE_FLOAT),
02091                       "Casting integer column to float colum... ");
02092 
02094   cpl_table_fill_invalid_int(table, "Integer", 320);
02095   cpl_table_fill_invalid_int(table, "AInt", 320);
02096   cpl_table_fill_invalid_int(table, "New AInt", 320);
02097   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
02098   cpl_table_delete(table);
02099   table = cpl_table_load("test_table.tfits", 1, 1);
02100 
02101 
02102   test_fvalue(999.0, 0.00001,
02103                      cpl_table_get_float(table, "IntToFloat", 0, NULL),
02104                      "Check element  1 of casted column (2)... ");
02105   test_fvalue(999.0, 0.00001,
02106                      cpl_table_get_float(table, "IntToFloat", 1, NULL),
02107                      "Check element  2 of casted column (2)... ");
02108   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2),
02109                      "Check element  3 of casted column (2)... ");
02110   test_fvalue(999.0, 0.00001,
02111                      cpl_table_get_float(table, "IntToFloat", 3, NULL),
02112                      "Check element  4 of casted column (2)... ");
02113   test_fvalue(999.0, 0.00001,
02114                      cpl_table_get_float(table, "IntToFloat", 4, NULL),
02115                      "Check element  5 of casted column (2)... ");
02116   test_fvalue(999.0, 0.00001,
02117                      cpl_table_get_float(table, "IntToFloat", 5, NULL),
02118                      "Check element  6 of casted column (2)... ");
02119   test_fvalue(-1.0, 0.00001,
02120                      cpl_table_get_float(table, "IntToFloat", 6, NULL),
02121                      "Check element  7 of casted column (2)... ");
02122   test_fvalue(999.0, 0.00001,
02123                      cpl_table_get_float(table, "IntToFloat", 7, NULL),
02124                      "Check element  8 of casted column (2)... ");
02125   test_fvalue(999.0, 0.00001,
02126                      cpl_table_get_float(table, "IntToFloat", 8, NULL),
02127                      "Check element  9 of casted column (2)... ");
02128   test_fvalue(999.0, 0.00001,
02129                      cpl_table_get_float(table, "IntToFloat", 9, NULL),
02130                      "Check element 10 of casted column (2)... ");
02131   test_fvalue(999.0, 0.00001,
02132                      cpl_table_get_float(table, "IntToFloat", 10, NULL),
02133                      "Check element 11 of casted column (2)... ");
02134   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11),
02135                      "Check element 12 of casted column (2)... ");
02136   test_fvalue(3.0, 0.00001,
02137                      cpl_table_get_float(table, "IntToFloat", 12, NULL),
02138                      "Check element 13 of casted column (2)... ");
02139   test_fvalue(7.0, 0.00001,
02140                      cpl_table_get_float(table, "IntToFloat", 13, NULL),
02141                      "Check element 14 of casted column (2)... ");
02142   test_fvalue(1.0, 0.00001,
02143                      cpl_table_get_float(table, "IntToFloat", 14, NULL),
02144                      "Check element 15 of casted column (2)... ");
02145   test_fvalue(4.0, 0.00001,
02146                      cpl_table_get_float(table, "IntToFloat", 15, NULL),
02147                      "Check element 16 of casted column (2)... ");
02148   test_fvalue(6.0, 0.00001,
02149                      cpl_table_get_float(table, "IntToFloat", 16, NULL),
02150                      "Check element 17 of casted column (2)... ");
02151   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17),
02152                      "Check element 18 of casted column (2)... ");
02153   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18),
02154                      "Check element 19 of casted column (2)... ");
02155   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19),
02156                      "Check element 20 of casted column (2)... ");
02157   test_fvalue(999.0, 0.00001,
02158                      cpl_table_get_float(table, "IntToFloat", 20, NULL),
02159                      "Check element 21 of casted column (2)... ");
02160   test_fvalue(999.0, 0.00001,
02161                      cpl_table_get_float(table, "IntToFloat", 21, NULL),
02162                      "Check element 22 of casted column (2)... ");
02163 
02164   test(cpl_table_shift_column(table, "IntToFloat", 1), 
02165                               "Shift new column one position down... ");
02166 
02167   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0),
02168                      "Check element  1 of shifted column... ");
02169   test_fvalue(999.0, 0.00001,
02170                      cpl_table_get_float(table, "IntToFloat", 1, NULL),
02171                      "Check element  2 of shifted column... ");
02172   test_fvalue(999.0, 0.00001,
02173                      cpl_table_get_float(table, "IntToFloat", 2, NULL),
02174                      "Check element  3 of shifted column... ");
02175   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3),
02176                      "Check element  4 of shifted column... ");
02177   test_fvalue(999.0, 0.00001,
02178                      cpl_table_get_float(table, "IntToFloat", 4, NULL),
02179                      "Check element  5 of shifted column... ");
02180   test_fvalue(999.0, 0.00001,
02181                      cpl_table_get_float(table, "IntToFloat", 5, NULL),
02182                      "Check element  6 of shifted column... ");
02183   test_fvalue(999.0, 0.00001,
02184                      cpl_table_get_float(table, "IntToFloat", 6, NULL),
02185                      "Check element  7 of shifted column... ");
02186   test_fvalue(-1.0, 0.00001,
02187                      cpl_table_get_float(table, "IntToFloat", 7, NULL),
02188                      "Check element  8 of shifted column... ");
02189   test_fvalue(999.0, 0.00001,
02190                      cpl_table_get_float(table, "IntToFloat", 8, NULL),
02191                      "Check element  9 of shifted column... ");
02192   test_fvalue(999.0, 0.00001,
02193                      cpl_table_get_float(table, "IntToFloat", 9, NULL),
02194                      "Check element 10 of shifted column... ");
02195   test_fvalue(999.0, 0.00001,
02196                      cpl_table_get_float(table, "IntToFloat", 10, NULL),
02197                      "Check element 11 of shifted column... ");
02198   test_fvalue(999.0, 0.00001,
02199                      cpl_table_get_float(table, "IntToFloat", 11, NULL),
02200                      "Check element 12 of shifted column... ");
02201   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12),
02202                      "Check element 13 of shifted column... ");
02203   test_fvalue(3.0, 0.00001,
02204                      cpl_table_get_float(table, "IntToFloat", 13, NULL),
02205                      "Check element 14 of shifted column... ");
02206   test_fvalue(7.0, 0.00001,
02207                      cpl_table_get_float(table, "IntToFloat", 14, NULL),
02208                      "Check element 15 of shifted column... ");
02209   test_fvalue(1.0, 0.00001,
02210                      cpl_table_get_float(table, "IntToFloat", 15, NULL),
02211                      "Check element 16 of shifted column... ");
02212   test_fvalue(4.0, 0.00001,
02213                      cpl_table_get_float(table, "IntToFloat", 16, NULL),
02214                      "Check element 17 of shifted column... ");
02215   test_fvalue(6.0, 0.00001,
02216                      cpl_table_get_float(table, "IntToFloat", 17, NULL),
02217                      "Check element 18 of shifted column... ");
02218   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18),
02219                      "Check element 19 of shifted column... ");
02220   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19),
02221                      "Check element 20 of shifted column... ");
02222   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20),
02223                      "Check element 21 of shifted column... ");
02224   test_fvalue(999.0, 0.00001,
02225                      cpl_table_get_float(table, "IntToFloat", 21, NULL),
02226                      "Check element 22 of shifted column... ");
02227 
02228   test(cpl_table_add_columns(table, "Integer", "IntToFloat"), 
02229                             "Sum \"IntToFloat\" to \"Integer\"... ");
02230 
02232   cpl_table_fill_invalid_int(table, "Integer", 320);
02233   cpl_table_fill_invalid_int(table, "AInt", 320);
02234   cpl_table_fill_invalid_int(table, "New AInt", 320);
02235   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
02236   cpl_table_delete(table);
02237   table = cpl_table_load("test_table.tfits", 1, 1);
02238 
02239 
02240   test_ivalue(0, cpl_table_is_valid(table, "Integer", 0),
02241                        "Check element  1 of \"Integer\" += \"IntToFloat\"... ");
02242   test_ivalue(1998, cpl_table_get_int(table, "Integer", 1, NULL),
02243                        "Check element  2 of \"Integer\" += \"IntToFloat\"... ");
02244   test_ivalue(0, cpl_table_is_valid(table, "Integer", 2),
02245                        "Check element  3 of \"Integer\" += \"IntToFloat\"... ");
02246   test_ivalue(0, cpl_table_is_valid(table, "Integer", 3),
02247                        "Check element  4 of \"Integer\" += \"IntToFloat\"... ");
02248   test_ivalue(1998, cpl_table_get_int(table, "Integer", 4, NULL),
02249                        "Check element  5 of \"Integer\" += \"IntToFloat\"... ");
02250   test_ivalue(1998, cpl_table_get_int(table, "Integer", 5, NULL),
02251                        "Check element  6 of \"Integer\" += \"IntToFloat\"... ");
02252   test_ivalue(998, cpl_table_get_int(table, "Integer", 6, NULL),
02253                        "Check element  7 of \"Integer\" += \"IntToFloat\"... ");
02254   test_ivalue(998, cpl_table_get_int(table, "Integer", 7, NULL),
02255                        "Check element  8 of \"Integer\" += \"IntToFloat\"... ");
02256   test_ivalue(1998, cpl_table_get_int(table, "Integer", 8, NULL),
02257                        "Check element  9 of \"Integer\" += \"IntToFloat\"... ");
02258   test_ivalue(1998, cpl_table_get_int(table, "Integer", 9, NULL),
02259                        "Check element 10 of \"Integer\" += \"IntToFloat\"... ");
02260   test_ivalue(1998, cpl_table_get_int(table, "Integer", 10, NULL),
02261                        "Check element 11 of \"Integer\" += \"IntToFloat\"... ");
02262   test_ivalue(0, cpl_table_is_valid(table, "Integer", 11),
02263                        "Check element 12 of \"Integer\" += \"IntToFloat\"... ");
02264   test_ivalue(0, cpl_table_is_valid(table, "Integer", 12),
02265                        "Check element 13 of \"Integer\" += \"IntToFloat\"... ");
02266   test_ivalue(10, cpl_table_get_int(table, "Integer", 13, NULL),
02267                        "Check element 14 of \"Integer\" += \"IntToFloat\"... ");
02268   test_ivalue(8, cpl_table_get_int(table, "Integer", 14, NULL),
02269                        "Check element 15 of \"Integer\" += \"IntToFloat\"... ");
02270   test_ivalue(5, cpl_table_get_int(table, "Integer", 15, NULL),
02271                        "Check element 16 of \"Integer\" += \"IntToFloat\"... ");
02272   test_ivalue(10, cpl_table_get_int(table, "Integer", 16, NULL),
02273                        "Check element 17 of \"Integer\" += \"IntToFloat\"... ");
02274   test_ivalue(0, cpl_table_is_valid(table, "Integer", 17),
02275                        "Check element 18 of \"Integer\" += \"IntToFloat\"... ");
02276   test_ivalue(0, cpl_table_is_valid(table, "Integer", 18),
02277                        "Check element 19 of \"Integer\" += \"IntToFloat\"... ");
02278   test_ivalue(0, cpl_table_is_valid(table, "Integer", 19),
02279                        "Check element 20 of \"Integer\" += \"IntToFloat\"... ");
02280   test_ivalue(0, cpl_table_is_valid(table, "Integer", 20),
02281                        "Check element 21 of \"Integer\" += \"IntToFloat\"... ");
02282   test_ivalue(1998, cpl_table_get_int(table, "Integer", 21, NULL),
02283                        "Check element 22 of \"Integer\" += \"IntToFloat\"... ");
02284 
02285   test(cpl_table_subtract_columns(table, "Integer", "IntToFloat"), 
02286                             "Subtract \"IntToFloat\" from \"Integer\"... ");
02287 
02288   test(cpl_table_subtract_columns(table, "IntToFloat", "Integer"), 
02289                             "Subtract \"Integer\" from \"IntToFloat\"... ");
02290 
02291   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0),
02292                      "Check element  1 of \"IntToFloat\" -= \"Integer\"... ");
02293   test_fvalue(0.0, 0.00001,
02294                      cpl_table_get_float(table, "IntToFloat", 1, NULL),
02295                      "Check element  2 of \"IntToFloat\" -= \"Integer\"... ");
02296   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2),
02297                      "Check element  3 of \"IntToFloat\" -= \"Integer\"... ");
02298   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3),
02299                      "Check element  4 of \"IntToFloat\" -= \"Integer\"... ");
02300   test_fvalue(0.0, 0.00001,
02301                      cpl_table_get_float(table, "IntToFloat", 4, NULL),
02302                      "Check element  5 of \"IntToFloat\" -= \"Integer\"... ");
02303   test_fvalue(0.0, 0.00001,
02304                      cpl_table_get_float(table, "IntToFloat", 5, NULL),
02305                      "Check element  6 of \"IntToFloat\" -= \"Integer\"... ");
02306   test_fvalue(1000.0, 0.00001,
02307                      cpl_table_get_float(table, "IntToFloat", 6, NULL),
02308                      "Check element  7 of \"IntToFloat\" -= \"Integer\"... ");
02309   test_fvalue(-1000.0, 0.00001,
02310                      cpl_table_get_float(table, "IntToFloat", 7, NULL),
02311                      "Check element  8 of \"IntToFloat\" -= \"Integer\"... ");
02312   test_fvalue(0.0, 0.00001,
02313                      cpl_table_get_float(table, "IntToFloat", 8, NULL),
02314                      "Check element  9 of \"IntToFloat\" -= \"Integer\"... ");
02315   test_fvalue(0.0, 0.00001,
02316                      cpl_table_get_float(table, "IntToFloat", 9, NULL),
02317                      "Check element 10 of \"IntToFloat\" -= \"Integer\"... ");
02318   test_fvalue(0.0, 0.00001,
02319                      cpl_table_get_float(table, "IntToFloat", 10, NULL),
02320                      "Check element 11 of \"IntToFloat\" -= \"Integer\"... ");
02321   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11),
02322                      "Check element 12 of \"IntToFloat\" -= \"Integer\"... ");
02323   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12),
02324                      "Check element 13 of \"IntToFloat\" -= \"Integer\"... ");
02325   test_fvalue(-4.0, 0.00001,
02326                      cpl_table_get_float(table, "IntToFloat", 13, NULL),
02327                      "Check element 14 of \"IntToFloat\" -= \"Integer\"... ");
02328   test_fvalue(6.0, 0.00001,
02329                      cpl_table_get_float(table, "IntToFloat", 14, NULL),
02330                      "Check element 15 of \"IntToFloat\" -= \"Integer\"... ");
02331   test_fvalue(-3.0, 0.00001,
02332                      cpl_table_get_float(table, "IntToFloat", 15, NULL),
02333                      "Check element 16 of \"IntToFloat\" -= \"Integer\"... ");
02334   test_fvalue(-2.0, 0.00001,
02335                      cpl_table_get_float(table, "IntToFloat", 16, NULL),
02336                      "Check element 17 of \"IntToFloat\" -= \"Integer\"... ");
02337   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17),
02338                      "Check element 18 of \"IntToFloat\" -= \"Integer\"... ");
02339   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18),
02340                      "Check element 19 of \"IntToFloat\" -= \"Integer\"... ");
02341   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19),
02342                      "Check element 20 of \"IntToFloat\" -= \"Integer\"... ");
02343   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20),
02344                      "Check element 21 of \"IntToFloat\" -= \"Integer\"... ");
02345   test_fvalue(0.0, 0.00001,
02346                      cpl_table_get_float(table, "IntToFloat", 21, NULL),
02347                      "Check element 22 of \"IntToFloat\" -= \"Integer\"... ");
02348 
02349   test(cpl_table_multiply_columns(table, "IntToFloat", "Double"), 
02350                      "Multiply double column with float column... ");
02351 
02352   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 0),
02353                      "Check element  1 of \"IntToFloat\" *= \"Double\"... ");
02354   test_fvalue(0.0, 0.00001,
02355                      cpl_table_get_float(table, "IntToFloat", 1, NULL),
02356                      "Check element  2 of \"IntToFloat\" *= \"Double\"... ");
02357   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 2),
02358                      "Check element  3 of \"IntToFloat\" *= \"Double\"... ");
02359   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 3),
02360                      "Check element  4 of \"IntToFloat\" *= \"Double\"... ");
02361   test_fvalue(0.0, 0.00001,
02362                      cpl_table_get_float(table, "IntToFloat", 4, NULL),
02363                      "Check element  5 of \"IntToFloat\" *= \"Double\"... ");
02364   test_fvalue(0.0, 0.00001,
02365                      cpl_table_get_float(table, "IntToFloat", 5, NULL),
02366                      "Check element  6 of \"IntToFloat\" *= \"Double\"... ");
02367   test_fvalue(-1110.0, 0.00001,
02368                      cpl_table_get_float(table, "IntToFloat", 6, NULL),
02369                      "Check element  7 of \"IntToFloat\" *= \"Double\"... ");
02370   test_fvalue(-999880.0, 0.00001,
02371                      cpl_table_get_float(table, "IntToFloat", 7, NULL),
02372                      "Check element  8 of \"IntToFloat\" *= \"Double\"... ");
02373   test_fvalue(0.0, 0.00001,
02374                      cpl_table_get_float(table, "IntToFloat", 8, NULL),
02375                      "Check element  9 of \"IntToFloat\" *= \"Double\"... ");
02376   test_fvalue(0.0, 0.00001,
02377                      cpl_table_get_float(table, "IntToFloat", 9, NULL),
02378                      "Check element 10 of \"IntToFloat\" *= \"Double\"... ");
02379   test_fvalue(0.0, 0.00001,
02380                      cpl_table_get_float(table, "IntToFloat", 10, NULL),
02381                      "Check element 11 of \"IntToFloat\" *= \"Double\"... ");
02382   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 11),
02383                      "Check element 12 of \"IntToFloat\" *= \"Double\"... ");
02384   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 12),
02385                      "Check element 13 of \"IntToFloat\" *= \"Double\"... ");
02386   test_fvalue(-28.44, 0.00001,
02387                      cpl_table_get_float(table, "IntToFloat", 13, NULL),
02388                      "Check element 14 of \"IntToFloat\" *= \"Double\"... ");
02389   test_fvalue(6.66, 0.00001,
02390                      cpl_table_get_float(table, "IntToFloat", 14, NULL),
02391                      "Check element 15 of \"IntToFloat\" *= \"Double\"... ");
02392   test_fvalue(-12.33, 0.00001,
02393                      cpl_table_get_float(table, "IntToFloat", 15, NULL),
02394                      "Check element 16 of \"IntToFloat\" *= \"Double\"... ");
02395   test_fvalue(-12.22, 0.00001,
02396                      cpl_table_get_float(table, "IntToFloat", 16, NULL),
02397                      "Check element 17 of \"IntToFloat\" *= \"Double\"... ");
02398   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 17),
02399                      "Check element 18 of \"IntToFloat\" *= \"Double\"... ");
02400   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 18),
02401                      "Check element 19 of \"IntToFloat\" *= \"Double\"... ");
02402   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 19),
02403                      "Check element 20 of \"IntToFloat\" *= \"Double\"... ");
02404   test_ivalue(0, cpl_table_is_valid(table, "IntToFloat", 20),
02405                      "Check element 21 of \"IntToFloat\" *= \"Double\"... ");
02406   test_fvalue(0.0, 0.00001,
02407                      cpl_table_get_float(table, "IntToFloat", 21, NULL),
02408                      "Check element 22 of \"IntToFloat\" *= \"Double\"... ");
02409 
02410   test(cpl_table_divide_columns(table, "Float", "IntToFloat"), 
02411                      "Divide float column with float column... ");
02412 
02413   test_ivalue(0, cpl_table_is_valid(table, "Float", 0),
02414                      "Check element  1 of \"Float\" /= \"IntToFloat\"... ");
02415   test_ivalue(0, cpl_table_is_valid(table, "Float", 1),
02416                      "Check element  2 of \"Float\" /= \"IntToFloat\"... ");
02417   test_ivalue(0, cpl_table_is_valid(table, "Float", 2),
02418                      "Check element  3 of \"Float\" /= \"IntToFloat\"... ");
02419   test_ivalue(0, cpl_table_is_valid(table, "Float", 3),
02420                      "Check element  4 of \"Float\" /= \"IntToFloat\"... ");
02421   test_ivalue(0, cpl_table_is_valid(table, "Float", 4),
02422                      "Check element  5 of \"Float\" /= \"IntToFloat\"... ");
02423   test_ivalue(0, cpl_table_is_valid(table, "Float", 5),
02424                      "Check element  6 of \"Float\" /= \"IntToFloat\"... ");
02425   test_fvalue(0.000991, 0.0000001,
02426                      cpl_table_get_float(table, "Float", 6, NULL),
02427                      "Check element  7 of \"Float\" /= \"IntToFloat\"... ");
02428   test_fvalue(-0.0010001, 0.0000001,
02429                      cpl_table_get_float(table, "Float", 7, NULL),
02430                      "Check element  8 of \"Float\" /= \"IntToFloat\"... ");
02431   test_ivalue(0, cpl_table_is_valid(table, "Float", 8),
02432                      "Check element  9 of \"Float\" /= \"IntToFloat\"... ");
02433   test_ivalue(0, cpl_table_is_valid(table, "Float", 9),
02434                      "Check element 10 of \"Float\" /= \"IntToFloat\"... ");
02435   test_ivalue(0, cpl_table_is_valid(table, "Float", 10),
02436                      "Check element 11 of \"Float\" /= \"IntToFloat\"... ");
02437   test_ivalue(0, cpl_table_is_valid(table, "Float", 11),
02438                      "Check element 12 of \"Float\" /= \"IntToFloat\"... ");
02439   test_ivalue(0, cpl_table_is_valid(table, "Float", 12),
02440                      "Check element 13 of \"Float\" /= \"IntToFloat\"... ");
02441   test_fvalue(-0.2496484, 0.0000001,
02442                      cpl_table_get_float(table, "Float", 13, NULL),
02443                      "Check element 14 of \"Float\" /= \"IntToFloat\"... ");
02444   test_fvalue(0.1651652, 0.0000001,
02445                      cpl_table_get_float(table, "Float", 14, NULL),
02446                      "Check element 15 of \"Float\" /= \"IntToFloat\"... ");
02447   test_fvalue(-0.3325223, 0.0000001,
02448                      cpl_table_get_float(table, "Float", 15, NULL),
02449                      "Check element 16 of \"Float\" /= \"IntToFloat\"... ");
02450   test_fvalue(-0.4991817, 0.0000001,
02451                      cpl_table_get_float(table, "Float", 16, NULL),
02452                      "Check element 17 of \"Float\" /= \"IntToFloat\"... ");
02453   test_ivalue(0, cpl_table_is_valid(table, "Float", 17),
02454                      "Check element 18 of \"Float\" /= \"IntToFloat\"... ");
02455   test_ivalue(0, cpl_table_is_valid(table, "Float", 18),
02456                      "Check element 19 of \"Float\" /= \"IntToFloat\"... ");
02457   test_ivalue(0, cpl_table_is_valid(table, "Float", 19),
02458                      "Check element 20 of \"Float\" /= \"IntToFloat\"... ");
02459   test_ivalue(0, cpl_table_is_valid(table, "Float", 20),
02460                      "Check element 21 of \"Float\" /= \"IntToFloat\"... ");
02461   test_ivalue(0, cpl_table_is_valid(table, "Float", 21),
02462                      "Check element 22 of \"Float\" /= \"IntToFloat\"... ");
02463 
02464   test(cpl_table_add_scalar(table, "Float", 1), 
02465                      "Add integer constant to \"Float\"... ");
02466 
02467   test_ivalue(0, cpl_table_is_valid(table, "Float", 0),
02468                      "Check element  1 of adding 1 to \"Float\"... ");
02469   test_ivalue(0, cpl_table_is_valid(table, "Float", 1),
02470                      "Check element  2 of adding 1 to \"Float\"... ");
02471   test_ivalue(0, cpl_table_is_valid(table, "Float", 2),
02472                      "Check element  3 of adding 1 to \"Float\"... ");
02473   test_ivalue(0, cpl_table_is_valid(table, "Float", 3),
02474                      "Check element  4 of adding 1 to \"Float\"... ");
02475   test_ivalue(0, cpl_table_is_valid(table, "Float", 4),
02476                      "Check element  5 of adding 1 to \"Float\"... ");
02477   test_ivalue(0, cpl_table_is_valid(table, "Float", 5),
02478                      "Check element  6 of adding 1 to \"Float\"... ");
02479   test_fvalue(1.000991, 0.0000001,
02480                      cpl_table_get_float(table, "Float", 6, NULL),
02481                      "Check element  7 of adding 1 to \"Float\"... ");
02482   test_fvalue(1-0.0010001, 0.0000001,
02483                      cpl_table_get_float(table, "Float", 7, NULL),
02484                      "Check element  8 of adding 1 to \"Float\"... ");
02485   test_ivalue(0, cpl_table_is_valid(table, "Float", 8),
02486                      "Check element  9 of adding 1 to \"Float\"... ");
02487   test_ivalue(0, cpl_table_is_valid(table, "Float", 9),
02488                      "Check element 10 of adding 1 to \"Float\"... ");
02489   test_ivalue(0, cpl_table_is_valid(table, "Float", 10),
02490                      "Check element 11 of adding 1 to \"Float\"... ");
02491   test_ivalue(0, cpl_table_is_valid(table, "Float", 11),
02492                      "Check element 12 of adding 1 to \"Float\"... ");
02493   test_ivalue(0, cpl_table_is_valid(table, "Float", 12),
02494                      "Check element 13 of adding 1 to \"Float\"... ");
02495   test_fvalue(1-0.2496484, 0.0000001,
02496                      cpl_table_get_float(table, "Float", 13, NULL),
02497                      "Check element 14 of adding 1 to \"Float\"... ");
02498   test_fvalue(1.1651652, 0.0000001,
02499                      cpl_table_get_float(table, "Float", 14, NULL),
02500                      "Check element 15 of adding 1 to \"Float\"... ");
02501   test_fvalue(1-0.3325223, 0.0000001,
02502                      cpl_table_get_float(table, "Float", 15, NULL),
02503                      "Check element 16 of adding 1 to \"Float\"... ");
02504   test_fvalue(1-0.4991817, 0.0000001,
02505                      cpl_table_get_float(table, "Float", 16, NULL),
02506                      "Check element 17 of adding 1 to \"Float\"... ");
02507   test_ivalue(0, cpl_table_is_valid(table, "Float", 17),
02508                      "Check element 18 of adding 1 to \"Float\"... ");
02509   test_ivalue(0, cpl_table_is_valid(table, "Float", 18),
02510                      "Check element 19 of adding 1 to \"Float\"... ");
02511   test_ivalue(0, cpl_table_is_valid(table, "Float", 19),
02512                      "Check element 20 of adding 1 to \"Float\"... ");
02513   test_ivalue(0, cpl_table_is_valid(table, "Float", 20),
02514                      "Check element 21 of adding 1 to \"Float\"... ");
02515   test_ivalue(0, cpl_table_is_valid(table, "Float", 21),
02516                      "Check element 22 of adding 1 to \"Float\"... ");
02517 
02518   test(cpl_table_set_column_invalid(table, "Float", 0, 
02519                      cpl_table_get_nrow(table)), 
02520                      "Set \"Float\" column to NULL... ");
02521 
02522   test_data(copia, cpl_table_duplicate(table), "Duplicate table... ");
02523 
02524   test(cpl_table_erase_invalid_rows(table), "Pruning table... ");
02525 
02526   test_ivalue(18, cpl_table_get_nrow(table), 
02527                        "Checking table length after pruning... ");
02528 
02529   test_ivalue(10, cpl_table_get_ncol(table), 
02530                        "Checking table width after pruning... ");
02531 
02532   test(cpl_table_erase_invalid(copia), "Cleaning table... ");
02533 
02534   test_ivalue(8, cpl_table_get_nrow(copia), 
02535                        "Checking table length after cleaning... ");
02536 
02537   test_ivalue(10, cpl_table_get_ncol(copia), 
02538                        "Checking table width after cleaning... ");
02539 
02540   cpl_table_delete(copia);
02541 
02542   test(cpl_table_name_column(table, "IntToFloat", "Float"),
02543            "Renaming \"IntToFloat\" to \"Float\"... ");
02544 
02545   test(cpl_table_set_column_invalid(table, "Integer", 7, 2), 
02546                               "Set NULLs in \"Integer\" column... ");
02547 
02548   test(cpl_table_set_invalid(table, "Float", 7), 
02549                               "Set NULL in \"Float\" column... ");
02550 
02551   test(cpl_table_set_invalid(table, "Float", 9), 
02552                               "Set another NULL in \"Float\" column... ");
02553 
02554   test(cpl_table_set_invalid(table, "Double", 7), 
02555                               "Set NULL in \"Double\" column... ");
02556 
02557   test(cpl_table_set_invalid(table, "String", 7), 
02558                               "Set NULL in \"String\" column... ");
02559 
02560   test(cpl_table_new_column(table, "Sequence", CPL_TYPE_INT),
02561                                 "Creating the \"Sequence\" column... ");
02562 
02563   for (i = 0; i < 18; i++) {
02564     sprintf(message, "Writing to row %d of the \"Sequence\" column... ", i);
02565     test(cpl_table_set_int(table, "Sequence", i, i), message);
02566   }
02567 /*
02568   cpl_table_dump_structure(table);
02569   cpl_table_dump(table, 0, cpl_table_get_nrow(table));
02570 */
02571   names[0] = "Integer";
02572 
02573   reflist = uves_propertylist_new();
02574   uves_propertylist_append_bool(reflist, names[0], 0);
02575 /* %$% */
02576 /*
02577 cpl_table_dump_structure(table, NULL);
02578 cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
02579 */
02580 
02581   test(uves_table_sort(table, reflist), 
02582        "Sorting by increasing values of the \"Integer\" column... ");
02583 
02584   uves_propertylist_delete(reflist);
02585 
02587   cpl_table_fill_invalid_int(table, "Integer", 320);
02588   cpl_table_fill_invalid_int(table, "AInt", 320);
02589   cpl_table_fill_invalid_int(table, "New AInt", 320);
02590   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
02591   cpl_table_delete(table);
02592   table = cpl_table_load("test_table.tfits", 1, 1);
02593 
02594 
02595   test_ivalue(18, cpl_table_get_nrow(table),
02596                        "Checking table length after sorting... ");
02597 
02598   test_ivalue(11, cpl_table_get_ncol(table),
02599                        "Checking table width after sorting... ");
02600 
02601   test_ivalue(7, cpl_table_count_invalid(table, "Integer"),
02602                      "Count \"Integer\" NULLs after sorting... ");
02603 
02604   test_ivalue(7, cpl_table_count_invalid(table, "Float"),
02605                      "Count \"Float\" NULLs after sorting... ");
02606 
02607   test_ivalue(2, cpl_table_count_invalid(table, "Double"),
02608                      "Count \"Double\" NULLs after sorting... ");
02609 
02610   test_ivalue(2, cpl_table_count_invalid(table, "String"),
02611                      "Count \"String\" NULLs after sorting... ");
02612 
02613   for (i = 0; i < 7; i++) {
02614     sprintf(message, "Check element  %d of sorted \"Integer\"... ", i + 1);
02615     test_ivalue(0, cpl_table_is_valid(table, "Integer", i), message);
02616   }
02617 
02618   test_ivalue(-1, cpl_table_get_int(table, "Integer", 7, NULL),
02619                      "Check element  7 of sorted \"Integer\"... ");
02620 
02621   test_ivalue(1, cpl_table_get_int(table, "Integer", 8, NULL),
02622                      "Check element  8 of sorted \"Integer\"... ");
02623 
02624   test_ivalue(4, cpl_table_get_int(table, "Integer", 9, NULL),
02625                      "Check element  9 of sorted \"Integer\"... ");
02626 
02627   test_ivalue(6, cpl_table_get_int(table, "Integer", 10, NULL),
02628                      "Check element 10 of sorted \"Integer\"... ");
02629 
02630   test_ivalue(7, cpl_table_get_int(table, "Integer", 11, NULL),
02631                      "Check element 11 of sorted \"Integer\"... ");
02632 
02633   for (i = 12; i < 18; i++) {
02634     sprintf(message, "Check element  %d of sorted \"Integer\"... ", i + 1);
02635     test_ivalue(999, cpl_table_get_int(table, "Integer", i, NULL),
02636                        message);
02637   }
02638 
02639   test_fvalue(999.88, 0.00001,
02640                      cpl_table_get_double(table, "Double", 0, NULL),
02641                      "Check element  1 of sorted \"Double\"... ");
02642 
02643   test_fvalue(999.88, 0.00001,
02644                      cpl_table_get_double(table, "Double", 1, NULL),
02645                      "Check element  2 of sorted \"Double\"... ");
02646 
02647   test_ivalue(0, cpl_table_is_valid(table, "Double", 2), 
02648                      "Check element  3 of sorted \"Double\"... ");
02649 
02650   test_fvalue(999.88, 0.00001,
02651                      cpl_table_get_double(table, "Double", 3, NULL),
02652                      "Check element  4 of sorted \"Double\"... ");
02653 
02654   test_fvalue(3.11, 0.00001,
02655                      cpl_table_get_double(table, "Double", 4, NULL),
02656                      "Check element  5 of sorted \"Double\"... ");
02657 
02658   test_ivalue(0, cpl_table_is_valid(table, "Double", 5), 
02659                      "Check element  6 of sorted \"Double\"... ");
02660 
02661   test_fvalue(999.88, 0.00001,
02662                      cpl_table_get_double(table, "Double", 6, NULL),
02663                      "Check element  7 of sorted \"Double\"... ");
02664 
02665   test_fvalue(-1.11, 0.00001,
02666                      cpl_table_get_double(table, "Double", 7, NULL),
02667                      "Check element  8 of sorted \"Double\"... ");
02668 
02669   test_fvalue(1.11, 0.00001,
02670                     cpl_table_get_double(table, "Double", 8, NULL),
02671                     "Check element  9 of sorted \"Double\"... ");
02672 
02673   test_fvalue(4.11, 0.00001,
02674                     cpl_table_get_double(table, "Double", 9, NULL),
02675                     "Check element  10 of sorted \"Double\"... ");
02676 
02677   test_fvalue(6.11, 0.00001,
02678                     cpl_table_get_double(table, "Double", 10, NULL),
02679                     "Check element 11 of sorted \"Double\"... ");
02680 
02681   test_fvalue(7.11, 0.00001,
02682                     cpl_table_get_double(table, "Double", 11, NULL),
02683                     "Check element 12 of sorted \"Double\"... ");
02684 
02685   for (i = 12; i < 18; i++) {
02686     sprintf(message, "Check element  %d of sorted \"Double\"... ", i + 1);
02687     test_fvalue(999.88, 0.00001, 
02688                 cpl_table_get_double(table, "Double", i, NULL), message);
02689   }
02690 
02691   test_svalue("999", cpl_table_get_string(table, "String", 0),
02692               "Check element  1 of sorted \"String\"... ");
02693 
02694   test_svalue("999", cpl_table_get_string(table, "String", 1),
02695               "Check element  2 of sorted \"String\"... ");
02696 
02697   test_ivalue(0, cpl_table_is_valid(table, "String", 2),
02698               "Check element  3 of sorted \"String\"... ");
02699 
02700   test_svalue("999", cpl_table_get_string(table, "String", 3),
02701               "Check element  4 of sorted \"String\"... ");
02702 
02703   test_svalue("baaa", cpl_table_get_string(table, "String", 4),
02704               "Check element  5 of sorted \"String\"... ");
02705 
02706   test_ivalue(0, cpl_table_is_valid(table, "String", 5),
02707               "Check element  6 of sorted \"String\"... ");
02708 
02709   test_svalue("999", cpl_table_get_string(table, "String", 6),
02710               "Check element  7 of sorted \"String\"... ");
02711 
02712   test_svalue("extra", cpl_table_get_string(table, "String", 7),
02713               "Check element  8 of sorted \"String\"... ");
02714 
02715   test_svalue("acde", cpl_table_get_string(table, "String", 8),
02716               "Check element  9 of sorted \"String\"... ");
02717 
02718   test_svalue(" sss", cpl_table_get_string(table, "String", 9),
02719               "Check element 10 of sorted \"String\"... ");
02720 
02721   test_svalue("daaa", cpl_table_get_string(table, "String", 10),
02722               "Check element 11 of sorted \"String\"... ");
02723 
02724   test_svalue("aaaa", cpl_table_get_string(table, "String", 11),
02725               "Check element 11 of sorted \"String\"... ");
02726 
02727   for (i = 12; i < 18; i++) {
02728     sprintf(message, "Check element  %d of sorted \"String\"... ", i + 1);
02729     test_svalue("999", cpl_table_get_string(table, "String", i), message);
02730   }
02731 
02732 
02733   test_ivalue(0, cpl_table_is_valid(table, "Float", 0),
02734               "Check element  1 of sorted \"Float\"... ");
02735 
02736   test_ivalue(0, cpl_table_is_valid(table, "Float", 1),
02737               "Check element  2 of sorted \"Float\"... ");
02738 
02739   test_ivalue(0, cpl_table_is_valid(table, "Float", 2),
02740               "Check element  3 of sorted \"Float\"... ");
02741 
02742   test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 3, NULL),
02743               "Check element  4 of sorted \"Float\"... ");
02744 
02745   test_ivalue(0, cpl_table_is_valid(table, "Float", 4),
02746               "Check element  5 of sorted \"Float\"... ");
02747 
02748   test_ivalue(0, cpl_table_is_valid(table, "Float", 5),
02749               "Check element  6 of sorted \"Float\"... ");
02750 
02751   test_ivalue(0, cpl_table_is_valid(table, "Float", 6),
02752               "Check element  7 of sorted \"Float\"... ");
02753 
02754   test_fvalue(-1110.0, 0.00001, 
02755               cpl_table_get_float(table, "Float", 7, NULL),
02756               "Check element  8 of sorted \"Float\"... ");
02757 
02758   test_fvalue(6.66, 0.00001, 
02759               cpl_table_get_float(table, "Float", 8, NULL),
02760               "Check element  9 of sorted \"Float\"... ");
02761 
02762   test_fvalue(-12.33, 0.00001, 
02763               cpl_table_get_float(table, "Float", 9, NULL),
02764               "Check element 10 of sorted \"Float\"... ");
02765 
02766   test_fvalue(-12.22, 0.00001, 
02767               cpl_table_get_float(table, "Float", 10, NULL),
02768               "Check element 11 of sorted \"Float\"... ");
02769 
02770   test_fvalue(-28.44, 0.00001, 
02771               cpl_table_get_float(table, "Float", 11, NULL),
02772               "Check element 12 of sorted \"Float\"... ");
02773 
02774   test_fvalue(0.0, 0.00001, 
02775               cpl_table_get_float(table, "Float", 12, NULL),
02776               "Check element 13 of sorted \"Float\"... ");
02777 
02778   test_fvalue(0.0, 0.00001, 
02779               cpl_table_get_float(table, "Float", 13, NULL),
02780               "Check element 14 of sorted \"Float\"... ");
02781 
02782   test_fvalue(0.0, 0.00001, 
02783               cpl_table_get_float(table, "Float", 14, NULL),
02784               "Check element 15 of sorted \"Float\"... ");
02785 
02786   test_fvalue(-999880.0, 0.00001, 
02787               cpl_table_get_float(table, "Float", 15, NULL),
02788               "Check element 16 of sorted \"Float\"... ");
02789 
02790   test_ivalue(0, cpl_table_is_valid(table, "Float", 16),
02791               "Check element 17 of sorted \"Float\"... ");
02792 
02793   test_fvalue(0.0, 0.00001, 
02794               cpl_table_get_float(table, "Float", 17, NULL),
02795               "Check element 18 of sorted \"Float\"... ");
02796 
02797   names[0] = "Sequence";
02798 
02799   reflist = uves_propertylist_new();
02800   uves_propertylist_append_bool(reflist, names[0], 0);
02801 
02802   test(uves_table_sort(table, reflist), "Undo table sorting... ");
02803 
02804   uves_propertylist_delete(reflist);
02805 
02806   names[0] = "Integer";
02807   reverse[0] = 1;
02808 
02809   reflist = uves_propertylist_new();
02810   uves_propertylist_append_bool(reflist, names[0], 1);
02811 
02812   test(uves_table_sort(table, reflist), 
02813        "Sorting by decreasing values of the \"Integer\" column... ");
02814 
02815 /* %$% */
02816 /*
02817 cpl_table_dump_structure(table, NULL);
02818 cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
02819 */
02820 
02821   uves_propertylist_delete(reflist);
02822 
02823 /*
02824   cpl_table_dump_structure(table, NULL);
02825   cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
02826 
02827   printf("Median of Integer: %d\n", cpl_table_median_int(table, "Integer"));
02828   printf("Median of Float: %f\n", cpl_table_median_float(table, "Float"));
02829   printf("Median of Double: %f\n", cpl_table_median_double(table, "Double"));
02830   printf("Median of Sequence: %d\n", cpl_table_median_int(table, "Sequence"));
02831 */
02832 
02833 /*
02834 
02835 cpl_table_dump_structure(table, NULL);
02836 cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
02837 
02838 */
02839 
02840   test_fvalue(999.000000, 0.001, cpl_table_get_column_median(table, "Integer"),
02841                    "Median of Integer...");
02842   test_fvalue(0.000000, 0.001, cpl_table_get_column_median(table, "Float"),
02843                    "Median of Float...");
02844   test_fvalue(999.880000, 0.001, cpl_table_get_column_median(table, "Double"),
02845                    "Median of Double...");
02846   test_fvalue(8.000000, 0.001, cpl_table_get_column_median(table, "Sequence"),
02847                    "Median of Sequence...");
02848   test_fvalue(546.454545, 0.001, cpl_table_get_column_mean(table, "Integer"),
02849                    "Mean of Integer...");
02850   test_fvalue(-91003.302727, 0.001, cpl_table_get_column_mean(table, "Float"),
02851                    "Mean of Float...");
02852   test_fvalue(626.202500, 0.001, cpl_table_get_column_mean(table, "Double"),
02853                    "Mean of Double...");
02854   test_fvalue(8.500000, 0.001, cpl_table_get_column_mean(table, "Sequence"),
02855                    "Mean of Sequence...");
02856   test_fvalue(519.939489, 0.001, cpl_table_get_column_stdev(table, "Integer"),
02857                    "Stdev of Integer...");
02858   test_fvalue(301440.480937, 0.001, cpl_table_get_column_stdev(table, "Float"),
02859                    "Stdev of Float...");
02860   test_fvalue(498.239830, 0.001, cpl_table_get_column_stdev(table, "Double"),
02861                    "Stdev of Double...");
02862   test_fvalue(5.338539, 0.001, cpl_table_get_column_stdev(table, "Sequence"),
02863                    "Stdev of Sequence...");
02864 
02865 /*
02866 
02867   printf("median of Integer: %f\n", cpl_table_get_column_median(table, "Integer"));
02868   printf("median of Float: %f\n", cpl_table_get_column_median(table, "Float"));
02869   printf("median of Double: %f\n", cpl_table_get_column_median(table, "Double"));
02870   printf("median of Sequence: %f\n", cpl_table_get_column_median(table, "Sequence"));
02871   printf("mean of Integer: %f\n", cpl_table_get_column_mean(table, "Integer"));
02872   printf("mean of Float: %f\n", cpl_table_get_column_mean(table, "Float"));
02873   printf("mean of Double: %f\n", cpl_table_get_column_mean(table, "Double"));
02874   printf("mean of Sequence: %f\n", cpl_table_get_column_mean(table, "Sequence"));
02875   printf("Stdev of Integer: %f\n", cpl_table_get_column_stdev(table, "Integer"));
02876   printf("Stdev of Float: %f\n", cpl_table_get_column_stdev(table, "Float"));
02877   printf("Stdev of Double: %f\n", cpl_table_get_column_stdev(table, "Double"));
02878   printf("Stdev of Sequence: %f\n", cpl_table_get_column_stdev(table, "Sequence"));
02879 */
02880 
02882   cpl_table_fill_invalid_int(table, "Integer", 320);
02883   cpl_table_fill_invalid_int(table, "AInt", 320);
02884   cpl_table_fill_invalid_int(table, "New AInt", 320);
02885   cpl_table_save(table, NULL, NULL, "test_table.tfits", 0);
02886   cpl_table_delete(table);
02887   table = cpl_table_load("test_table.tfits", 1, 1);
02888 
02889 
02890   test_ivalue(18, cpl_table_get_nrow(table),
02891                        "Checking table length after decreasing sorting... ");
02892 
02893   test_ivalue(11, cpl_table_get_ncol(table),
02894                        "Checking table width after decreasing sorting... ");
02895 
02896   test_ivalue(7, cpl_table_count_invalid(table, "Integer"),
02897                      "Count \"Integer\" NULLs after decreasing sorting... ");
02898 
02899   test_ivalue(7, cpl_table_count_invalid(table, "Float"),
02900                      "Count \"Float\" NULLs after decreasing sorting... ");
02901 
02902   test_ivalue(2, cpl_table_count_invalid(table, "Double"),
02903                      "Count \"Double\" NULLs after decreasing sorting... ");
02904 
02905   test_ivalue(2, cpl_table_count_invalid(table, "String"),
02906                      "Count \"String\" NULLs after decreasing sorting... ");
02907 
02908   for (i = 0; i < 7; i++) {
02909     sprintf(message, "Check element  %d of sorted \"Integer\"... ", i + 1);
02910     test_ivalue(0, cpl_table_is_valid(table, "Integer", i), message);
02911   }
02912 
02913   for (i = 7; i < 13; i++) {
02914     sprintf(message, "Check element  %d of sorted \"Integer\"... ", i + 1);
02915     test_ivalue(999, cpl_table_get_int(table, "Integer", i, NULL),
02916                        message);
02917   }
02918 
02919   test_ivalue(7, cpl_table_get_int(table, "Integer", 13, NULL),
02920                      "Check element 13 of sorted \"Integer\"... ");
02921 
02922   test_ivalue(6, cpl_table_get_int(table, "Integer", 14, NULL),
02923                      "Check element 14 of sorted \"Integer\"... ");
02924 
02925   test_ivalue(4, cpl_table_get_int(table, "Integer", 15, NULL),
02926                      "Check element 15 of sorted \"Integer\"... ");
02927 
02928   test_ivalue(1, cpl_table_get_int(table, "Integer", 16, NULL),
02929                      "Check element 16 of sorted \"Integer\"... ");
02930 
02931   test_ivalue(-1, cpl_table_get_int(table, "Integer", 17, NULL),
02932                      "Check element 17 of sorted \"Integer\"... ");
02933 
02934 
02935   test_fvalue(999.88, 0.00001,
02936                      cpl_table_get_double(table, "Double", 0, NULL),
02937                      "Check element  1 of sorted \"Double\"... ");
02938 
02939   test_fvalue(999.88, 0.00001,
02940                      cpl_table_get_double(table, "Double", 1, NULL),
02941                      "Check element  2 of sorted \"Double\"... ");
02942 
02943   test_ivalue(0, cpl_table_is_valid(table, "Double", 2),
02944                      "Check element  3 of sorted \"Double\"... ");
02945 
02946   test_fvalue(999.88, 0.00001,
02947                      cpl_table_get_double(table, "Double", 3, NULL),
02948                      "Check element  4 of sorted \"Double\"... ");
02949 
02950   test_fvalue(3.11, 0.00001,
02951                      cpl_table_get_double(table, "Double", 4, NULL),
02952                      "Check element  5 of sorted \"Double\"... ");
02953 
02954   test_ivalue(0, cpl_table_is_valid(table, "Double", 5),
02955                      "Check element  6 of sorted \"Double\"... ");
02956 
02957   test_fvalue(999.88, 0.00001,
02958                      cpl_table_get_double(table, "Double", 6, NULL),
02959                      "Check element  7 of sorted \"Double\"... ");
02960 
02961   for (i = 7; i < 13; i++) {
02962     sprintf(message, "Check element  %d of sorted \"Double\"... ", i + 1);
02963     test_fvalue(999.88, 0.00001,
02964                 cpl_table_get_double(table, "Double", i, NULL), message);
02965   }
02966 
02967   test_fvalue(7.11, 0.00001,
02968                     cpl_table_get_double(table, "Double", 13, NULL),
02969                     "Check element 14 of sorted \"Double\"... ");
02970 
02971   test_fvalue(6.11, 0.00001,
02972                     cpl_table_get_double(table, "Double", 14, NULL),
02973                     "Check element 15 of sorted \"Double\"... ");
02974 
02975   test_fvalue(4.11, 0.00001,
02976                     cpl_table_get_double(table, "Double", 15, NULL),
02977                     "Check element 16 of sorted \"Double\"... ");
02978 
02979   test_fvalue(1.11, 0.00001,
02980                     cpl_table_get_double(table, "Double", 16, NULL),
02981                     "Check element 17 of sorted \"Double\"... ");
02982 
02983   test_fvalue(-1.11, 0.00001,
02984                      cpl_table_get_double(table, "Double", 17, NULL),
02985                      "Check element 18 of sorted \"Double\"... ");
02986 
02987 
02988   test_svalue("999", cpl_table_get_string(table, "String", 0),
02989               "Check element  1 of sorted \"String\"... ");
02990 
02991   test_svalue("999", cpl_table_get_string(table, "String", 1),
02992               "Check element  2 of sorted \"String\"... ");
02993 
02994   test_ivalue(0, cpl_table_is_valid(table, "String", 2),
02995               "Check element  3 of sorted \"String\"... ");
02996 
02997   test_svalue("999", cpl_table_get_string(table, "String", 3),
02998               "Check element  4 of sorted \"String\"... ");
02999 
03000   test_svalue("baaa", cpl_table_get_string(table, "String", 4),
03001               "Check element  5 of sorted \"String\"... ");
03002 
03003   test_ivalue(0, cpl_table_is_valid(table, "String", 5),
03004               "Check element  6 of sorted \"String\"... ");
03005 
03006   test_svalue("999", cpl_table_get_string(table, "String", 6),
03007               "Check element  7 of sorted \"String\"... ");
03008 
03009   for (i = 7; i < 13; i++) {
03010     sprintf(message, "Check element  %d of sorted \"String\"... ", i + 1);
03011     test_svalue("999", cpl_table_get_string(table, "String", i), message);
03012   }
03013 
03014   test_svalue("aaaa", cpl_table_get_string(table, "String", 13),
03015               "Check element 14 of sorted \"String\"... ");
03016 
03017   test_svalue("daaa", cpl_table_get_string(table, "String", 14),
03018               "Check element 15 of sorted \"String\"... ");
03019 
03020   test_svalue(" sss", cpl_table_get_string(table, "String", 15),
03021               "Check element 16 of sorted \"String\"... ");
03022 
03023   test_svalue("acde", cpl_table_get_string(table, "String", 16),
03024               "Check element 17 of sorted \"String\"... ");
03025 
03026   test_svalue("extra", cpl_table_get_string(table, "String", 17),
03027               "Check element 18 of sorted \"String\"... ");
03028 
03029 
03030   test_ivalue(0, cpl_table_is_valid(table, "Float", 0),
03031               "Check element  1 of sorted \"Float\"... ");
03032 
03033   test_ivalue(0, cpl_table_is_valid(table, "Float", 1),
03034               "Check element  2 of sorted \"Float\"... ");
03035 
03036   test_ivalue(0, cpl_table_is_valid(table, "Float", 2),
03037               "Check element  3 of sorted \"Float\"... ");
03038 
03039   test_fvalue(0.0, 0.00001, cpl_table_get_float(table, "Float", 3, NULL),
03040               "Check element  4 of sorted \"Float\"... ");
03041 
03042   test_ivalue(0, cpl_table_is_valid(table, "Float", 4),
03043               "Check element  5 of sorted \"Float\"... ");
03044 
03045   test_ivalue(0, cpl_table_is_valid(table, "Float", 5),
03046               "Check element  6 of sorted \"Float\"... ");
03047 
03048   test_ivalue(0, cpl_table_is_valid(table, "Float", 6),
03049               "Check element  7 of sorted \"Float\"... ");
03050 
03051   test_fvalue(0.0, 0.00001,
03052               cpl_table_get_float(table, "Float", 7, NULL),
03053               "Check element  8 of sorted \"Float\"... ");
03054 
03055   test_fvalue(0.0, 0.00001,
03056               cpl_table_get_float(table, "Float", 8, NULL),
03057               "Check element  9 of sorted \"Float\"... ");
03058 
03059   test_fvalue(0.0, 0.00001,
03060               cpl_table_get_float(table, "Float", 9, NULL),
03061               "Check element 10 of sorted \"Float\"... ");
03062 
03063   test_fvalue(-999880.0, 0.00001,
03064               cpl_table_get_float(table, "Float", 10, NULL),
03065               "Check element 11 of sorted \"Float\"... ");
03066 
03067   test_ivalue(0, cpl_table_is_valid(table, "Float", 11),
03068               "Check element 12 of sorted \"Float\"... ");
03069 
03070   test_fvalue(0.0, 0.00001,
03071               cpl_table_get_float(table, "Float", 12, NULL),
03072               "Check element 13 of sorted \"Float\"... ");
03073 
03074   test_fvalue(-28.44, 0.00001,
03075               cpl_table_get_float(table, "Float", 13, NULL),
03076               "Check element 14 of sorted \"Float\"... ");
03077 
03078   test_fvalue(-12.22, 0.00001,
03079               cpl_table_get_float(table, "Float", 14, NULL),
03080               "Check element 15 of sorted \"Float\"... ");
03081 
03082   test_fvalue(-12.33, 0.00001,
03083               cpl_table_get_float(table, "Float", 15, NULL),
03084               "Check element 16 of sorted \"Float\"... ");
03085 
03086   test_fvalue(6.66, 0.00001,
03087               cpl_table_get_float(table, "Float", 16, NULL),
03088               "Check element 17 of sorted \"Float\"... ");
03089 
03090   test_fvalue(-1110.0, 0.00001,
03091               cpl_table_get_float(table, "Float", 17, NULL),
03092               "Check element 18 of sorted \"Float\"... ");
03093 
03094   cpl_table_delete(table);
03095   cpl_free(fArray);
03096 
03097   /*
03098    * Powers
03099    */
03100 
03101   nrows = 7;
03102 
03103   table = cpl_table_new(nrows);
03104   cpl_table_new_column(table, "Int", CPL_TYPE_INT);
03105   cpl_table_new_column(table, "Float", CPL_TYPE_FLOAT);
03106   cpl_table_new_column(table, "Double", CPL_TYPE_DOUBLE);
03107 
03108   for (i = 0; i < nrows; i++) {
03109       cpl_table_set_int(table, "Int", i, i);
03110       cpl_table_set_float(table, "Float", i, i);
03111       cpl_table_set_double(table, "Double", i, i);
03112   }
03113 
03114   cpl_table_exponential_column(table, "Int", 2);
03115   cpl_table_exponential_column(table, "Float", 2);
03116   cpl_table_exponential_column(table, "Double", 2);
03117 
03118   pp = 1;
03119   for (i = 0; i < nrows; i++) {
03120       test_ivalue(pp, cpl_table_get_int(table, 
03121                       "Int", i, NULL), "Check expo Int... ");
03122       test_fvalue((float)pp, 0.00001, cpl_table_get_float(table, 
03123                       "Float", i, NULL), "Check expo Float... ");
03124       test_fvalue((float)pp, 0.00001, cpl_table_get_double(table, 
03125                       "Double", i, NULL), "Check expo Double... ");
03126       pp *= 2;
03127   }
03128 
03129   cpl_table_logarithm_column(table, "Int", 2);
03130   cpl_table_logarithm_column(table, "Float", 2);
03131   cpl_table_logarithm_column(table, "Double", 2);
03132 
03133   for (i = 0; i < nrows; i++) {
03134       test_ivalue(i, cpl_table_get_int(table, 
03135                      "Int", i, NULL), "Check log Int... ");
03136       test_fvalue((float)i, 0.00001, cpl_table_get_float(table, 
03137                      "Float", i, NULL), "Check log Float... ");
03138       test_fvalue((float)i, 0.00001, cpl_table_get_double(table, 
03139                      "Double", i, NULL), "Check log Double... ");
03140   }
03141 
03142   cpl_table_power_column(table, "Int", 2);
03143   cpl_table_power_column(table, "Float", 2);
03144   cpl_table_power_column(table, "Double", 2);
03145 
03146   for (i = 0; i < nrows; i++) {
03147       test_ivalue(i*i, cpl_table_get_int(table,
03148                      "Int", i, NULL), "Check pow Int... ");
03149       test_fvalue((float)i*i, 0.00001, cpl_table_get_float(table,
03150                      "Float", i, NULL), "Check pow Float... ");
03151       test_fvalue((float)i*i, 0.00001, cpl_table_get_double(table,
03152                      "Double", i, NULL), "Check pow Double... ");
03153   }
03154 
03155   cpl_table_power_column(table, "Int", 0.5);
03156   cpl_table_power_column(table, "Float", 0.5); 
03157   cpl_table_power_column(table, "Double", 0.5); 
03158 
03159   for (i = 0; i < nrows; i++) {
03160       test_ivalue(i, cpl_table_get_int(table,
03161                      "Int", i, NULL), "Check sqrt Int... ");
03162       test_fvalue((float)i, 0.00001, cpl_table_get_float(table,
03163                      "Float", i, NULL), "Check sqrt Float... ");
03164       test_fvalue((float)i, 0.00001, cpl_table_get_double(table,
03165                      "Double", i, NULL), "Check sqrt Double... ");
03166   }
03167 
03168   cpl_table_delete(table);
03169 
03170 
03171   /*
03172    * Testing the selection functions
03173    */
03174 
03175   nrows = 7;
03176 
03177   table = cpl_table_new(nrows);
03178   cpl_table_new_column(table, "Int", CPL_TYPE_INT);
03179   cpl_table_new_column(table, "String", CPL_TYPE_STRING);
03180 
03181   unit = "abcd\0efgh\0ijkl\0mnop\0qrst\0uvwx\0yz";
03182 
03183   for (i = 0; i < nrows; i++) {
03184        cpl_table_set_int(table, "Int", i, i);
03185        cpl_table_set_string(table, "String", i, unit + i*5);
03186   }
03187 
03188   cpl_table_duplicate_column(table, "Int2", table, "Int");
03189   cpl_table_multiply_columns(table, "Int2", "Int2");
03190   cpl_table_cast_column(table, "Int", "Float", CPL_TYPE_FLOAT);
03191 
03192 #ifdef VERBOSE
03193 
03194   printf("\nThis is the test table:\n\n");
03195   cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
03196 
03197   printf("\nNow erase all selected:\n\n");
03198 
03199 #endif
03200 
03201   copia = cpl_table_duplicate(table);
03202   test_ivalue(7, cpl_table_count_selected(copia), "Check all selected... ");
03203   uves_table_erase_selected_dfs02356(copia);
03204 #ifdef VERBOSE
03205   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03206 #endif
03207   test_ivalue(0, cpl_table_get_nrow(copia), 
03208               "Check length erase all selected... ");
03209   cpl_table_delete(copia);
03210 
03211 #ifdef VERBOSE
03212 
03213   printf("\nThis is the test table:\n\n");
03214   cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
03215 
03216   printf("\nNow delete all Int >= Int2:\n\n");
03217 
03218 #endif
03219 
03220   copia = cpl_table_duplicate(table);
03221   cpl_table_and_selected(copia, "Int", CPL_NOT_LESS_THAN, "Int2");
03222   test_ivalue(2, cpl_table_count_selected(copia), 
03223               "Check Int >= Int2 selected... ");
03224   uves_table_erase_selected_dfs02356(copia);
03225 #ifdef VERBOSE
03226   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03227 #endif
03228   test_ivalue(5, cpl_table_get_nrow(copia), 
03229               "Check length erase all Int >= Int2... ");
03230   cpl_table_delete(copia);
03231 
03232 #ifdef VERBOSE
03233 
03234   printf("\nThis is the test table:\n\n");
03235   cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
03236 
03237   printf("\nNow delete all Int > 3:\n\n");
03238 
03239 #endif
03240 
03241   copia = cpl_table_duplicate(table);
03242   cpl_table_and_selected_int(copia, "Int", CPL_GREATER_THAN, 3);
03243   test_ivalue(3, cpl_table_count_selected(copia), 
03244               "Check Int > 3 selected... ");
03245   uves_table_erase_selected_dfs02356(copia);
03246 #ifdef VERBOSE
03247   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03248 #endif
03249   test_ivalue(4, cpl_table_get_nrow(copia), 
03250               "Check length erase all Int > 3... ");
03251   cpl_table_delete(copia);
03252 
03253 #ifdef VERBOSE
03254 
03255   printf("\nThis is the test table:\n\n");
03256   cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
03257 
03258   printf("\nNow delete all Int2 > Float:\n\n");
03259 
03260 #endif
03261 
03262   copia = cpl_table_duplicate(table);
03263   cpl_table_and_selected(copia, "Int2", CPL_GREATER_THAN, "Float");
03264   test_ivalue(5, cpl_table_count_selected(copia), 
03265               "Check Int2 > Float selected... ");
03266   uves_table_erase_selected_dfs02356(copia);
03267 #ifdef VERBOSE
03268   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03269 #endif
03270   test_ivalue(2, cpl_table_get_nrow(copia), 
03271               "Check length erase all Int2 > Float... ");
03272   cpl_table_delete(copia);
03273 
03274 #ifdef VERBOSE
03275 
03276   printf("\nThis is the test table:\n\n");
03277   cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
03278 
03279   printf("\nNow delete all String == \"^[a-l].*\":\n\n");
03280 
03281 #endif
03282 
03283   copia = cpl_table_duplicate(table);
03284   cpl_table_and_selected_string(copia, "String", CPL_EQUAL_TO, "^[a-l].*");
03285   test_ivalue(3, cpl_table_count_selected(copia), 
03286               "Check String == \"^[a-l].*\" selected... ");
03287   uves_table_erase_selected_dfs02356(copia);
03288 #ifdef VERBOSE
03289   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03290 #endif
03291   test_ivalue(4, cpl_table_get_nrow(copia), 
03292               "Check length erase all String == \"^[a-l].*\"... ");
03293   cpl_table_delete(copia);
03294 
03295 #ifdef VERBOSE
03296 
03297   printf("\nThis is the test table:\n\n");
03298   cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
03299 
03300   printf("\nNow delete all String > \"carlo\":\n\n");
03301 
03302 #endif
03303 
03304   copia = cpl_table_duplicate(table);
03305   cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "carlo");
03306   test_ivalue(6, cpl_table_count_selected(copia), 
03307               "Check String > \"carlo\" selected... ");
03308   uves_table_erase_selected_dfs02356(copia);
03309 #ifdef VERBOSE
03310   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03311 #endif
03312   test_ivalue(1, cpl_table_get_nrow(copia), 
03313               "Check length erase all String > \"carlo\"... ");
03314   cpl_table_delete(copia);
03315 
03316 #ifdef VERBOSE
03317 
03318   printf("\nThis is the test table:\n\n");
03319   cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
03320 
03321   printf("\nNow delete all String > \"tattoo\" and Int == 3:\n\n");
03322 
03323 #endif
03324 
03325   copia = cpl_table_duplicate(table);
03326   cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "tattoo");
03327   cpl_table_or_selected_int(copia, "Int", CPL_EQUAL_TO, 3);
03328   test_ivalue(3, cpl_table_count_selected(copia), 
03329               "Check String > \"tattoo\" and Int == 3 selected... ");
03330   uves_table_erase_selected_dfs02356(copia);
03331 #ifdef VERBOSE
03332   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03333 #endif
03334   test_ivalue(4, cpl_table_get_nrow(copia),
03335               "Check length erase all String > \"tattoo\" and Int == 3... ");
03336   cpl_table_delete(copia);
03337 
03338 #ifdef VERBOSE
03339 
03340   printf("\nNow keep all String > \"tattoo\" and Int == 3:\n\n");
03341 
03342 #endif
03343 
03344   copia = cpl_table_duplicate(table);
03345   cpl_table_and_selected_string(copia, "String", CPL_GREATER_THAN, "tattoo");
03346   cpl_table_or_selected_int(copia, "Int", CPL_EQUAL_TO, 3);
03347   cpl_table_not_selected(copia);
03348   test_ivalue(4, cpl_table_count_selected(copia), 
03349               "Check String > \"tattoo\" and Int == 3 rejected... ");
03350   uves_table_erase_selected_dfs02356(copia);
03351 #ifdef VERBOSE
03352   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03353 #endif
03354   test_ivalue(3, cpl_table_get_nrow(copia),
03355               "Check length keep all String > \"tattoo\" and Int == 3... ");
03356   cpl_table_delete(copia);
03357 
03358 #ifdef VERBOSE
03359 
03360   printf("\nThis is the test table:\n\n");
03361   cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
03362 
03363   printf("\nNow delete rows 0, 2, and 6:\n\n");
03364 
03365 #endif
03366 
03367   copia = cpl_table_duplicate(table);
03368   cpl_table_unselect_all(copia);
03369   cpl_table_select_row(copia, 0);
03370   cpl_table_select_row(copia, 2);
03371   cpl_table_select_row(copia, 6);
03372   test_ivalue(3, cpl_table_count_selected(copia), 
03373               "Check rows 0, 2, and 6 selected... ");
03374   uves_table_erase_selected_dfs02356(copia);
03375 #ifdef VERBOSE
03376   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03377 #endif
03378   test_ivalue(4, cpl_table_get_nrow(copia),
03379               "Check length erase rows 0, 2, and 6... ");
03380   cpl_table_delete(copia);
03381 
03382 #ifdef VERBOSE
03383 
03384   printf("\nNow keep rows 0, 2, and 6:\n\n");
03385 
03386 #endif
03387 
03388   copia = cpl_table_duplicate(table);
03389   cpl_table_unselect_row(copia, 0);
03390   cpl_table_unselect_row(copia, 2);
03391   cpl_table_unselect_row(copia, 6);
03392   test_ivalue(4, cpl_table_count_selected(copia), 
03393               "Check rows 0, 2, and 6 rejected... ");
03394   uves_table_erase_selected_dfs02356(copia);
03395 #ifdef VERBOSE
03396   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03397 #endif
03398   test_ivalue(3, cpl_table_get_nrow(copia),
03399               "Check length erase rows 0, 2, and 6... ");
03400   cpl_table_delete(copia);
03401 
03402 #ifdef VERBOSE
03403 
03404   printf("\nThis is the test table:\n\n");
03405   cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
03406 
03407   printf("\nNow delete first 3 rows:\n\n");
03408 
03409 #endif
03410 
03411   copia = cpl_table_duplicate(table);
03412   cpl_table_and_selected_window(copia, 0, 3);
03413   test_ivalue(3, cpl_table_count_selected(copia), 
03414               "Check first 3 rows selected... ");
03415   uves_table_erase_selected_dfs02356(copia);
03416 #ifdef VERBOSE
03417   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03418 #endif
03419   test_ivalue(4, cpl_table_get_nrow(copia),
03420               "Check length erase first 3 rows... ");
03421   cpl_table_delete(copia);
03422 
03423 #ifdef VERBOSE
03424 
03425   printf("\nNow delete last 2 rows:\n\n");
03426 
03427 #endif
03428 
03429   copia = cpl_table_duplicate(table);
03430   cpl_table_and_selected_window(copia, 5, 2);
03431   test_ivalue(2, cpl_table_count_selected(copia), 
03432               "Check last 2 rows selected... ");
03433   uves_table_erase_selected_dfs02356(copia);
03434 #ifdef VERBOSE
03435   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03436 #endif
03437   test_ivalue(5, cpl_table_get_nrow(copia),
03438               "Check length erase last 2 rows... ");
03439   cpl_table_delete(copia);
03440 
03441 #ifdef VERBOSE
03442 
03443   printf("\nNow delete rows from 2 to 3:\n\n");
03444 
03445 #endif
03446 
03447   copia = cpl_table_duplicate(table);
03448   cpl_table_and_selected_window(copia, 2, 2);
03449   test_ivalue(2, cpl_table_count_selected(copia), 
03450               "Check middle 2 rows selected... ");
03451   uves_table_erase_selected_dfs02356(copia);
03452 #ifdef VERBOSE
03453   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03454 #endif
03455   test_ivalue(5, cpl_table_get_nrow(copia),
03456               "Check length erase rows from 2 to 3... ");
03457   cpl_table_delete(copia);
03458 
03459 #ifdef VERBOSE
03460 
03461   printf("\nNow delete rows from 1 to 3 and row 6:\n\n");
03462 
03463 #endif
03464 
03465   copia = cpl_table_duplicate(table);
03466   cpl_table_and_selected_window(copia, 1, 3);
03467   cpl_table_or_selected_window(copia, 6, 1);
03468   test_ivalue(4, cpl_table_count_selected(copia), 
03469               "Check rows 1 to 3 and row 6 rejected... ");
03470   uves_table_erase_selected_dfs02356(copia);
03471 #ifdef VERBOSE
03472   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03473 #endif
03474   test_ivalue(3, cpl_table_get_nrow(copia),
03475               "Check length erase rows from 1 to 3 and row 6... ");
03476   cpl_table_delete(copia);
03477 
03478   /* Erase only invalid elements */
03479   copia = cpl_table_duplicate(table);
03480   for (i = 0; i < nrows; i++) {
03481       cpl_table_set_invalid(copia, "Int", i);
03482   }
03483 
03484   cpl_table_unselect_row(copia, nrows-1);
03485 
03486   uves_table_erase_selected_dfs02356(copia);
03487 #ifdef VERBOSE
03488   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03489 #endif
03490   test_ivalue(1, cpl_table_get_nrow(copia),
03491               "Check length erase last row, only invalid values... ");
03492   cpl_table_delete(copia);
03493 
03494   /* Erase array column with valid/invalid values */
03495   copia = cpl_table_duplicate(table);
03496 
03497   cpl_table_cast_column(copia, "Int", "Double", CPL_TYPE_DOUBLE);
03498 
03499   test(cpl_table_new_column_array(copia, "ADouble", 
03500                                   CPL_TYPE_DOUBLE | CPL_TYPE_POINTER, 2),
03501                                   "Creating the ArrayDouble column... ");
03502 
03503   array = cpl_array_new(2, CPL_TYPE_DOUBLE);
03504   test(cpl_table_set_array(copia, "ADouble", 1, array),
03505        "Set a valid array to ADouble 1... ");
03506   test(cpl_table_set_array(copia, "ADouble", 2, array),
03507        "Set a valid array to ADouble 2... ");
03508   cpl_array_delete(array);
03509 
03510   cpl_table_unselect_row(copia, 0);
03511   cpl_table_unselect_row(copia, 2);
03512   cpl_table_set_invalid(copia, "Int", 6);
03513   cpl_table_set_invalid(copia, "Int2", 0);
03514   cpl_table_set_invalid(copia, "Int2", 1);
03515   cpl_table_set_invalid(copia, "Double", 0);
03516   cpl_table_set_invalid(copia, "Double", 1);
03517 
03518   uves_table_erase_selected_dfs02356(copia);
03519 #ifdef VERBOSE
03520   cpl_table_dump(copia, 0, cpl_table_get_nrow(copia), NULL);
03521 #endif
03522   test_ivalue(2, cpl_table_get_nrow(copia),
03523               "Check length erase valid/invalid values... ");
03524   test_ivalue(0, cpl_table_is_valid(copia, "Int2", 0), 
03525                     "Check that first element of \"Int2\" is still NULL... ");
03526   test_ivalue(1, cpl_table_is_valid(copia, "Int2", 1), 
03527                     "Check that first element of \"Int2\" is now valid... ");
03528 
03529   cpl_table_unselect_row(copia, 0);
03530   cpl_table_unselect_row(copia, 1);
03531   uves_table_erase_selected_dfs02356(copia);
03532   test_ivalue(2, cpl_table_count_selected(copia),
03533               "Check that rows are selected... ");
03534 
03535   cpl_table_delete(copia);
03536 
03537   cpl_table_delete(table);
03538 
03539 
03540 
03541   table = cpl_table_new(4);
03542   cpl_table_new_column(table, "S", CPL_TYPE_STRING);
03543   cpl_table_new_column(table, "D", CPL_TYPE_DOUBLE);
03544 
03545   cpl_table_set_double(table, "D", 0, 43.04);
03546   cpl_table_set_double(table, "D", 1, 43.04);
03547   cpl_table_set_double(table, "D", 2, 43.04);
03548   cpl_table_set_double(table, "D", 3, 43.04);
03549   cpl_table_set_invalid(table, "D", 3);
03550 
03551   cpl_table_set_string(table, "S", 0, "type");
03552   cpl_table_set_string(table, "S", 1, "type");
03553   cpl_table_set_string(table, "S", 2, "type");
03554   cpl_table_set_string(table, "S", 3, "type");
03555   cpl_table_set_invalid(table, "S", 1);
03556 
03557 #ifdef VERBOSE
03558   cpl_table_dump(table, 0, 4, stdout);
03559 #endif
03560 
03561   cpl_table_select_all(table);
03562   test_ivalue(4, cpl_table_count_selected(table), "A...");
03563   cpl_table_and_selected_invalid(table, "D");
03564   test_ivalue(1, cpl_table_count_selected(table), "B...");
03565 
03566   cpl_table_select_all(table);
03567   test_ivalue(4, cpl_table_count_selected(table), "C...");
03568 
03569 //fails:  cpl_table_and_selected_invalid(table, "S");
03570   uves_table_and_selected_invalid(table, "S");
03571 
03572   test_ivalue(1, cpl_table_count_selected(table), "D...");
03573 
03574   cpl_table_delete(table);
03575 
03576 
03577   /*
03578    * Test case: dividing a double column by integer
03579    */
03580 
03581   nrows = 100;
03582 
03583   table = cpl_table_new(nrows);
03584   cpl_table_new_column(table, "Int", CPL_TYPE_INT);
03585 
03586   for (i = 0; i < nrows; i++)
03587        cpl_table_set_int(table, "Int", i, i + 1);
03588 
03589   cpl_table_cast_column(table, "Int", "Double", CPL_TYPE_DOUBLE);
03590 
03591   test(cpl_table_divide_columns(table, "Double", "Int"), 
03592                      "Divide double column with integer column... ");
03593 
03594   for (i = 0; i < nrows; i++) {
03595     sprintf(message, "Check element %d of result column... ", i);
03596     test_fvalue(1.0, 0.00001, cpl_table_get_double(table, "Double", i, NULL), 
03597                 message);
03598   }
03599 
03600 #ifdef VERBOSE
03601   cpl_table_dump(table, 0, cpl_table_get_nrow(table), NULL);
03602 #endif
03603 
03604   cpl_table_delete(table);
03605 
03606 /*
03607   table = cpl_table_load("/home/cizzo/qfits/qfits/test/asciitable.tfits", 1, 1);
03608   table = cpl_table_load("/home/cizzo/qfits/qfits/test/bintable.tfits", 1, 1);
03609 
03610   names[0] = "IDENT";
03611   names[1] = "Mag";
03612   reverse[0] = 0;
03613   reverse[1] = 1;
03614   uves_table_sort(table, names, 2, reverse);
03615  
03616   cpl_table_dump_structure(table);
03617   cpl_table_dump(table, 0, cpl_table_get_nrow(table));
03618 */
03619 
03620   return cpl_error_get_code();
03621 
03622 }
03623 
03624 
03625 
03626 /*----------------------------------------------------------------------------*/
03630 /*----------------------------------------------------------------------------*/
03631 
03632 int main(void)
03633 {
03634     IRPLIB_TEST_INIT;
03635 
03636     irplib_test_eq(0, table_erase_selected());
03637     uves_find_property_test();
03638     uves_average_reject_test();
03639     uves_polynomial_fit_2d_test();
03640 
03641     IRPLIB_TEST_END;
03642 }
03643 

Generated on Thu Nov 15 14:32:31 2007 for UVES Pipeline Reference Manual by  doxygen 1.5.1