41 #include <uves_utils_wrappers.h>
43 #include <uves_utils.h>
44 #include <uves_utils_cpl.h>
45 #include <uves_error.h>
46 #include <uves_dump.h>
49 #include <irplib_utils.h>
57 static int get_candidate(
const double *a,
const int ia[],
60 int (*f)(
const double x[],
const double a[],
62 int (*dfda)(
const double x[],
const double a[],
72 static double get_chisq(
int N,
int D,
73 int (*f)(
const double x[],
const double a[],
82 uves_image_filter_wrapper(
const cpl_image *b,
84 cpl_filter_mode mode);
86 uves_image_filter_median(
const cpl_image * img,
const cpl_matrix * mx)
88 return uves_image_filter_wrapper(img, mx, CPL_FILTER_MEDIAN);
92 uves_image_filter_linear(
const cpl_image *img,
const cpl_matrix * mx)
94 return uves_image_filter_wrapper(img, mx, CPL_FILTER_LINEAR);
103 #define image_is_rejected(badmap, x, y) \
104 ((badmap) != NULL && (badmap)[((x)-1) + ((y)-1)*nx] == CPL_BINARY_1)
106 #ifndef UVES_FIT_MAXITER
107 #define UVES_FIT_MAXITER 1000
128 uves_image_filter_wrapper(
const cpl_image *b,
130 cpl_filter_mode mode)
132 const double EPSILON = 1E-5;
133 int nx = cpl_image_get_size_x(b);
134 int ny = cpl_image_get_size_y(b);
135 int nrow = cpl_matrix_get_nrow(k);
136 int ncol = cpl_matrix_get_ncol(k);
138 cpl_type type = cpl_image_get_type(b);
139 cpl_image * a = cpl_image_new(nx, ny, type);
141 cpl_mask* m = cpl_mask_new(ncol, nrow);
142 cpl_msg_warning(cpl_func,
"nx[%d], ny[%d], ncol[%d], nrow[%d]", nx, ny, ncol, nrow);
143 for (i = 0; i < ncol ; i++)
145 for (j = 0; j < nrow ; j++)
147 double value = cpl_matrix_get(k, j, i);
148 if (fabs(value - 1.0) < EPSILON)
150 cpl_mask_set(m, i + 1, j + 1, CPL_BINARY_1);
155 cpl_image_filter_mask(a, b, m, mode, CPL_BORDER_FILTER);
161 uves_image_filter_mode(
const cpl_image* b,
162 const cpl_matrix * ker,
163 cpl_filter_mode filter)
165 int nx = cpl_image_get_size_x(b);
166 int ny = cpl_image_get_size_y(b);
167 int type = cpl_image_get_type(b);
168 cpl_image * a = cpl_image_new(nx, ny, type);
171 case CPL_FILTER_MEDIAN:
172 check_nomsg(cpl_image_filter(a, b, ker, CPL_FILTER_MEDIAN, CPL_BORDER_FILTER));
174 case CPL_FILTER_LINEAR:
175 check_nomsg(cpl_image_filter(a, b, ker, CPL_FILTER_LINEAR, CPL_BORDER_FILTER));
177 case CPL_FILTER_STDEV:
178 cpl_image_filter(a, b, ker, CPL_FILTER_STDEV, CPL_BORDER_FILTER);
180 case CPL_FILTER_MORPHO:
181 cpl_image_filter(a, b, ker, CPL_FILTER_MORPHO, CPL_BORDER_FILTER);
202 void uves_image_reject_all(cpl_image *image)
208 nx = cpl_image_get_size_x(image);
209 ny = cpl_image_get_size_y(image);
211 for (y = 1; y <= ny; y++) {
212 for (x = 1; x <= nx; x++) {
213 cpl_image_reject(image, x, y);
284 uves_fit_1d_image(
const cpl_image *image,
const cpl_image *noise,
285 const cpl_binary *image_badmap,
286 bool horizontal,
bool fix_back,
bool fit_back,
287 int xlo,
int xhi,
int y_0,
288 double *x0,
double *sigma,
double *norm,
double *background,
290 double *mse,
double *red_chisq,
291 cpl_matrix **covariance,
292 int (*f) (
const double x[],
const double a[],
double *result),
293 int (*dfda)(
const double x[],
const double a[],
double result[]),
296 cpl_vector *x = NULL;
297 cpl_vector *y = NULL;
298 cpl_vector *sigma_y = NULL;
300 cpl_fit_mode fit_pattern;
306 const double *image_data = NULL;
307 const double *noise_data = NULL;
309 assure( x0 != NULL , CPL_ERROR_NULL_INPUT,
"Null fit parameter");
310 assure( sigma != NULL , CPL_ERROR_NULL_INPUT,
"Null fit parameter");
311 assure( norm != NULL , CPL_ERROR_NULL_INPUT,
"Null fit parameter");
312 assure( background != NULL, CPL_ERROR_NULL_INPUT,
"Null fit parameter");
315 assure( image != NULL, CPL_ERROR_NULL_INPUT,
"Null image");
317 image_type = cpl_image_get_type(image);
327 assure( image_type == CPL_TYPE_DOUBLE, CPL_ERROR_UNSUPPORTED_MODE,
330 image_data = cpl_image_get_data_double_const(image);
334 image_type = cpl_image_get_type(noise);
341 assure( image_type == CPL_TYPE_DOUBLE, CPL_ERROR_UNSUPPORTED_MODE,
344 noise_data = cpl_image_get_data_double_const(noise);
347 nx = cpl_image_get_size_x(image);
348 ny = cpl_image_get_size_y(image);
352 assure( 1 <= xlo && xlo <= xhi && xhi <= nx &&
353 1 <= y_0 && y_0 <= ny, CPL_ERROR_ACCESS_OUT_OF_RANGE,
354 "Illegal window (%d, %d)-(%d, %d), image: %dx%d",
360 assure( 1 <= xlo && xlo <= xhi && xhi <= ny &&
361 1 <= y_0 && y_0 <= nx,
362 CPL_ERROR_ACCESS_OUT_OF_RANGE,
363 "Illegal window (%d, %d)-(%d, %d), image: %dx%d",
373 assure( cpl_image_get_size_x(noise) == nx &&
374 cpl_image_get_size_y(noise) == ny,
375 CPL_ERROR_INCOMPATIBLE_INPUT,
"Noise image: %" CPL_SIZE_FORMAT
"x%" CPL_SIZE_FORMAT
", image: %dx%d:",
376 cpl_image_get_size_x(noise),
377 cpl_image_get_size_y(noise),
383 for (i = xlo; i <= xhi; i++)
385 if ( !image_is_rejected(image_badmap,
386 (horizontal) ? i : y_0,
387 (horizontal) ? y_0 : i) )
391 if( !image_is_rejected(image_badmap,
392 (horizontal) ? i : y_0,
393 (horizontal) ? y_0 : i) )
401 noise_data[(((horizontal) ? i : y_0) - 1) +
402 (((horizontal) ? y_0 : i) - 1) * nx]
404 CPL_ERROR_ILLEGAL_INPUT,
405 "Non-positive noise at (%d, %d): %e",
406 (horizontal) ? i : y_0,
407 (horizontal) ? y_0 : i,
408 noise_data[(((horizontal) ? i : y_0) - 1) +
409 (((horizontal) ? y_0 : i) - 1) * nx]
429 assure( N >= 1, CPL_ERROR_ILLEGAL_INPUT,
"Only %d good pixel(s)", N);
432 x = cpl_vector_new(N);
433 y = cpl_vector_new(N);
436 sigma_y = cpl_vector_new(N);
442 fit_pattern = CPL_FIT_CENTROID | CPL_FIT_STDEV | CPL_FIT_AREA;
446 fit_pattern = CPL_FIT_AREA | CPL_FIT_OFFSET;
450 fit_pattern = CPL_FIT_ALL;
471 flux = image_data[(((horizontal) ? i : y_0) - 1) +
472 (((horizontal) ? y_0 : i) - 1) * nx];
475 if ( !image_is_rejected(image_badmap,
476 (horizontal) ? i : y_0,
477 (horizontal) ? y_0 : i) )
489 flux_noise = noise_data
490 [(((horizontal) ? i : y_0) - 1) +
491 (((horizontal) ? y_0 : i) - 1) * nx];
494 if ( !image_is_rejected(image_badmap,
500 cpl_vector_set(x, j, i);
501 cpl_vector_set(y, j, flux);
502 cpl_vector_set(sigma_y, j, flux_noise);
508 cpl_vector_set(x, j, i);
509 cpl_vector_set(y, j, flux);
514 passure( j == N,
"%d %d", j, N);
516 check( uves_fit_1d(x, NULL,
518 fit_pattern, fit_back,
519 x0, sigma, norm, background,
528 uves_free_vector(&x);
529 uves_free_vector(&y);
530 uves_free_vector(&sigma_y);
532 return cpl_error_get_code();
544 static int uves_fit_1d_compare(
const void *left,
548 (((uves_fit_1d_input *)left )->x <
549 ((uves_fit_1d_input *)right)->x) ? -1 :
550 (((uves_fit_1d_input *)left )->x ==
551 ((uves_fit_1d_input *)right)->x) ? 0 : 1;
579 uves_fit_1d(cpl_vector *x,
const cpl_vector *sigma_x,
580 cpl_vector *y,
const cpl_vector *sigma_y,
581 cpl_fit_mode fit_pars,
bool fit_back,
582 double *x0,
double *sigma,
double *area,
double *offset,
double *slope,
583 double *mse,
double *red_chisq,
584 cpl_matrix **covariance,
585 int (*f) (
const double x[],
const double a[],
double *result),
586 int (*dfda)(
const double x[],
const double a[],
double result[]),
589 cpl_matrix *x_matrix = NULL;
597 double sigma_guess = 0;
601 cpl_ensure_code( M == 4 || M == 5, CPL_ERROR_UNSUPPORTED_MODE);
604 cpl_ensure_code( x != NULL, CPL_ERROR_NULL_INPUT);
605 cpl_ensure_code( sigma_x == NULL, CPL_ERROR_UNSUPPORTED_MODE);
606 cpl_ensure_code( y != NULL, CPL_ERROR_NULL_INPUT);
609 N = cpl_vector_get_size(x);
611 cpl_ensure_code( N == cpl_vector_get_size(y),
612 CPL_ERROR_INCOMPATIBLE_INPUT);
616 cpl_ensure_code( N == cpl_vector_get_size(sigma_x),
617 CPL_ERROR_INCOMPATIBLE_INPUT);
621 cpl_ensure_code( N == cpl_vector_get_size(sigma_y),
622 CPL_ERROR_INCOMPATIBLE_INPUT);
625 cpl_ensure_code( x0 != NULL &&
629 (M != 5 || slope != NULL), CPL_ERROR_NULL_INPUT);
631 if (! (fit_pars & CPL_FIT_STDEV))
633 cpl_ensure_code( *sigma > 0, CPL_ERROR_ILLEGAL_INPUT);
636 cpl_ensure_code( !fit_back || fit_pars == (CPL_FIT_OFFSET | CPL_FIT_AREA),
637 CPL_ERROR_INCOMPATIBLE_INPUT);
640 if (! (fit_pars & CPL_FIT_AREA) && !fit_back)
642 cpl_ensure_code( *area > 0, CPL_ERROR_ILLEGAL_INPUT);
649 cpl_ensure_code( red_chisq == NULL || N >= 5, CPL_ERROR_ILLEGAL_INPUT);
651 if (covariance != NULL) *covariance = NULL;
658 cpl_ensure_code( (red_chisq == NULL && covariance == NULL) ||
660 CPL_ERROR_INCOMPATIBLE_INPUT);
663 x_matrix = cpl_matrix_wrap(N, 1, cpl_vector_get_data(x));
664 if (x_matrix == NULL)
668 CPL_ERROR_ILLEGAL_OUTPUT);
672 if (sigma_x != NULL && cpl_vector_get_min(sigma_x) <= 0)
674 cpl_matrix_unwrap(x_matrix);
677 CPL_ERROR_ILLEGAL_INPUT);
679 if (sigma_y != NULL && cpl_vector_get_min(sigma_y) <= 0)
681 cpl_matrix_unwrap(x_matrix);
684 CPL_ERROR_ILLEGAL_INPUT);
694 assert( fit_pars == CPL_FIT_OFFSET || CPL_FIT_AREA);
696 offset_guess = cpl_vector_get_median_const(y);
697 area_guess = N*(cpl_vector_get_mean(y) - offset_guess);
701 sigma_guess = *sigma;
706 double fraction[3] = {0.25 , 0.50 , 0.75};
707 const double *y_data = cpl_vector_get_data_const(y);
709 if (fit_pars & CPL_FIT_OFFSET)
718 cpl_vector *y_dup = cpl_vector_duplicate(y);
722 cpl_matrix_unwrap(x_matrix);
725 CPL_ERROR_ILLEGAL_OUTPUT);
729 cpl_vector_get_data(y_dup), N, N/4);
731 cpl_vector_delete(y_dup);
735 offset_guess = *offset;
740 if ( (fit_pars & CPL_FIT_CENTROID) ||
741 (fit_pars & CPL_FIT_STDEV )
752 *sorted_input = cpl_malloc(N *
sizeof(*sorted_input));
753 const double *x_data = cpl_matrix_get_data_const(x_matrix);
754 cpl_boolean is_sorted = CPL_TRUE;
757 if (sorted_input == NULL)
759 cpl_matrix_unwrap(x_matrix);
762 CPL_ERROR_ILLEGAL_INPUT);
765 for (i = 0; i < N; i++)
767 sorted_input[i].x = x_data[i];
768 sorted_input[i].y = y_data[i];
770 is_sorted = is_sorted &&
771 (i==0 || (x_data[i-1] < x_data[i]));
776 qsort(sorted_input, N,
sizeof(*sorted_input),
777 &uves_fit_1d_compare);
780 for(i = 0; i < N; i++)
782 double flux = sorted_input[i].y;
784 sum += (flux - offset_guess);
797 double running_sum = 0.0;
801 flux = sorted_input[i].y - offset_guess;
803 for (j = 0; j < 3; j++)
805 double limit = fraction[j] * sum;
808 while (running_sum + flux < limit && i < N-1)
812 flux = sorted_input[i].y - offset_guess;
817 k = (limit - running_sum)/flux;
826 x1 = sorted_input[i-1].x;
827 x2 = sorted_input[i].x;
839 quartile[j] = sorted_input[i].x;
848 x1 = sorted_input[i].x;
849 x2 = sorted_input[i+1].x;
861 quartile[j] = sorted_input[i].x;
872 quartile[1] = cpl_matrix_get_mean(x_matrix);
874 quartile[2] = quartile[1];
875 quartile[0] = quartile[2] - 1.0;
879 cpl_free(sorted_input);
883 x0_guess = (fit_pars & CPL_FIT_CENTROID) ? quartile[1] : *x0;
890 sigma_guess = (fit_pars & CPL_FIT_STDEV) ?
891 (quartile[2] - quartile[0]) / (2*0.6744) : *sigma;
893 area_guess = (fit_pars & CPL_FIT_AREA) ?
894 (cpl_vector_get_max(y) - offset_guess) * sqrt(2*M_PI) * sigma_guess : *area;
898 if ( area_guess <= 0) area_guess = 1.0;
899 if (sigma_guess <= 0) sigma_guess = 1.0;
910 assert(M == 4 || M == 5);
911 a = cpl_vector_new(M);
915 cpl_matrix_unwrap(x_matrix);
918 CPL_ERROR_ILLEGAL_OUTPUT);
921 cpl_vector_set(a, 0, x0_guess);
922 cpl_vector_set(a, 1, sigma_guess);
923 cpl_vector_set(a, 2, area_guess);
924 cpl_vector_set(a, 3, offset_guess);
926 ia[0] = fit_pars & CPL_FIT_CENTROID;
927 ia[1] = fit_pars & CPL_FIT_STDEV;
928 ia[2] = fit_pars & CPL_FIT_AREA;
929 ia[3] = fit_pars & CPL_FIT_OFFSET;
936 if (fit_pars & CPL_FIT_OFFSET)
938 cpl_vector_set(a, 4, 0);
942 cpl_vector_set(a, 4, *slope);
948 ec = uves_fit(x_matrix, NULL,
957 ia[4] = fit_pars & CPL_FIT_OFFSET;
959 if (covariance != NULL)
961 uves_free_matrix(covariance);
964 ec = uves_fit(x_matrix, NULL,
972 cpl_matrix_unwrap(x_matrix);
975 if (ec == CPL_ERROR_NONE ||
976 ec == CPL_ERROR_SINGULAR_MATRIX)
988 if (CPL_FIT_CENTROID) *x0 = cpl_vector_get(a, 0);
989 if (CPL_FIT_STDEV ) *sigma = fabs(cpl_vector_get(a, 1));
990 if (CPL_FIT_AREA ) *area = cpl_vector_get(a, 2);
991 if (CPL_FIT_OFFSET ) {
992 *offset = cpl_vector_get(a, 3);
993 if (M == 5) *slope = cpl_vector_get(a, 4);
997 cpl_vector_delete(a);
999 xlo = cpl_vector_get_min(x);
1000 xhi = cpl_vector_get_max(x);
1002 if (ec == CPL_ERROR_CONTINUE ||
1004 !irplib_isnan(*x0 ) && !irplib_isinf(*x0 ) &&
1005 !irplib_isnan(*sigma ) && !irplib_isinf(*sigma ) &&
1006 !irplib_isnan(*area ) && !irplib_isinf(*area ) &&
1007 !irplib_isnan(*offset) && !irplib_isinf(*offset) &&
1008 ((M != 5) || (!irplib_isnan(*slope ) && !irplib_isinf(*slope ))) &&
1009 xlo <= *x0 && *x0 <= xhi &&
1010 0 < *sigma && *sigma < (xhi - xlo + 1) &&
1011 (fit_back || 0 < *area)
1023 *sigma = sigma_guess;
1025 *offset = offset_guess;
1026 if (M == 5) *slope = 0;
1030 if (covariance != NULL && *covariance != NULL)
1032 cpl_matrix_delete(*covariance);
1039 CPL_ERROR_CONTINUE);
1043 return CPL_ERROR_NONE;
1117 uves_fit(
const cpl_matrix *x,
const cpl_matrix *sigma_x,
1118 const cpl_vector *y,
const cpl_vector *sigma_y,
1119 cpl_vector *a,
const int ia[],
1120 int (*f)(
const double x[],
const double a[],
double *result),
1121 int (*dfda)(
const double x[],
const double a[],
double result[]),
1124 cpl_matrix **covariance)
1126 const double *x_data = NULL;
1127 const double *y_data = NULL;
1128 const double *sigma_data = NULL;
1135 double lambda = 0.0;
1136 double MAXLAMBDA = 10e40;
1138 double chi_sq = 0.0;
1143 cpl_matrix *alpha = NULL;
1144 cpl_matrix *beta = NULL;
1145 double *a_data = NULL;
1146 double *a_da = NULL;
1147 double *part = NULL;
1148 int *ia_local = NULL;
1153 if (covariance != NULL) *covariance = NULL;
1156 cpl_ensure_code(x != NULL, CPL_ERROR_NULL_INPUT);
1157 cpl_ensure_code(sigma_x == NULL, CPL_ERROR_UNSUPPORTED_MODE);
1158 cpl_ensure_code(y != NULL, CPL_ERROR_NULL_INPUT);
1159 cpl_ensure_code(a != NULL, CPL_ERROR_NULL_INPUT);
1161 cpl_ensure_code(f != NULL, CPL_ERROR_NULL_INPUT);
1162 cpl_ensure_code(dfda != NULL, CPL_ERROR_NULL_INPUT);
1165 cpl_ensure_code( sigma_y != NULL || (red_chisq == NULL && covariance == NULL),
1166 CPL_ERROR_INCOMPATIBLE_INPUT);
1168 D = cpl_matrix_get_ncol(x);
1169 N = cpl_matrix_get_nrow(x);
1170 M = cpl_vector_get_size(a);
1171 cpl_ensure_code(N > 0 && D > 0 && M > 0, CPL_ERROR_ILLEGAL_INPUT);
1173 cpl_ensure_code( cpl_vector_get_size(y) == N,
1174 CPL_ERROR_INCOMPATIBLE_INPUT);
1176 x_data = cpl_matrix_get_data_const(x);
1177 y_data = cpl_vector_get_data_const(y);
1178 a_data = cpl_vector_get_data(a);
1180 if (sigma_y != NULL)
1182 cpl_ensure_code( cpl_vector_get_size(sigma_y) == N,
1183 CPL_ERROR_INCOMPATIBLE_INPUT);
1185 cpl_ensure_code( cpl_vector_get_min (sigma_y) > 0,
1186 CPL_ERROR_ILLEGAL_INPUT);
1187 sigma_data = cpl_vector_get_data_const(sigma_y);
1190 ia_local = cpl_malloc(M *
sizeof(
int));
1191 cpl_ensure_code(ia_local != NULL, CPL_ERROR_ILLEGAL_OUTPUT);
1199 for (i = 0; i < M; i++)
1201 ia_local[i] = ia[i];
1212 cpl_ensure_code( CPL_FALSE,
1213 CPL_ERROR_ILLEGAL_INPUT);
1223 for (i = 0; i < M; i++)
1230 if (! ( red_chisq == NULL || N > Mfit ) )
1235 CPL_ERROR_ILLEGAL_INPUT);
1239 alpha = cpl_matrix_new(Mfit, Mfit);
1245 CPL_ERROR_ILLEGAL_OUTPUT);
1248 beta = cpl_matrix_new(Mfit, 1);
1252 cpl_matrix_delete(alpha);
1255 CPL_ERROR_ILLEGAL_OUTPUT);
1258 a_da = cpl_malloc(M *
sizeof(
double));
1262 cpl_matrix_delete(alpha);
1263 cpl_matrix_delete(beta);
1266 CPL_ERROR_ILLEGAL_OUTPUT);
1269 part = cpl_malloc(M *
sizeof(
double));
1273 cpl_matrix_delete(alpha);
1274 cpl_matrix_delete(beta);
1278 CPL_ERROR_ILLEGAL_OUTPUT);
1285 if( (chi_sq = get_chisq(N, D, f, a_data, x_data, y_data, sigma_data)) < 0)
1288 cpl_matrix_delete(alpha);
1289 cpl_matrix_delete(beta);
1294 cpl_error_get_code());
1300 for (i = 0; i < M; i++)
1309 while (count < 5 && lambda < MAXLAMBDA && iterations < UVES_FIT_MAXITER)
1315 double chi_sq_candidate = 0.0;
1323 while( (returncode = get_candidate(a_data, ia_local,
1326 x_data, y_data, sigma_data,
1327 part, alpha, beta, a_da)
1329 && cpl_error_get_code() == CPL_ERROR_SINGULAR_MATRIX
1330 && lambda < MAXLAMBDA)
1340 if ( !( lambda < MAXLAMBDA ) )
1343 cpl_matrix_delete(alpha);
1344 cpl_matrix_delete(beta);
1349 CPL_ERROR_CONTINUE);
1352 if (returncode != 0)
1355 cpl_matrix_delete(alpha);
1356 cpl_matrix_delete(beta);
1361 cpl_error_get_code());
1365 if ((chi_sq_candidate = get_chisq(N, D, f, a_da,
1366 x_data, y_data, sigma_data)) < 0)
1369 cpl_matrix_delete(alpha);
1370 cpl_matrix_delete(beta);
1375 cpl_error_get_code());
1378 if (chi_sq_candidate > 1.000001 * chi_sq)
1383 chi_sq, chi_sq_candidate, lambda);
1390 uves_msg_error(
"Chi^2 = %f Candidate = %f* Lambda = %e count = %d",
1391 chi_sq, chi_sq_candidate, lambda, count);
1400 (chi_sq - chi_sq_candidate)/chi_sq < .01)
1411 if (chi_sq_candidate < chi_sq)
1415 for (i = 0; i < M; i++)
1417 a_data[i] = a_da[i];
1422 chi_sq = chi_sq_candidate;
1429 if ( !( lambda < MAXLAMBDA && iterations < UVES_FIT_MAXITER ) )
1433 lambda, iterations);
1436 cpl_matrix_delete(alpha);
1437 cpl_matrix_delete(beta);
1442 CPL_ERROR_CONTINUE);
1452 for(i = 0; i < N; i++)
1455 double residual = 0.0;
1458 if( f(&(x_data[i*D]),
1463 cpl_matrix_delete(alpha);
1464 cpl_matrix_delete(beta);
1469 CPL_ERROR_ILLEGAL_INPUT);
1472 residual = y_data[i] - fx_i;
1473 *mse += residual * residual;
1479 if (red_chisq != NULL)
1482 *red_chisq = chi_sq / (N-Mfit);
1488 if (covariance != NULL)
1492 if( get_candidate(a_data, ia_local,
1493 M, N, D, 0.0, f, dfda,
1494 x_data, y_data, sigma_data,
1495 part, alpha, beta, a_da)
1499 cpl_matrix_delete(alpha);
1500 cpl_matrix_delete(beta);
1505 cpl_error_get_code());
1508 cov = cpl_matrix_invert_create(alpha);
1512 cpl_matrix_delete(alpha);
1513 cpl_matrix_delete(beta);
1518 cpl_error_get_code());
1524 for (i = 0; i < Mfit; i++)
1526 if ( !(cpl_matrix_get(cov, i, i) > 0) )
1529 cpl_matrix_delete(alpha);
1530 cpl_matrix_delete(beta);
1533 cpl_matrix_delete(cov);
1537 CPL_ERROR_SINGULAR_MATRIX);
1546 *covariance = cpl_matrix_new(M, M);
1547 if (*covariance == NULL)
1550 cpl_matrix_delete(alpha);
1551 cpl_matrix_delete(beta);
1554 cpl_matrix_delete(cov);
1557 CPL_ERROR_ILLEGAL_OUTPUT);
1563 for (j = 0, jmfit = 0; j < M; j++)
1564 if (ia_local[j] != 0)
1568 for (i = 0, imfit = 0; i < M; i++)
1569 if (ia_local[i] != 0)
1571 cpl_matrix_set(*covariance, i, j,
1573 cov, imfit, jmfit));
1577 assert( imfit == Mfit );
1582 assert( jmfit == Mfit );
1585 cpl_matrix_delete(cov);
1589 cpl_matrix_delete(alpha);
1590 cpl_matrix_delete(beta);
1594 return CPL_ERROR_NONE;
1609 uves_cast_image(cpl_image **image, cpl_type to_type)
1611 cpl_image *temp = NULL;
1613 assure( image != NULL, CPL_ERROR_NULL_INPUT,
"Null image");
1617 check( *image = cpl_image_cast(temp, to_type),
"Couldn't convert image to %s",
1621 uves_free_image(&temp);
1622 return cpl_error_get_code();
1643 uves_crop_image(cpl_image **image,
int x1,
int y_1,
int x2,
int y2)
1645 cpl_image *temp = NULL;
1647 assure( image != NULL, CPL_ERROR_NULL_INPUT,
"Null image");
1651 check( *image = cpl_image_extract(temp, x1, y_1, x2, y2),
1652 "Could not extract image");
1655 uves_free_image(&temp);
1656 return cpl_error_get_code();
1686 cpl_type keywordtype,
void *result)
1691 assure( plist != NULL , CPL_ERROR_NULL_INPUT,
"Null property list");
1692 assure( keyword != NULL, CPL_ERROR_NULL_INPUT,
"Null keyword");
1696 "Keyword %s does not exist", keyword );
1699 "Could not read type of keyword '%s'", keyword );
1700 assure(t == keywordtype , CPL_ERROR_TYPE_MISMATCH,
1701 "Keyword '%s' has wrong type (%s). %s expected",
1705 switch (keywordtype)
1708 check( *((
int *)result) =
1710 "Could not get (integer) value of %s", keyword );
1712 case CPL_TYPE_BOOL :
1713 check( *((
bool *)result) =
1715 "Could not get (boolean) value of %s", keyword );
1717 case CPL_TYPE_DOUBLE:
1718 check( *((
double *)result) =
1720 "Could not get (double) value of %s" , keyword );
1722 case CPL_TYPE_STRING:
1723 check( *((
const char * *)result) =
1725 "Could not get (string) value of %s" , keyword );
1728 assure(
false, CPL_ERROR_INVALID_TYPE,
"Unknown type");
1733 return cpl_error_get_code();
1765 uves_find_frame(
const cpl_frameset *frames,
const char **wanted,
int N,
int *found,
1766 const cpl_frame **
frame)
1768 const char *filename = NULL;
1770 const cpl_frame *f = NULL;
1779 for (i = 0; i < N; i++)
1781 check( f = cpl_frameset_find_const(frames, wanted[i]),
1782 "Could not search through frame set");
1785 check( filename = cpl_frame_get_filename(f),
1786 "Could not read frame filename");
1798 assure(filename != NULL, CPL_ERROR_DATA_NOT_FOUND,
"No such frame in frame set");
1814 uves_get_nextensions(
const char *filename)
1816 cpl_size result = 0;
1817 cpl_frame *f = NULL;
1822 check(( f = cpl_frame_new(),
1823 cpl_frame_set_filename(f, filename)),
1824 "Could not create frame");
1826 check( result = cpl_frame_get_nextensions(f),
1827 "Error reading number of extensions of file '%s'", filename);
1829 cpl_frame_delete(f);
1856 uves_get_parameter(
const cpl_parameterlist *parameters,
const char *context,
1857 const char *recipe_id,
const char *name, cpl_type type,
1860 char *fullname = NULL;
1861 const cpl_parameter *p = NULL;
1863 passure( parameters != NULL,
" ");
1865 passure( recipe_id != NULL,
" ");
1869 if (context != NULL)
1871 check( fullname = uves_sprintf(
"%s.%s.%s", context, recipe_id, name),
1872 "Error getting full parameter name");
1876 check( fullname = uves_sprintf(
"%s.%s", recipe_id, name),
1877 "Error getting full parameter name");
1881 check( p = cpl_parameterlist_find_const(parameters, fullname),
1882 "Error searching for parameter '%s'", fullname);
1883 assure( p != NULL, CPL_ERROR_DATA_NOT_FOUND,
1884 "No parameter '%s' in parameter list", fullname);
1889 check( partype = cpl_parameter_get_type(p),
1890 "Could not read type of parameter '%s'", fullname);
1891 assure( partype == type, CPL_ERROR_TYPE_MISMATCH,
1892 "Parameter '%s' has type %s. Expected type was %s",
1901 check( *(
int * )value =
1902 cpl_parameter_get_int (p),
1903 "Could not read integer parameter '%s'", fullname);
1906 check( *(
bool * )value =
1907 cpl_parameter_get_bool (p),
1908 "Could not read boolean parameter '%s'", fullname);
1910 case CPL_TYPE_DOUBLE:
1911 check( *(
double * )value =
1912 cpl_parameter_get_double(p),
1913 "Could not read double parameter '%s'" , fullname );
1915 case CPL_TYPE_STRING:
1916 check( *(
const char ** )value =
1917 cpl_parameter_get_string(p),
1918 "Could not read string parameter '%s'" , fullname );
1921 assure(
false, CPL_ERROR_UNSUPPORTED_MODE,
1922 "Don't know how to read parameter '%s' of type %s",
1928 cpl_free(fullname); fullname = NULL;
1929 return cpl_error_get_code();
1950 uves_set_parameter(cpl_parameterlist *parameters,
1951 const char *context,
1952 const char *name, cpl_type type,
void *value)
1954 char *fullname = NULL;
1955 cpl_parameter *p = NULL;
1957 check( fullname = uves_sprintf(
"%s.%s", context, name),
1958 "Error getting full parameter name");
1961 check( p = cpl_parameterlist_find(parameters, fullname),
1962 "Error searching for parameter '%s'", fullname);
1963 assure( p != NULL, CPL_ERROR_DATA_NOT_FOUND,
1964 "No parameter '%s' in parameter list", fullname);
1969 check( partype = cpl_parameter_get_type(p),
1970 "Could not read type of parameter '%s'", fullname);
1971 assure( partype == type, CPL_ERROR_TYPE_MISMATCH,
1972 "Parameter '%s' has type %s. Expected type was %s",
1981 check( cpl_parameter_set_int (p, *((
int *) value)),
1982 "Could not set integer parameter '%s'", fullname);
1985 check( cpl_parameter_set_bool (p, *((
bool *) value)),
1986 "Could not set boolean parameter '%s'", fullname);
1988 case CPL_TYPE_DOUBLE:
1989 check( cpl_parameter_set_double(p, *((
double *) value)),
1990 "Could not set double parameter '%s'" , fullname);
1992 case CPL_TYPE_STRING:
1993 check( cpl_parameter_set_string(p, *((
char **) value)),
1994 "Could not set string parameter '%s'" , fullname);
1997 assure(
false, CPL_ERROR_UNSUPPORTED_MODE,
1998 "Don't know how to set parameter of type %s",
2004 cpl_free(fullname); fullname = NULL;
2005 return cpl_error_get_code();
2025 uves_set_parameter_default(cpl_parameterlist *parameters,
const char *context,
2026 const char *parname,
2027 cpl_type type,
void *value)
2029 const char *full_name = NULL;
2030 cpl_parameter *p = NULL;
2033 if (context != NULL)
2035 full_name = uves_sprintf(
"%s.%s", context, parname);
2039 full_name = uves_sprintf(
"%s", parname);
2042 if (full_name == NULL)
2044 return CPL_ERROR_ILLEGAL_OUTPUT;
2048 if ( (p = cpl_parameterlist_find(parameters, full_name)) == NULL)
2052 uves_free_string_const(&full_name);
2053 if (cpl_error_get_code() != CPL_ERROR_NONE)
return cpl_error_get_code();
2054 else return CPL_ERROR_DATA_NOT_FOUND;
2057 partype = cpl_parameter_get_type(p);
2059 if (partype != type)
2061 uves_msg_error(
"Parameter '%s' has type %s. Expected type was %s",
2065 uves_free_string_const(&full_name);
2066 return CPL_ERROR_TYPE_MISMATCH;
2072 cpl_parameter_set_default_int (p, *((
int *) value));
2075 cpl_parameter_set_default_bool (p, *((
bool *) value));
2077 case CPL_TYPE_DOUBLE:
2078 cpl_parameter_set_default_double(p, *((
double *) value));
2080 case CPL_TYPE_STRING:
2081 cpl_parameter_set_default_string(p, *((
char **) value));
2086 uves_free_string_const(&full_name);
2087 return CPL_ERROR_INVALID_TYPE;
2090 if (cpl_error_get_code() != CPL_ERROR_NONE)
2095 uves_free_string_const(&full_name);
2096 return cpl_error_get_code();
2100 uves_free_string_const(&full_name);
2101 return CPL_ERROR_NONE;
2119 uves_raise_to_median_frac(cpl_table *t,
const char *column,
double fraction)
2125 assure(cpl_table_has_column(t, column), CPL_ERROR_DATA_NOT_FOUND,
2126 "No such column: %s", column);
2128 assure(cpl_table_get_column_type(t, column) == CPL_TYPE_DOUBLE,
2129 CPL_ERROR_UNSUPPORTED_MODE,
"Column %s has type %s. %s expected",
2135 threshold = fraction * cpl_table_get_column_median(t, column);
2136 for (i = 0; i < cpl_table_get_nrow(t); i++)
2138 if (cpl_table_get_double(t, column, i, NULL) < threshold)
2140 cpl_table_set_double(t, column, i, threshold);
2169 uves_select_table_rows(cpl_table *t,
const char *column,
2170 cpl_table_select_operator
operator,
double value)
2175 assure( t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
2176 assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT,
2177 "No such column: %s", column);
2179 type = cpl_table_get_column_type(t, column);
2181 assure( type == CPL_TYPE_DOUBLE || type == CPL_TYPE_FLOAT ||
2182 type == CPL_TYPE_INT, CPL_ERROR_INVALID_TYPE,
2183 "Column '%s' must be double or int. %s found", column,
2186 check( cpl_table_select_all(t),
"Error selecting rows");
2188 if (type == CPL_TYPE_DOUBLE)
2190 result = cpl_table_and_selected_double(t, column,
operator, value);
2192 else if (type == CPL_TYPE_FLOAT)
2194 result = cpl_table_and_selected_float(t, column,
operator, value);
2196 else if (type == CPL_TYPE_INT)
2198 result = cpl_table_and_selected_int(t, column,
operator,
2199 uves_round_double(value));
2224 uves_extract_table_rows_local(cpl_table *t,
const char *column,
2225 cpl_table_select_operator
operator,
double value)
2229 assure( t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
2230 assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT,
2231 "No such column: %s", column);
2233 check( result = uves_select_table_rows(t, column,
operator, value),
2234 "Error selecting rows");
2236 check( cpl_table_not_selected(t),
"Error selecting rows");
2238 check( cpl_table_erase_selected(t),
"Error deleting rows");
2265 uves_erase_table_rows(cpl_table *t,
const char *column,
2266 cpl_table_select_operator
operator,
double value)
2270 assure( t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
2271 assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT,
2272 "No such column: %s", column);
2274 check( result = uves_select_table_rows(t, column,
operator, value),
2275 "Error selecting rows");
2277 check( cpl_table_erase_selected(t),
"Error deleting rows");
2298 void uves_propertylist_append_property(
uves_propertylist *plist,
const cpl_property *p)
2300 switch(cpl_property_get_type(p)) {
2302 uves_propertylist_append_char(plist, cpl_property_get_name(p), cpl_property_get_char(p));
2305 uves_propertylist_append_bool(plist, cpl_property_get_name(p), cpl_property_get_bool(p));
2308 uves_propertylist_append_int(plist, cpl_property_get_name(p), cpl_property_get_int(p));
2311 uves_propertylist_append_long(plist, cpl_property_get_name(p), cpl_property_get_long(p));
2313 case CPL_TYPE_FLOAT:
2314 uves_propertylist_append_float(plist, cpl_property_get_name(p), cpl_property_get_float(p));
2316 case CPL_TYPE_DOUBLE:
2317 uves_propertylist_append_double(plist, cpl_property_get_name(p), cpl_property_get_double(p));
2319 case CPL_TYPE_STRING:
2320 uves_propertylist_append_string(plist, cpl_property_get_name(p), cpl_property_get_string(p));
2323 assure(
false, CPL_ERROR_UNSUPPORTED_MODE,
2341 uves_table_and_selected_invalid(cpl_table *t,
const char *column)
2343 if (cpl_table_get_column_type(t, column) != CPL_TYPE_STRING)
2345 return cpl_table_and_selected_invalid(t, column);
2350 for (i = 0; i < cpl_table_get_nrow(t); i++)
2352 if (cpl_table_is_selected(t, i))
2354 if (cpl_table_is_valid(t, column, i))
2356 cpl_table_unselect_row(t, i);
2363 return cpl_table_count_selected(t);
2387 uves_erase_invalid_table_rows(cpl_table *t,
const char *column)
2391 assure( t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
2397 cpl_table *argument = t;
2399 while ( (name = cpl_table_get_column_name(argument)) != NULL)
2404 n_deleted_rows = uves_erase_invalid_table_rows(t, name);
2406 if (n_deleted_rows > 0)
2409 n_deleted_rows, name);
2411 result += n_deleted_rows;
2416 assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT,
2417 "No such column: %s", column);
2419 check(( cpl_table_select_all(t),
2420 result = uves_table_and_selected_invalid(t, column),
2421 cpl_table_erase_selected(t)),
2422 "Error deleting rows");
2448 uves_extract_table_rows(
const cpl_table *t,
const char *column,
2449 cpl_table_select_operator
operator,
double value)
2451 cpl_table *result = NULL;
2453 assure( t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
2454 assure( cpl_table_has_column(t, column), CPL_ERROR_INCOMPATIBLE_INPUT,
2455 "No such column: %s", column);
2459 check(( result = cpl_table_duplicate(t),
2461 uves_select_table_rows(result, column,
operator, value),
2462 cpl_table_not_selected(result),
2464 cpl_table_erase_selected(result)),
2466 "Error extracting rows");
2468 passure( cpl_table_count_selected(result) == cpl_table_get_nrow(result),
2469 "%" CPL_SIZE_FORMAT
" %" CPL_SIZE_FORMAT
"",
2470 cpl_table_count_selected(result), cpl_table_get_nrow(result) );
2473 if (cpl_error_get_code() != CPL_ERROR_NONE)
2475 uves_free_table(&result);
2494 uves_sort_table_1(cpl_table *t,
const char *column,
bool reverse)
2498 assure(t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
2499 assure(cpl_table_has_column(t, column), CPL_ERROR_ILLEGAL_INPUT,
2500 "No column '%s'", column);
2503 uves_propertylist_append_bool(plist, column, reverse)),
2504 "Could not create property list for sorting");
2506 check( uves_table_sort(t, plist),
"Could not sort table");
2509 uves_free_propertylist(&plist);
2531 uves_sort_table_2(cpl_table *t,
const char *column1,
const char *column2,
2532 bool reverse1,
bool reverse2)
2536 assure(t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
2537 assure(cpl_table_has_column(t, column1), CPL_ERROR_ILLEGAL_INPUT,
2538 "No column '%s'", column1);
2539 assure(cpl_table_has_column(t, column2), CPL_ERROR_ILLEGAL_INPUT,
2540 "No column '%s'", column2);
2543 uves_propertylist_append_bool(plist, column1, reverse1),
2544 uves_propertylist_append_bool(plist, column2, reverse2)),
2545 "Could not create property list for sorting");
2546 check( uves_table_sort(t, plist),
"Could not sort table");
2549 uves_free_propertylist(&plist);
2569 uves_sort_table_3(cpl_table *t,
const char *column1,
const char *column2,
2570 const char *column3,
2571 bool reverse1,
bool reverse2,
bool reverse3)
2575 assure(t != NULL, CPL_ERROR_NULL_INPUT,
"Null table");
2576 assure(cpl_table_has_column(t, column1), CPL_ERROR_ILLEGAL_INPUT,
2577 "No column '%s'", column1);
2578 assure(cpl_table_has_column(t, column2), CPL_ERROR_ILLEGAL_INPUT,
2579 "No column '%s'", column2);
2580 assure(cpl_table_has_column(t, column3), CPL_ERROR_ILLEGAL_INPUT,
2581 "No column '%s'", column3);
2584 uves_propertylist_append_bool(plist, column1, reverse1),
2585 uves_propertylist_append_bool(plist, column2, reverse2),
2586 uves_propertylist_append_bool(plist, column3, reverse3)),
2587 "Could not create property list for sorting");
2588 check( uves_table_sort(t, plist),
"Could not sort table");
2591 uves_free_propertylist(&plist);
2600 void uves_free(
const void *mem)
2602 cpl_free((
void *)mem);
2612 void uves_free_image(cpl_image **i)
2613 {
if(i){cpl_image_delete(*i); *i = NULL;}}
2620 void uves_free_mask(cpl_mask **m)
2621 {
if(m){cpl_mask_delete(*m); *m = NULL;}}
2628 void uves_free_imagelist(cpl_imagelist **i)
2629 {
if(i){cpl_imagelist_delete(*i); *i = NULL;}}
2637 void uves_free_table(cpl_table **t)
2638 {
if(t){cpl_table_delete(*t); *t = NULL;}}
2646 void uves_free_table_const(
const cpl_table **t)
2647 {
if(t){cpl_table_delete((cpl_table*) (*t)); *t = NULL;}}
2673 void uves_free_property(cpl_property **p)
2674 {
if(p){cpl_property_delete(*p); *p = NULL;}}
2681 void uves_free_polynomial(cpl_polynomial **p)
2682 {
if(p){cpl_polynomial_delete(*p); *p = NULL;}}
2689 void uves_free_matrix(cpl_matrix **m)
2690 {
if(m){cpl_matrix_delete(*m); *m = NULL;}}
2697 void uves_free_parameterlist(cpl_parameterlist **p)
2698 {
if(p){cpl_parameterlist_delete(*p); *p = NULL;}}
2705 void uves_free_frameset(cpl_frameset **f)
2706 {
if(f){cpl_frameset_delete(*f); *f = NULL;}}
2713 void uves_free_frame(cpl_frame **f)
2714 {
if(f){cpl_frame_delete(*f); *f = NULL;}}
2721 void uves_free_bivector(cpl_bivector **b)
2722 {
if(b){cpl_bivector_delete(*b); *b = NULL;}}
2729 void uves_free_vector(cpl_vector **v)
2730 {
if(v){cpl_vector_delete(*v); *v = NULL;}}
2737 void uves_free_stats(cpl_stats **s)
2738 {
if(s){cpl_stats_delete(*s); *s = NULL;}}
2745 void uves_unwrap_vector(cpl_vector **v)
2746 {
if(v){cpl_vector_unwrap(*v); *v = NULL;}}
2753 void uves_unwrap_vector_const(
const cpl_vector **v)
2754 {
if(v){cpl_vector_unwrap((cpl_vector*) (*v)); *v = NULL;}}
2761 void uves_unwrap_bivector_vectors(cpl_bivector **b)
2762 {
if(b){cpl_bivector_unwrap_vectors(*b); *b = NULL;}}
2769 void uves_free_array(cpl_array **a)
2770 {
if(a){cpl_array_delete(*a); *a = NULL;}}
2778 void uves_free_int(
int **i)
2779 {
if(i){cpl_free(*i); *i = NULL;}}
2787 void uves_free_int_const(
const int **i)
2788 {
if(i){uves_free(*i); *i = NULL;}}
2795 void uves_free_float(
float **f)
2796 {
if(f){cpl_free(*f); *f = NULL;}}
2804 void uves_free_double(
double **d)
2805 {
if(d){cpl_free(*d); *d = NULL;}}
2813 void uves_free_string(
char **s)
2814 {
if(s){cpl_free(*s); *s = NULL;}}
2821 void uves_free_string_const(
const char **s)
2822 {
if(s){uves_free(*s); *s = NULL;}}
2848 get_chisq(
int N,
int D,
2849 int (*f)(
const double x[],
const double a[],
double *result),
2853 const double *sigma)
2861 for (i = 0; i < N; i++)
2865 const double *x_i = &(x[0+i*D]);
2870 &fx_i) == 0, CPL_ERROR_ILLEGAL_INPUT, -1.0);
2875 residual = (fx_i - y[i]);
2879 residual = (fx_i - y[i]) / sigma[i];
2882 chi_sq += residual*residual;
2924 get_candidate(
const double *a,
const int ia[],
2925 int M,
int N,
int D,
2927 int (*f)(
const double x[],
const double a[],
double *result),
2928 int (*dfda)(
const double x[],
const double a[],
double result[]),
2931 const double *sigma,
2948 Mfit = cpl_matrix_get_nrow(alpha);
2950 alpha_data = cpl_matrix_get_data(alpha);
2951 beta_data = cpl_matrix_get_data(beta);
2964 cpl_matrix_fill(alpha, 0.0);
2965 cpl_matrix_fill(beta , 0.0);
2967 for (k = 0; k < N; k++)
2971 const double *x_k = &(x[0+k*D]);
2979 sm2 = 1.0 / (sigma[k] * sigma[k]);
2983 cpl_ensure( f(x_k, a, &fx_k) == 0, CPL_ERROR_ILLEGAL_INPUT, -1);
2986 cpl_ensure( dfda(x_k, a, partials) == 0,
2987 CPL_ERROR_ILLEGAL_INPUT, -1);
2989 for (i = 0, imfit = 0; i < M; i++)
2995 sm2 * (y[k] - fx_k) * partials[i];
2999 for (j = 0, jmfit = 0; j < i; j++)
3003 alpha_data[jmfit + imfit*Mfit] +=
3015 alpha_data[jmfit + imfit*Mfit] +=
3017 partials[j] * (1 + lambda);
3023 assert( imfit == Mfit );
3027 for (i = 0, imfit = 0; i < M; i++)
3031 for (j = i+1, jmfit = imfit+1; j < M; j++)
3035 alpha_data[jmfit + imfit*Mfit] =
3036 alpha_data[imfit + jmfit*Mfit];
3041 assert( jmfit == Mfit );
3046 assert( imfit == Mfit );
3048 da = cpl_matrix_solve(alpha, beta);
3050 cpl_ensure(da != NULL, cpl_error_get_code(), -1);
3053 da_data = cpl_matrix_get_data(da);
3055 for (i = 0, imfit = 0; i < M; i++)
3059 a_da[i] = a[i] + da_data[0 + imfit*1];
3069 assert( imfit == Mfit );
3071 cpl_matrix_delete(da);
#define uves_msg_error(...)
Print an error message.
int uves_propertylist_get_bool(const uves_propertylist *self, const char *name)
Get the boolean value of the given property list entry.
double uves_propertylist_get_double(const uves_propertylist *self, const char *name)
Get the double value of the given property list entry.
#define passure(BOOL,...)
uves_propertylist * uves_propertylist_new(void)
Create an empty property list.
cpl_type uves_propertylist_get_type(const uves_propertylist *self, const char *name)
Get the the type of a property list entry.
const char * uves_propertylist_get_string(const uves_propertylist *self, const char *name)
Get the string value of the given property list entry.
int uves_propertylist_get_int(const uves_propertylist *self, const char *name)
Get the integer value of the given property list entry.
const char * uves_tostring_cpl_type(cpl_type t)
Convert a CPL type to a string.
#define uves_msg_low(...)
Print a message on a lower message level.
#define assure_nomsg(BOOL, CODE)
int uves_propertylist_contains(const uves_propertylist *self, const char *name)
Check whether a property is present in a property list.
void uves_propertylist_delete(const uves_propertylist *self)
Destroy a property list.
double uves_utils_get_kth_double(double *a, int n, int k)
returns the kth value of an array