38 #include <sinfo_utils_wrappers.h>
39 #include <sinfo_functions.h>
40 #include <sinfo_dump.h>
41 #include <sinfo_utils.h>
42 #include <sinfo_error.h>
43 #include "sinfo_msg.h"
60 sinfo_sort_table_1(cpl_table *t,
const char *column, cpl_boolean reverse)
62 cpl_propertylist *plist = NULL;
64 assure(t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
65 assure(cpl_table_has_column(t, column), CPL_ERROR_ILLEGAL_INPUT,
66 "No column '%s'", column);
68 check(( plist = cpl_propertylist_new(),
69 cpl_propertylist_append_bool(plist, column, reverse)),
70 "Could not create property list for sorting");
72 check( cpl_table_sort(t, plist),
"Could not sort table");
75 sinfo_free_propertylist(&plist);
76 return cpl_error_get_code();
97 sinfo_sort_table_2(cpl_table *t,
const char *column1,
const char *column2,
98 cpl_boolean reverse1, cpl_boolean reverse2)
100 cpl_propertylist *plist = NULL;
102 assure(t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
103 assure(cpl_table_has_column(t, column1), CPL_ERROR_ILLEGAL_INPUT,
104 "No column '%s'", column1);
105 assure(cpl_table_has_column(t, column2), CPL_ERROR_ILLEGAL_INPUT,
106 "No column '%s'", column2);
108 check(( plist = cpl_propertylist_new(),
109 cpl_propertylist_append_bool(plist, column1, reverse1),
110 cpl_propertylist_append_bool(plist, column2, reverse2)),
111 "Could not create property list for sorting");
112 check( cpl_table_sort(t, plist),
"Could not sort table");
115 sinfo_free_propertylist(&plist);
116 return cpl_error_get_code();
138 sinfo_extract_table_rows(
const cpl_table *t,
const char *column,
139 cpl_table_select_operator
operator,
double value)
141 cpl_table *result = NULL;
142 assure( t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
143 assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT,
144 "No such column: %s", column);
149 check(result = cpl_table_duplicate(t),
"selecting");
150 check(sinfo_select_table_rows(result, column,
operator, value),
"select");
151 check(cpl_table_not_selected(result),
"Inverses selection");
152 check(cpl_table_erase_selected(result),
"erase selection");
163 if (cpl_error_get_code() != CPL_ERROR_NONE)
165 sinfo_free_table(&result);
191 sinfo_select_table_rows(cpl_table *t,
const char *column,
192 cpl_table_select_operator
operator,
double value)
196 assure( t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
197 assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT,
198 "No such column: %s", column);
200 type = cpl_table_get_column_type(t, column);
202 assure( type == CPL_TYPE_DOUBLE ||
203 type == CPL_TYPE_INT, CPL_ERROR_INVALID_TYPE,
204 "Column '%s' must be double or int. %s found", column,
205 sinfo_tostring_cpl_type(type));
207 check( cpl_table_select_all(t),
"Error selecting rows");
209 if (type == CPL_TYPE_DOUBLE)
211 result = cpl_table_and_selected_double(t, column,
operator, value);
213 else if (type == CPL_TYPE_INT)
215 result = cpl_table_and_selected_int (t, column,
operator,
216 sinfo_round_double(value));
218 else { passure(CPL_FALSE,
""); }
231 void sinfo_free_parameter(cpl_parameter **p)
232 {
if(p){cpl_parameter_delete(*p); *p = NULL;}}
242 void sinfo_free_apertures(cpl_apertures **a)
243 {
if(a){cpl_apertures_delete(*a); *a = NULL;}}
252 void sinfo_free_image(cpl_image **i) {
if(i){cpl_image_delete(*i); *i = NULL;}}
261 void sinfoni_free_vector(cpl_vector **v) {
if(v){cpl_vector_delete(*v); *v = NULL;}}
270 void sinfo_free_array(cpl_array **i) {
if(i){cpl_array_delete(*i); *i = NULL;}}
278 void sinfo_free_mask(cpl_mask **m) {
if(m){cpl_mask_delete(*m); *m = NULL;}}
285 void sinfo_free_imagelist(cpl_imagelist **i)
286 {
if(i){cpl_imagelist_delete(*i); *i = NULL;}}
293 void sinfo_free_table(cpl_table **t) {
if(t){cpl_table_delete(*t); *t = NULL;}}
300 void sinfo_free_propertylist(cpl_propertylist **p)
301 {
if(p){cpl_propertylist_delete(*p); *p = NULL;}}
308 void sinfo_free_polynomial(cpl_polynomial **p)
309 {
if(p){cpl_polynomial_delete(*p); *p = NULL;}}
317 void sinfoni_free_matrix(cpl_matrix **m)
318 {
if(m){cpl_matrix_delete(*m); *m = NULL;}}
327 void sinfo_free_parameterlist(cpl_parameterlist **p)
328 {
if(p){cpl_parameterlist_delete(*p); *p = NULL;}}
335 void sinfo_free_frameset(cpl_frameset **f)
336 {
if(f){cpl_frameset_delete(*f); *f = NULL;}}
345 void sinfo_free_frame(cpl_frame **f)
346 {
if(f){cpl_frame_delete(*f); *f = NULL;}}
355 void sinfo_free_int(
int **i) {
if(i){cpl_free(*i); *i = NULL;}}
364 void sinfo_free_float(
float **f) {
if(f){cpl_free(*f); *f = NULL;}}
374 void sinfo_free_double(
double **d) {
if(d){cpl_free(*d); *d = NULL;}}
383 void sinfo_free_array_imagelist(cpl_imagelist ***a)
384 {
if(*a){cpl_free(*a); *a = NULL;}}
392 void sinfo_free_array_image(cpl_image ***a) {
if(*a){cpl_free(*a); *a = NULL;}}
402 void sinfo_free_image_array(cpl_image ***a,
const int n)
406 for (
int i=0; i < n; i++) {
407 if((*a)[i] != NULL) {
408 sinfo_free_image(&(*a)[i]);
412 sinfo_free_array_image(&(*a));
424 void sinfo_free_float_array(
float ***a,
const int n)
428 for (
int i=0; i < n; i++) {
429 if((*a)[i] != NULL) {
430 sinfo_free_float(&(*a)[i]);
447 sinfo_free_my_vector(cpl_vector **v) {
if(v){cpl_vector_delete(*v);*v = NULL;}}
458 sinfo_free_bivector(cpl_bivector **bv) {
460 cpl_bivector_delete(*bv);
472 void sinfo_free_stats(cpl_stats **s) {
if(s){cpl_stats_delete(*s); *s = NULL;}}
480 sinfo_unwrap_vector(cpl_vector **v) {
if(v){cpl_vector_unwrap(*v); *v = NULL;}}
488 void sinfo_unwrap_matrix(cpl_matrix **m)
489 {
if(m){cpl_matrix_unwrap(*m); *m = NULL;}}
498 void sinfo_unwrap_bivector_vectors(cpl_bivector **b)
499 {
if(b){cpl_bivector_unwrap_vectors(*b); *b = NULL;}}