sinfo_utils_wrappers.c

00001 
00002 /*                                                                           *
00003  *   This file is part of the ESO SINFO Pipeline                             *
00004  *   Copyright (C) 2004,2005 European Southern Observatory                   *
00005  *                                                                           *
00006  *   This library is free software; you can redistribute it and/or modify    *
00007  *   it under the terms of the GNU General Public License as published by    *
00008  *   the Free Software Foundation; either version 2 of the License, or       *
00009  *   (at your option) any later version.                                     *
00010  *                                                                           *
00011  *   This program is distributed in the hope that it will be useful,         *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
00014  *   GNU General Public License for more details.                            *
00015  *                                                                           *
00016  *   You should have received a copy of the GNU General Public License       *
00017  *   along with this program; if not, write to the Free Software             *
00018  *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA    *
00019  *                                                                           */
00020 
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #  include <config.h>
00024 #endif
00025 
00026 /*---------------------------------------------------------------------------*/
00034 /*--------------------------------------------------------------------------*/
00035 
00038 #include <sinfo_utils_wrappers.h>
00039 #include <sinfo_functions.h>
00040 #include <sinfo_dump.h>
00041 #include <sinfo_utils.h>
00042 #include <sinfo_error.h>
00043 #include "sinfo_msg.h"
00044 /*---------------------------------------------------------------------------*/
00045 
00046 /*---------------------------------------------------------------------------*/
00058 /*---------------------------------------------------------------------------*/
00059 cpl_error_code
00060 sinfo_sort_table_1(cpl_table *t, const char *column, cpl_boolean reverse)
00061 {
00062     cpl_propertylist *plist = NULL;
00063     
00064     assure(t != NULL, CPL_ERROR_NULL_INPUT, "Null table");
00065     assure(cpl_table_has_column(t, column), CPL_ERROR_ILLEGAL_INPUT, 
00066        "No column '%s'", column);
00067 
00068     check(( plist = cpl_propertylist_new(),
00069         cpl_propertylist_append_bool(plist, column, reverse)),
00070        "Could not create property list for sorting");
00071 
00072     check( cpl_table_sort(t, plist), "Could not sort table");
00073 
00074   cleanup:
00075     sinfo_free_propertylist(&plist);
00076     return cpl_error_get_code();
00077 }
00078 
00079 /*---------------------------------------------------------------------------*/
00095 /*---------------------------------------------------------------------------*/
00096 cpl_error_code
00097 sinfo_sort_table_2(cpl_table *t, const char *column1, const char *column2, 
00098           cpl_boolean reverse1, cpl_boolean reverse2)
00099 {
00100     cpl_propertylist *plist = NULL;
00101     
00102     assure(t != NULL, CPL_ERROR_NULL_INPUT, "Null table");
00103     assure(cpl_table_has_column(t, column1), CPL_ERROR_ILLEGAL_INPUT, 
00104        "No column '%s'", column1);
00105     assure(cpl_table_has_column(t, column2), CPL_ERROR_ILLEGAL_INPUT,
00106        "No column '%s'", column2);
00107 
00108     check(( plist = cpl_propertylist_new(),
00109         cpl_propertylist_append_bool(plist, column1, reverse1),
00110         cpl_propertylist_append_bool(plist, column2, reverse2)),
00111        "Could not create property list for sorting");
00112     check( cpl_table_sort(t, plist), "Could not sort table");
00113     
00114   cleanup:
00115     sinfo_free_propertylist(&plist);
00116     return cpl_error_get_code();
00117 }
00118 
00119 /*---------------------------------------------------------------------------*/
00136 /*---------------------------------------------------------------------------*/
00137 cpl_table *
00138 sinfo_extract_table_rows(const cpl_table *t, const char *column,
00139             cpl_table_select_operator operator, double value)
00140 {
00141     cpl_table *result = NULL;
00142     assure( t != NULL, CPL_ERROR_NULL_INPUT, "Null table");
00143     assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT,
00144         "No such column: %s", column);
00145     
00146     /* 1. Extract (duplicate) the entire table
00147        2. remove rows *not* satisfying the criterion */
00148 
00149     check(result = cpl_table_duplicate(t),"selecting");
00150     check(sinfo_select_table_rows(result, column, operator, value),"select");
00151     check(cpl_table_not_selected(result),"Inverses selection");
00152     check(cpl_table_erase_selected(result),"erase selection");//problems
00153 
00154     /*
00155     check(( result = cpl_table_duplicate(t),
00156         sinfo_select_table_rows(result, column, operator, value),
00157         cpl_table_not_selected(result),  // Inverses selection 
00158         cpl_table_erase_selected(result)),
00159        "Error extracting rows");
00160     */
00161     
00162   cleanup:
00163     if (cpl_error_get_code() != CPL_ERROR_NONE)
00164     {
00165         sinfo_free_table(&result);
00166     }
00167     return result;
00168 }
00169 
00170 
00171 /*---------------------------------------------------------------------------*/
00188 /*---------------------------------------------------------------------------*/
00189 
00190 int
00191 sinfo_select_table_rows(cpl_table *t,  const char *column, 
00192                cpl_table_select_operator operator, double value)
00193 {
00194     int result = 0;
00195     cpl_type type;
00196     assure( t != NULL, CPL_ERROR_NULL_INPUT, "Null table");
00197     assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT, 
00198         "No such column: %s", column);
00199 
00200     type = cpl_table_get_column_type(t, column);
00201 
00202     assure( type == CPL_TYPE_DOUBLE ||
00203         type == CPL_TYPE_INT, CPL_ERROR_INVALID_TYPE,
00204         "Column '%s' must be double or int. %s found", column, 
00205         sinfo_tostring_cpl_type(type));
00206 
00207     check( cpl_table_select_all(t), "Error selecting rows");
00208     
00209     if      (type == CPL_TYPE_DOUBLE)
00210     {
00211         result = cpl_table_and_selected_double(t, column, operator, value);
00212     }
00213     else if (type == CPL_TYPE_INT)
00214     {
00215         result = cpl_table_and_selected_int   (t, column, operator, 
00216                              sinfo_round_double(value));
00217     }
00218     else { /*impossible*/ passure(CPL_FALSE, ""); }
00219     
00220   cleanup:
00221     return result;
00222 
00223 }
00224 
00229 /*---------------------------------------------------------------------------*/
00230 void sinfo_free_parameter(cpl_parameter **p) 
00231 {if(p){cpl_parameter_delete(*p);            *p = NULL;}}
00232 
00233 
00234 
00239 /*---------------------------------------------------------------------------*/
00240 void sinfo_free_apertures(cpl_apertures **a) 
00241 {if(a){cpl_apertures_delete(*a);            *a = NULL;}}
00242 /*---------------------------------------------------------------------------*/
00243 
00244 /*---------------------------------------------------------------------------*/
00249 /*---------------------------------------------------------------------------*/
00250 void sinfo_free_image(cpl_image **i)  {if(i){cpl_image_delete(*i); *i = NULL;}}
00251 
00252 
00253 /*---------------------------------------------------------------------------*/
00258 /*---------------------------------------------------------------------------*/
00259 void sinfoni_free_vector(cpl_vector **v)  {if(v){cpl_vector_delete(*v); *v = NULL;}}
00260 
00261 
00262 /*---------------------------------------------------------------------------*/
00267 /*---------------------------------------------------------------------------*/
00268 void sinfo_free_array(cpl_array **i)  {if(i){cpl_array_delete(*i); *i = NULL;}}
00269 
00270 /*---------------------------------------------------------------------------*/
00275 /*---------------------------------------------------------------------------*/
00276 void sinfo_free_mask(cpl_mask **m)  {if(m){cpl_mask_delete(*m); *m = NULL;}}
00277 /*---------------------------------------------------------------------------*/
00282 /*---------------------------------------------------------------------------*/
00283 void sinfo_free_imagelist(cpl_imagelist **i) 
00284 {if(i){cpl_imagelist_delete(*i);        *i = NULL;}}
00285 /*---------------------------------------------------------------------------*/
00290 /*---------------------------------------------------------------------------*/
00291 void sinfo_free_table(cpl_table **t) {if(t){cpl_table_delete(*t); *t = NULL;}}
00292 /*---------------------------------------------------------------------------*/
00297 /*---------------------------------------------------------------------------*/
00298 void sinfo_free_propertylist(cpl_propertylist **p)   
00299 {if(p){cpl_propertylist_delete(*p);     *p = NULL;}}
00300 /*---------------------------------------------------------------------------*/
00305 /*---------------------------------------------------------------------------*/
00306 void sinfo_free_polynomial(cpl_polynomial **p)       
00307 {if(p){cpl_polynomial_delete(*p);       *p = NULL;}}
00308 /*---------------------------------------------------------------------------*/
00313 /*---------------------------------------------------------------------------*/
00314 /* similar also present in svd.c */
00315 void sinfoni_free_matrix(cpl_matrix **m) 
00316 {if(m){cpl_matrix_delete(*m); *m = NULL;}}
00317 
00318 /*---------------------------------------------------------------------------*/
00323 /*---------------------------------------------------------------------------*/
00324 void sinfo_free_parameterlist(cpl_parameterlist **p) 
00325 {if(p){cpl_parameterlist_delete(*p);    *p = NULL;}}
00326 /*----------------------------------------------------------------------------*/
00331 /*---------------------------------------------------------------------------*/
00332 void sinfo_free_frameset(cpl_frameset **f) 
00333 {if(f){cpl_frameset_delete(*f);    *f = NULL;}}
00334 
00335 
00336 /*---------------------------------------------------------------------------*/
00341 /*---------------------------------------------------------------------------*/
00342 void sinfo_free_frame(cpl_frame **f) 
00343 {if(f){cpl_frame_delete(*f);    *f = NULL;}}
00344 
00345 
00346 /*---------------------------------------------------------------------------*/
00351 /*---------------------------------------------------------------------------*/
00352 void sinfo_free_int(int **i) {if(i){cpl_free(*i);    *i = NULL;}}
00353 
00354 
00355 /*---------------------------------------------------------------------------*/
00360 /*---------------------------------------------------------------------------*/
00361 void sinfo_free_float(float **f) {if(f){cpl_free(*f);    *f = NULL;}}
00362 
00363 
00364 
00365 /*---------------------------------------------------------------------------*/
00370 /*---------------------------------------------------------------------------*/
00371 void sinfo_free_double(double **d) {if(d){cpl_free(*d);    *d = NULL;}}
00372 
00373 
00374 /*---------------------------------------------------------------------------*/
00379 /*---------------------------------------------------------------------------*/
00380 void sinfo_free_array_imagelist(cpl_imagelist ***a) 
00381 {if(*a){cpl_free(*a); *a = NULL;}}
00382 
00383 /*---------------------------------------------------------------------------*/
00388 /*---------------------------------------------------------------------------*/
00389 void sinfo_free_array_image(cpl_image ***a) {if(*a){cpl_free(*a); *a = NULL;}}
00390 
00391 
00392 /*---------------------------------------------------------------------------*/
00398 /*---------------------------------------------------------------------------*/
00399 void sinfo_free_image_array(cpl_image ***a, const int n) 
00400 {
00401   int i=0;
00402   if((*a) != NULL) {
00403     for (i=0; i < n; i++) {
00404       if((*a)[i] != NULL) {
00405     sinfo_free_image(&(*a)[i]);
00406     (*a)[i]=NULL;
00407       }
00408     }
00409     sinfo_free_array_image(&(*a));
00410     *a=NULL;
00411   }
00412 }
00413 
00414 /*---------------------------------------------------------------------------*/
00420 /*---------------------------------------------------------------------------*/
00421 void sinfo_free_float_array(float ***a, const int n) 
00422 {
00423   int i=0;
00424   if((*a) != NULL) {
00425     for (i=0; i < n; i++) {
00426       if((*a)[i] != NULL) {
00427     sinfo_free_float(&(*a)[i]);
00428     (*a)[i]=NULL;
00429       }
00430     }
00431     cpl_free(*a);
00432     *a=NULL;
00433   }
00434 }
00435 
00436 /*---------------------------------------------------------------------------*/
00441 /*---------------------------------------------------------------------------*/
00442 
00443 void 
00444 sinfo_free_my_vector(cpl_vector **v) {if(v){cpl_vector_delete(*v);*v = NULL;}}
00445 
00446 
00447 /*---------------------------------------------------------------------------*/
00452 /*---------------------------------------------------------------------------*/
00453 
00454 void 
00455 sinfo_free_bivector(cpl_bivector **bv) {
00456   if(bv){
00457      cpl_bivector_delete(*bv);
00458      *bv = NULL;
00459   }
00460 }
00461 
00462 /*---------------------------------------------------------------------------*/
00467 /*---------------------------------------------------------------------------*/
00468 void sinfo_free_stats(cpl_stats **s) {if(s){cpl_stats_delete(*s); *s = NULL;}}
00469 /*---------------------------------------------------------------------------*/
00474 /*---------------------------------------------------------------------------*/
00475 void 
00476 sinfo_unwrap_vector(cpl_vector **v) {if(v){cpl_vector_unwrap(*v); *v = NULL;}}
00477 
00478 /*---------------------------------------------------------------------------*/
00483 /*---------------------------------------------------------------------------*/
00484 void sinfo_unwrap_matrix(cpl_matrix **m) 
00485 {if(m){cpl_matrix_unwrap(*m); *m = NULL;}}
00486 
00487 /*---------------------------------------------------------------------------*/
00492 /*---------------------------------------------------------------------------*/
00493 void sinfo_unwrap_bivector_vectors(cpl_bivector **b) 
00494 {if(b){cpl_bivector_unwrap_vectors(*b); *b = NULL;}}
00495 

Generated on 8 Mar 2011 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1