00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00147
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");
00153
00154
00155
00156
00157
00158
00159
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 { 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 sinfo_free_array(cpl_array **i) {if(i){cpl_array_delete(*i); *i = NULL;}}
00260
00261
00266
00267 void sinfo_free_mask(cpl_mask **m) {if(m){cpl_mask_delete(*m); *m = NULL;}}
00268
00273
00274 void sinfo_free_imagelist(cpl_imagelist **i)
00275 {if(i){cpl_imagelist_delete(*i); *i = NULL;}}
00276
00281
00282 void sinfo_free_table(cpl_table **t) {if(t){cpl_table_delete(*t); *t = NULL;}}
00283
00288
00289 void sinfo_free_propertylist(cpl_propertylist **p)
00290 {if(p){cpl_propertylist_delete(*p); *p = NULL;}}
00291
00296
00297 void sinfo_free_polynomial(cpl_polynomial **p)
00298 {if(p){cpl_polynomial_delete(*p); *p = NULL;}}
00299
00304
00305
00306 void sinfoni_free_matrix(cpl_matrix **m)
00307 {if(m){cpl_matrix_delete(*m); *m = NULL;}}
00308
00309
00314
00315 void sinfo_free_parameterlist(cpl_parameterlist **p)
00316 {if(p){cpl_parameterlist_delete(*p); *p = NULL;}}
00317
00322
00323 void sinfo_free_frameset(cpl_frameset **f)
00324 {if(f){cpl_frameset_delete(*f); *f = NULL;}}
00325
00326
00327
00332
00333 void sinfo_free_frame(cpl_frame **f)
00334 {if(f){cpl_frame_delete(*f); *f = NULL;}}
00335
00336
00337
00342
00343 void sinfo_free_int(int **i) {if(i){cpl_free(*i); *i = NULL;}}
00344
00345
00346
00351
00352 void sinfo_free_float(float **f) {if(f){cpl_free(*f); *f = NULL;}}
00353
00354
00355
00356
00361
00362 void sinfo_free_double(double **d) {if(d){cpl_free(*d); *d = NULL;}}
00363
00364
00365
00370
00371 void sinfo_free_array_imagelist(cpl_imagelist ***a)
00372 {if(*a){cpl_free(*a); *a = NULL;}}
00373
00374
00379
00380 void sinfo_free_array_image(cpl_image ***a) {if(*a){cpl_free(*a); *a = NULL;}}
00381
00382
00383
00389
00390 void sinfo_free_image_array(cpl_image ***a, const int n)
00391 {
00392 int i=0;
00393 if((*a) != NULL) {
00394 for (i=0; i < n; i++) {
00395 if((*a)[i] != NULL) {
00396 sinfo_free_image(&(*a)[i]);
00397 (*a)[i]=NULL;
00398 }
00399 }
00400 sinfo_free_array_image(&(*a));
00401 *a=NULL;
00402 }
00403 }
00404
00405
00411
00412 void sinfo_free_float_array(float ***a, const int n)
00413 {
00414 int i=0;
00415 if((*a) != NULL) {
00416 for (i=0; i < n; i++) {
00417 if((*a)[i] != NULL) {
00418 sinfo_free_float(&(*a)[i]);
00419 (*a)[i]=NULL;
00420 }
00421 }
00422 cpl_free(*a);
00423 *a=NULL;
00424 }
00425 }
00426
00427
00432
00433
00434 void
00435 sinfoni_free_vector(cpl_vector **v) {if(v){cpl_vector_delete(*v);*v = NULL;}}
00436
00437
00442
00443 void sinfo_free_stats(cpl_stats **s) {if(s){cpl_stats_delete(*s); *s = NULL;}}
00444
00449
00450 void
00451 sinfo_unwrap_vector(cpl_vector **v) {if(v){cpl_vector_unwrap(*v); *v = NULL;}}
00452
00453
00458
00459 void sinfo_unwrap_matrix(cpl_matrix **m)
00460 {if(m){cpl_matrix_unwrap(*m); *m = NULL;}}
00461
00462
00467
00468 void sinfo_unwrap_bivector_vectors(cpl_bivector **b)
00469 {if(b){cpl_bivector_unwrap_vectors(*b); *b = NULL;}}
00470