62double pythag(
double ,
double );
64cpl_matrix *
svdcmp(cpl_matrix * , cpl_vector * , cpl_matrix * );
73 cpl_ensure (array, CPL_ERROR_NULL_INPUT, -1);
75 cpl_size size = cpl_array_get_size (array);
78 for (cpl_size s = 0; s < size ; s++) {
79 if (cpl_array_get (array, s, NULL) < lo_cut) {
80 cpl_array_set (array, s, lo_cut);
95 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
96 cpl_ensure (size>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
99 output = cpl_malloc (n *
sizeof(cpl_array *));
102 if ( type == CPL_TYPE_DOUBLE )
103 for ( out1 = 0 ; out1 < n ; out1++ ) {
104 output[out1] = cpl_array_new (size, type);
105 cpl_array_fill_window_double (output[out1], 0, size, 0.0);
107 else if ( type == CPL_TYPE_DOUBLE_COMPLEX )
108 for ( out1 = 0 ; out1 < n ; out1++ ) {
109 output[out1] = cpl_array_new (size, type);
110 cpl_array_fill_window_double_complex (output[out1], 0, size, 0.0 * I*0.0);
113 cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
"This type is not supported.");
114 FREE (cpl_free, output);
124 const cpl_table * from_table,
129 cpl_ensure_code (to_table, CPL_ERROR_NULL_INPUT);
130 cpl_ensure_code (to_x, CPL_ERROR_NULL_INPUT);
131 cpl_ensure_code (to_y, CPL_ERROR_NULL_INPUT);
132 cpl_ensure_code (from_table, CPL_ERROR_NULL_INPUT);
133 cpl_ensure_code (from_x, CPL_ERROR_NULL_INPUT);
134 cpl_ensure_code (from_y, CPL_ERROR_NULL_INPUT);
137 cpl_size nxref = cpl_table_get_nrow (from_table);
138 cpl_size nxout = cpl_table_get_nrow (to_table);
141 cpl_vector * xref = cpl_vector_new (nxref);
142 for (cpl_size row = 0; row < nxref; row++) {
143 cpl_vector_set (xref, row, cpl_table_get (from_table, from_x, row, NULL));
148 cpl_vector * xout = cpl_vector_new (nxout);
149 for (cpl_size row = 0; row < nxout; row++) {
150 cpl_vector_set (xout, row, cpl_table_get (to_table, to_x, row, NULL));
155 cpl_vector * yref = cpl_vector_new (nxref);
156 cpl_vector * yout = cpl_vector_new (nxout);
157 cpl_bivector * fref = cpl_bivector_wrap_vectors (xref, yref);
158 cpl_bivector * fout = cpl_bivector_wrap_vectors (xout, yout);
161 cpl_size depth = cpl_table_get_column_depth (from_table, from_y);
163 cpl_error_set_message (cpl_func,CPL_ERROR_INVALID_TYPE ,
164 "Report this error to gravity.drs");
167 const char * unit = cpl_table_get_column_unit (from_table, from_y);
171 for (cpl_size size = 0; size < depth; size++) {
174 for (cpl_size row = 0; row < nxref; row++) {
176 cpl_vector_set (yref, row, value);
181 cpl_bivector_interpolate_linear (fout, fref);
185 for (cpl_size row = 0; row < nxout; row++) {
186 double value = cpl_vector_get (yout, row);
194 FREE (cpl_bivector_delete, fref);
195 FREE (cpl_bivector_delete, fout);
198 return CPL_ERROR_NONE;
219 cpl_ensure (table, CPL_ERROR_NULL_INPUT, 0.0);
220 cpl_ensure (name, CPL_ERROR_NULL_INPUT, 0.0);
223 cpl_size valid_elem = 0;
225 cpl_size nrow = cpl_table_get_nrow (table);
226 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, 0.0);
228 cpl_type type = cpl_table_get_column_type (table, name);
229 cpl_size depth = cpl_table_get_column_depth (table, name);
231 cpl_array ** flags = cpl_table_get_data_array (table,
"FLAG");
234 cpl_array ** arrays = cpl_table_get_data_array (table, name);
235 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, 0.0);
237 cpl_size array_size = cpl_array_get_size(arrays[0]);
238 for (cpl_size r=0; r<nrow;r++)
239 for(cpl_size el=0; el<array_size; el++)
240 if (!cpl_array_get_int(flags[r], el, &valid))
242 sum += cpl_array_get_double(arrays[r], el, &valid);
246 mean = sum / valid_elem;
248 else if (depth == 0 && type == CPL_TYPE_DOUBLE) {
249 double * data = cpl_table_get_data_double (table, name);
250 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
251 cpl_size array_size = cpl_array_get_size(flags[0]);
252 for (cpl_size r=0; r<nrow;r++)
254 for(cpl_size el=0; el<array_size; el++)
256 if (!cpl_array_get_int(flags[r], el, &valid))
264 mean = mean / valid_elem;
268 cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
"unknow type");
292 cpl_ensure (table, CPL_ERROR_NULL_INPUT, 0.0);
293 cpl_ensure (name, CPL_ERROR_NULL_INPUT, 0.0);
296 cpl_size valid_elem = 0;
298 cpl_size nrow = cpl_table_get_nrow (table);
299 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, 0.0);
301 cpl_type type = cpl_table_get_column_type (table, name);
302 cpl_size depth = cpl_table_get_column_depth (table, name);
304 cpl_array ** flags = cpl_table_get_data_array (table,
"FLAG");
307 cpl_array ** arrays = cpl_table_get_data_array (table, name);
308 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, 0.0);
309 cpl_size array_size = cpl_array_get_size(arrays[0]);
310 for (cpl_size r=0; r<nrow;r++)
311 for(cpl_size el=0; el<array_size; el++)
312 if (!cpl_array_get_int(flags[r], el, &valid))
314 if(cpl_array_get_double(arrays[r], el, &valid) > max)
315 max = cpl_array_get_double(arrays[r], el, &valid);
318 else if (depth == 0 && type == CPL_TYPE_DOUBLE) {
319 double * data = cpl_table_get_data_double (table, name);
320 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
321 cpl_size array_size = cpl_array_get_size(flags[0]);
322 for (cpl_size r=0; r<nrow;r++)
324 for(cpl_size el=0; el<array_size; el++)
326 if (!cpl_array_get_int(flags[r], el, &valid))
336 cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
"unknow type");
345 cpl_ensure (table, CPL_ERROR_NULL_INPUT, 0.0);
346 cpl_ensure (name, CPL_ERROR_NULL_INPUT, 0.0);
349 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
350 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, 0.0);
352 cpl_type type = cpl_table_get_column_type (table, name);
353 cpl_size depth = cpl_table_get_column_depth (table, name);
355 if (depth == 0 && type == CPL_TYPE_DOUBLE) {
356 double * data = cpl_table_get_data_double (table, name);
357 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
358 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
360 else if (depth == 0 && type == CPL_TYPE_FLOAT) {
361 float * data = cpl_table_get_data_float (table, name);
362 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
363 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
365 else if (depth == 0 && type == CPL_TYPE_INT) {
366 int * data = cpl_table_get_data_int (table, name);
367 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
368 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
370 else if (depth > 0) {
371 cpl_array ** arrays = cpl_table_get_data_array (table, name);
372 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, 0.0);
373 cpl_array * output = cpl_array_duplicate (arrays[base]);
374 cpl_ensure (output, CPL_ERROR_ILLEGAL_INPUT, 0.0);
375 for (cpl_size r=1; r<nrow;r++)
376 cpl_array_add (output, arrays[r*nbase+base]);
377 mean = cpl_array_get_mean (output);
378 FREE (cpl_array_delete, output);
381 cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
"unknow type");
390 cpl_ensure (table, CPL_ERROR_NULL_INPUT, 0.0);
391 cpl_ensure (name, CPL_ERROR_NULL_INPUT, 0.0);
395 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
396 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, 0.0);
398 cpl_type type = cpl_table_get_column_type (table, name);
399 cpl_size depth = cpl_table_get_column_depth (table, name);
401 if (depth == 0 && type == CPL_TYPE_DOUBLE) {
402 double * data = cpl_table_get_data_double (table, name);
403 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
404 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
405 for (cpl_size r=0; r<nrow;r++) mean2 += data[r*nbase+base] * data[r*nbase+base];
407 else if (depth == 0 && type == CPL_TYPE_FLOAT) {
408 float * data = cpl_table_get_data_float (table, name);
409 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
410 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
411 for (cpl_size r=0; r<nrow;r++) mean2 += data[r*nbase+base] * data[r*nbase+base];
413 else if (depth == 0 && type == CPL_TYPE_INT) {
414 int * data = cpl_table_get_data_int (table, name);
415 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
416 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
417 for (cpl_size r=0; r<nrow;r++) mean2 += data[r*nbase+base] * data[r*nbase+base];
420 cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
"unknow type");
424 return sqrt (mean2 / nrow - mean*mean / nrow / nrow);
429 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
430 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
432 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
433 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
436 cpl_array ** arrays = cpl_table_get_data_array (table, name);
437 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, NULL);
440 cpl_array * output = cpl_array_duplicate (arrays[base]);
443 for (cpl_size r=1; r<nrow;r++)
444 cpl_array_add (output, arrays[r*nbase+base]);
451 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
452 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
454 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
455 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
458 cpl_array ** arrays = cpl_table_get_data_array (table, name);
459 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, NULL);
462 cpl_array * output = cpl_array_duplicate (arrays[base]);
465 for (cpl_size r=1; r<nrow;r++)
466 cpl_array_add (output, arrays[r*nbase+base]);
468 cpl_array_divide_scalar (output, nrow);
475 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
476 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
478 cpl_size nrow = cpl_table_get_nrow (table);
479 cpl_array ** pdata = cpl_table_get_data_array (table, name);
481 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
482 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
485 double ** data = cpl_malloc (
sizeof(
double*) * nrow);
488 for (cpl_size row=0; row<nrow; row++) {
489 data[row] = cpl_array_get_data_double (pdata[row]);
499 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
500 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
502 cpl_size nrow = cpl_table_get_nrow (table);
503 cpl_array ** pdata = cpl_table_get_data_array (table, name);
505 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
506 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
509 float ** data = cpl_malloc (
sizeof(
float*) * nrow);
512 for (cpl_size row=0; row<nrow; row++) {
513 data[row] = cpl_array_get_data_float (pdata[row]);
523 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
524 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
526 cpl_size nrow = cpl_table_get_nrow (table);
527 cpl_array ** pdata = cpl_table_get_data_array (table, name);
529 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
530 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
533 float complex ** data = cpl_malloc (
sizeof(
float complex*) * nrow);
536 for (cpl_size row=0; row<nrow; row++) {
537 data[row] = cpl_array_get_data_float_complex (pdata[row]);
548 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
549 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
551 cpl_size nrow = cpl_table_get_nrow (table);
552 cpl_array ** pdata = cpl_table_get_data_array (table, name);
554 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
555 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
558 double complex ** data = cpl_malloc (
sizeof(
double complex*) * nrow);
561 for (cpl_size row=0; row<nrow; row++) {
562 data[row] = cpl_array_get_data_double_complex (pdata[row]);
572 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
573 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
575 cpl_size nrow = cpl_table_get_nrow (table);
576 cpl_array ** pdata = cpl_table_get_data_array (table, name);
578 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
579 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
582 int ** data = cpl_malloc (
sizeof(
int*) * nrow);
585 for (cpl_size row=0; row<nrow; row++) {
586 data[row] = cpl_array_get_data_int (pdata[row]);
599 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
600 cpl_array * output = cpl_array_new (n, CPL_TYPE_DOUBLE);
601 cpl_array_fill_window_double (output, 0, n, value);
610 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
611 cpl_array * output = cpl_array_new (n, CPL_TYPE_INT);
612 cpl_array_fill_window_int (output, 0, n, value);
621 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
622 cpl_array * output = cpl_array_new (n, CPL_TYPE_DOUBLE_COMPLEX);
623 cpl_array_fill_window_double_complex (output, 0, n, value);
632 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
633 cpl_array * output = cpl_array_new (n, CPL_TYPE_FLOAT_COMPLEX);
634 cpl_array_fill_window_float_complex (output, 0, n, value);
643 cpl_ensure (input_re, CPL_ERROR_NULL_INPUT, NULL);
644 cpl_ensure (input_im, CPL_ERROR_NULL_INPUT, NULL);
646 cpl_size size_re = cpl_array_get_size (input_re);
647 cpl_size size_im = cpl_array_get_size (input_im);
649 cpl_ensure (size_re == size_im, CPL_ERROR_ILLEGAL_INPUT, NULL);
651 cpl_array * output = cpl_array_new (size_re, CPL_TYPE_DOUBLE_COMPLEX);
653 for (cpl_size n = 0; n < size_re; n ++) {
654 cpl_array_set_complex (output, n, 1.* I * cpl_array_get (input_im, n, NULL) +
655 cpl_array_get (input_re, n, NULL));
666 cpl_ensure (input_re, CPL_ERROR_NULL_INPUT, NULL);
667 cpl_ensure (input_im, CPL_ERROR_NULL_INPUT, NULL);
669 cpl_size size_re = cpl_array_get_size (input_re);
670 cpl_size size_im = cpl_array_get_size (input_im);
672 cpl_ensure (size_re == size_im, CPL_ERROR_ILLEGAL_INPUT, NULL);
674 cpl_array * output = cpl_array_new (size_re, CPL_TYPE_FLOAT_COMPLEX);
677 for (cpl_size n = 0; n < size_re; n ++) {
678 cpl_array_set_float_complex (output, n, 1.* I * cpl_array_get (input_im, n, &nv) +
679 cpl_array_get (input_re, n, &nv));
690 cpl_ensure (input_re, CPL_ERROR_NULL_INPUT, NULL);
691 cpl_ensure (input_im, CPL_ERROR_NULL_INPUT, NULL);
693 cpl_size size_re = cpl_array_get_size (input_re);
694 cpl_size size_im = cpl_array_get_size (input_im);
696 cpl_ensure (size_re == size_im, CPL_ERROR_ILLEGAL_INPUT, NULL);
698 cpl_array * output = cpl_array_new (size_re, CPL_TYPE_DOUBLE);
699 cpl_array_fill_window_double (output, 0, size_re, 0.0);
702 for (cpl_size n = 0; n < size_re; n ++) {
703 cpl_array_set_double (output, n, pow(cpl_array_get (input_im, n, &nv),2) +
704 pow(cpl_array_get (input_re, n, &nv),2) );
720 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
721 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
722 cpl_ensure_code (visR, CPL_ERROR_NULL_INPUT);
723 cpl_ensure_code (visI, CPL_ERROR_NULL_INPUT);
726 cpl_table_set_array (table, name, row, tmp_cast);
727 cpl_array_delete (tmp_cast);
731 return CPL_ERROR_NONE;
740 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
741 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
742 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
744 cpl_array * tmp_cast;
745 if (cpl_array_get_type (phase) == CPL_TYPE_FLOAT_COMPLEX ||
746 cpl_array_get_type (phase) == CPL_TYPE_DOUBLE_COMPLEX ) {
747 tmp_cast = cpl_array_cast (phase, CPL_TYPE_DOUBLE_COMPLEX);
748 cpl_array_arg (tmp_cast);
750 tmp_cast = cpl_array_cast (phase, CPL_TYPE_DOUBLE);
752 cpl_array_multiply_scalar (tmp_cast, 180.0/ CPL_MATH_PI);
753 cpl_table_set_array (table, name, row, tmp_cast);
754 cpl_array_delete (tmp_cast);
758 return CPL_ERROR_NONE;
772 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
773 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
774 cpl_ensure_code (row>-1, CPL_ERROR_ILLEGAL_INPUT);
775 cpl_ensure_code (len>0, CPL_ERROR_ILLEGAL_INPUT);
777 char * str = cpl_sprintf (
"%-*.*s", len, len, value);
778 cpl_table_set_string (table, name, row, str);
780 FREE (cpl_free, str);
784 return CPL_ERROR_NONE;
793 cpl_table * oi_wave_sc, cpl_table * oi_wave_ft)
796 cpl_ensure (input, CPL_ERROR_NULL_INPUT, NULL);
797 cpl_ensure (errs, CPL_ERROR_NULL_INPUT, NULL);
798 cpl_ensure (oi_wave_sc, CPL_ERROR_NULL_INPUT, NULL);
799 cpl_ensure (oi_wave_ft, CPL_ERROR_NULL_INPUT, NULL);
802 float *effWave_sc = cpl_table_get_data_float (oi_wave_sc,
"EFF_WAVE");
803 float *effWave_ft = cpl_table_get_data_float (oi_wave_ft,
"EFF_WAVE");
804 float *effBand_ft = cpl_table_get_data_float (oi_wave_ft,
"EFF_BAND");
805 cpl_size nwave_ft = cpl_table_get_nrow (oi_wave_ft);
806 cpl_size nwave_sc = cpl_table_get_nrow (oi_wave_sc);
810 cpl_array * output = cpl_array_new (nwave_ft, CPL_TYPE_DOUBLE);
811 cpl_array * weight = cpl_array_new (nwave_ft, CPL_TYPE_DOUBLE);
814 for (cpl_size wft = 0; wft < nwave_ft; wft++) {
815 for (cpl_size wsc = 0; wsc < nwave_sc; wsc++)
816 if ( fabs (effWave_sc[wsc] - effWave_ft[wft]) < 0.5 * effBand_ft[wft] ) {
818 double v = cpl_array_get (input, wsc, NULL);
819 double w = cpl_array_get (errs, wsc, NULL);
822 cpl_array_set (output, wft, cpl_array_get (output, wft, NULL) + v * w);
823 cpl_array_set (weight, wft, cpl_array_get (weight, wft, NULL) + w);
829 cpl_array_divide (output, weight);
830 cpl_array_delete (weight);
841 cpl_table * oi_vis2,
const char *name2)
844 cpl_ensure_code (oi_vis1, CPL_ERROR_NULL_INPUT);
845 cpl_ensure_code (oi_vis2, CPL_ERROR_NULL_INPUT);
846 cpl_ensure_code (name1, CPL_ERROR_NULL_INPUT);
847 cpl_ensure_code (name2, CPL_ERROR_NULL_INPUT);
852 cpl_type type1 = cpl_table_get_column_type (oi_vis1, name1);
853 cpl_type type2 = cpl_table_get_column_type (oi_vis2, name2);
854 cpl_size nrow1 = cpl_table_get_nrow (oi_vis1);
855 cpl_size nrow2 = cpl_table_get_nrow (oi_vis2);
858 if ( type1 != type2 || nrow1 != nrow2) {
859 return cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
860 "input columns not conformables");
863 if ( type1 == CPL_TYPE_DOUBLE ) {
864 double * data1 = cpl_table_get_data_double (oi_vis1, name1);
865 double * data2 = cpl_table_get_data_double (oi_vis2, name2);
868 for (row=0 ; row<nrow1 ; row++) data1[row] += data2[row];
870 else if ( type1 == CPL_TYPE_FLOAT_COMPLEX ) {
871 float complex * data1 = cpl_table_get_data_float_complex (oi_vis1, name1);
872 float complex * data2 = cpl_table_get_data_float_complex (oi_vis2, name2);
875 for (row=0 ; row<nrow1; row++) data1[row] += data2[row];
877 else if ( type1 == CPL_TYPE_DOUBLE_COMPLEX ) {
878 double complex * data1 = cpl_table_get_data_double_complex (oi_vis1, name1);
879 double complex * data2 = cpl_table_get_data_double_complex (oi_vis2, name2);
882 for (row=0 ; row<nrow1; row++) data1[row] += data2[row];
884 else if ( type1 & CPL_TYPE_POINTER ) {
885 cpl_array ** data1 = cpl_table_get_data_array (oi_vis1, name1);
886 cpl_array ** data2 = cpl_table_get_data_array (oi_vis2, name2);
889 for (row=0 ; row<nrow1; row++) {
890 cpl_array_add (data1[row], data2[row]);
894 return cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
895 "unknow type -- report to DRS team");
900 return CPL_ERROR_NONE;
912 const char *input_name,
913 const char *output_name,
914 int nsmooth,
int nbase)
917 cpl_ensure_code (oi_vis, CPL_ERROR_NULL_INPUT);
918 cpl_ensure_code (input_name, CPL_ERROR_NULL_INPUT);
919 cpl_ensure_code (output_name, CPL_ERROR_NULL_INPUT);
920 cpl_ensure_code (nsmooth>=0, CPL_ERROR_ILLEGAL_INPUT);
921 cpl_ensure_code (nbase>0, CPL_ERROR_ILLEGAL_INPUT);
924 int row_add, row_sub;
926 cpl_type type = cpl_table_get_column_type (oi_vis, input_name);
927 cpl_size nrow = cpl_table_get_nrow (oi_vis) / nbase;
929 if ( type == CPL_TYPE_DOUBLE ) {
930 double * data = cpl_table_get_data_double (oi_vis, input_name);
931 double * output = cpl_malloc (
sizeof(
double) * nrow * nbase);
937 for ( base=0 ; base<nbase ; base++) {
940 for ( row=-nsmooth ; row<nrow ; row++) {
941 row_add = row+nsmooth;
942 row_sub = row-nsmooth-1;
943 if ( row_add < nrow ) buffer += data[row_add * nbase + base];
944 if ( row_sub >= 0 ) buffer -= data[row_sub * nbase + base];
945 if( row>=0 && row<nrow ) output[row * nbase + base] = (double)(buffer);
952 if ( !strcmp (input_name, output_name)) {
953 for (row = 0; row < nrow * nbase; row++) data[row] = output[row];
956 if (cpl_table_has_column (oi_vis, output_name))
957 cpl_table_erase_column (oi_vis, output_name);
958 cpl_table_wrap_double (oi_vis, output, output_name);
962 else if ( type == CPL_TYPE_DOUBLE_COMPLEX ) {
963 double complex * data = cpl_table_get_data_double_complex (oi_vis, input_name);
964 double complex * output = cpl_malloc (
sizeof(
double complex) * nrow * nbase);
965 double complex buffer = 0.0;
970 for ( base=0 ; base<nbase ; base++) {
973 for ( row=-nsmooth ; row<nrow ; row++) {
974 row_add = row+nsmooth;
975 row_sub = row-nsmooth-1;
976 if ( row_add < nrow ) buffer += data[row_add * nbase + base];
977 if ( row_sub >= 0 ) buffer -= data[row_sub * nbase + base];
978 if( row>=0 && row<nrow ) output[row * nbase + base] = (
double complex)(buffer);
984 if ( !strcmp (input_name, output_name)) {
985 for (row = 0; row < nrow * nbase; row++) data[row] = output[row];
988 if (cpl_table_has_column (oi_vis, output_name))
989 cpl_table_erase_column (oi_vis, output_name);
990 cpl_table_wrap_double_complex (oi_vis, output, output_name);
995 return cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
996 "This type is not supported..."
997 "report this error to DRS team !!");
1001 return CPL_ERROR_NONE;
1005 const char *input_name,
1006 const char *output_name,
1007 int nsmooth,
int nbase)
1010 cpl_ensure_code (oi_vis, CPL_ERROR_NULL_INPUT);
1011 cpl_ensure_code (input_name, CPL_ERROR_NULL_INPUT);
1012 cpl_ensure_code (output_name, CPL_ERROR_NULL_INPUT);
1013 cpl_ensure_code (nsmooth>0, CPL_ERROR_ILLEGAL_INPUT);
1014 cpl_ensure_code (nbase>0, CPL_ERROR_ILLEGAL_INPUT);
1018 cpl_table_divide_scalar (oi_vis, output_name, 2.0*(
double)nsmooth+1.0);
1021 return CPL_ERROR_NONE;
1027 cpl_size size = cpl_table_get_nrow (oi_wave);
1028 cpl_array * sigma = cpl_array_new (size, CPL_TYPE_DOUBLE);
1030 for (cpl_size w = 0; w<size; w++ )
1031 cpl_array_set (sigma, w, 1./cpl_table_get (oi_wave,
"EFF_WAVE", w, &nv));
1033 CPLCHECK_NUL(
"Cannot compute the sigma array from EFF_WAVE");
1039 cpl_ensure (oi_wave, CPL_ERROR_NULL_INPUT, NULL);
1042 cpl_size size = cpl_table_get_nrow (oi_wave);
1043 cpl_array * wave = cpl_array_new (size, CPL_TYPE_FLOAT);
1045 for (cpl_size w = 0; w<size; w++ )
1046 cpl_array_set (wave, w, cpl_table_get (oi_wave,
"EFF_WAVE", w, &nv));
1048 CPLCHECK_NUL(
"Cannot compute the wave array from EFF_WAVE");
1055 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1058 cpl_size size = cpl_array_get_size (input);
1060 double complex cpx = 0.0 * I + 0.0;
1061 for (cpl_size wave = 0; wave<size; wave++ ) {
1062 cpx = cpl_array_get_complex (input,wave,&nv);
1063 cpl_array_set_complex (input, wave, cpx / cabs (cpx));
1064 if (nv) {cpl_array_set_invalid (input, wave); nv=0;}
1068 return CPL_ERROR_NONE;
1073 cpl_ensure (input, CPL_ERROR_NULL_INPUT, NULL);
1075 cpl_size size = cpl_array_get_size (input);
1077 cpl_array * inv = cpl_array_new (size, CPL_TYPE_DOUBLE);
1078 cpl_array_fill_window (inv, 0, size, 1.0);
1079 cpl_array_divide (inv, input);
1081 CPLCHECK_NUL(
"Cannot compute the sigma array from wave");
1090 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1092 cpl_size size_x = cpl_array_get_size (input);
1093 double phi_i, phi_ii, d_phi;
1096 for (cpl_size i_data = 1; i_data < size_x; i_data++){
1101 phi_i = cpl_array_get(input, i_data, NULL);
1102 phi_ii = cpl_array_get(input, i_data-1, NULL);
1104 d_phi = phi_i + k_wrap * 2 * M_PI - phi_ii;
1106 if (d_phi > M_PI) k_wrap --;
1107 if (d_phi < - M_PI) k_wrap ++;
1109 cpl_array_set(input, i_data, cpl_array_get(input, i_data, NULL) + k_wrap * 2 * M_PI);
1113 return CPL_ERROR_NONE;
1121 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1123 cpl_size size = cpl_array_get_size (input);
1125 for (cpl_size wave = 0; wave<size; wave++ ) {
1126 cpl_array_set (input, wave, carg (cexp ( 1.0 * I * cpl_array_get (input, wave, NULL))));
1130 return CPL_ERROR_NONE;
1139 cpl_ensure (input, CPL_ERROR_NULL_INPUT, NULL);
1141 cpl_size size = cpl_array_get_size (input);
1143 cpl_array * output = cpl_array_new (size, CPL_TYPE_DOUBLE_COMPLEX);
1144 cpl_array_fill_window_complex (output, 0, size, (
double complex)(0.0 + 0.0 * I));
1148 for (n = 0; n < size; n ++) {
1149 cpl_array_set_complex (output, n, cexp (factor * cpl_array_get (input, n, &nv) ) );
1161 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1162 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
1164 cpl_size size_in = cpl_array_get_size (input);
1165 cpl_size size_ph = cpl_array_get_size (phase);
1167 cpl_ensure_code (size_in == size_ph, CPL_ERROR_ILLEGAL_INPUT);
1171 for (n = 0; n < size_in; n ++) {
1172 cpl_array_set_complex( input, n,
1173 cpl_array_get_complex( input, n, &nv) *
1174 cexp ( factor * cpl_array_get( phase, n, &nv) ) );
1178 return CPL_ERROR_NONE;
1187 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1188 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
1190 cpl_size size_in = cpl_array_get_size (input);
1191 cpl_size size_ph = cpl_array_get_size (phase);
1193 cpl_ensure_code (size_in == size_ph, CPL_ERROR_ILLEGAL_INPUT);
1197 for (n = 0; n < size_in; n ++) {
1198 cpl_array_set_complex( input, n,
1199 cpl_array_get_complex( input, n, &nv) +
1200 cexp ( factor * cpl_array_get( phase, n, &nv) ) );
1204 return CPL_ERROR_NONE;
1213 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1214 cpl_ensure_code (add, CPL_ERROR_NULL_INPUT);
1215 cpl_ensure_code (sub, CPL_ERROR_NULL_INPUT);
1217 cpl_size size_in = cpl_array_get_size (input);
1218 cpl_size size_add = cpl_array_get_size (add);
1219 cpl_size size_sub = cpl_array_get_size (sub);
1221 cpl_ensure_code (size_in == size_add, CPL_ERROR_ILLEGAL_INPUT);
1222 cpl_ensure_code (size_in == size_sub, CPL_ERROR_ILLEGAL_INPUT);
1226 for (n = 0; n < size_in; n ++) {
1227 cpl_array_set_complex (input, n,
1228 cpl_array_get_complex (input, n, &nv) +
1229 cpl_array_get_complex (add, n, &nv) *
1230 conj (cpl_array_get_complex (sub, n, &nv)));
1234 return CPL_ERROR_NONE;
1243 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1244 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
1246 cpl_size size_in = cpl_array_get_size (input);
1247 cpl_size size_ph = cpl_array_get_size (phase);
1249 cpl_ensure_code (size_in == size_ph, CPL_ERROR_ILLEGAL_INPUT);
1251 cpl_array * tmp = cpl_array_duplicate (phase);
1253 cpl_array_multiply_scalar (tmp, factor);
1254 cpl_array_add (input, tmp);
1256 cpl_array_delete (tmp);
1259 return CPL_ERROR_NONE;
1264 cpl_ensure_code (input1, CPL_ERROR_NULL_INPUT);
1265 cpl_ensure_code (input2, CPL_ERROR_NULL_INPUT);
1267 cpl_size size_in1 = cpl_array_get_size (input1);
1268 cpl_size size_in2 = cpl_array_get_size (input2);
1270 cpl_ensure_code (size_in1 == size_in2, CPL_ERROR_ILLEGAL_INPUT);
1272 for (cpl_size w = 0 ; w < size_in1 ; w++)
1273 cpl_array_set_complex (input1, w, cpl_array_get_complex (input1, w, NULL) *
1274 conj(cpl_array_get_complex (input2, w, NULL)));
1277 return CPL_ERROR_NONE;
1287 cpl_ensure (DIT_smooth>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1288 cpl_ensure (input_array, CPL_ERROR_NULL_INPUT, NULL);
1290 cpl_type type = cpl_array_get_type (input_array);
1291 cpl_size nrow = cpl_array_get_size ( input_array );
1294 if (nrow-DIT_smooth*2-1<0) DIT_smooth=nrow/2;
1297 cpl_array * output_smooth_array;
1300 if ( type == CPL_TYPE_DOUBLE ) {
1301 double* input = cpl_array_get_data_double (input_array);
1302 double* output_smooth = cpl_malloc (nrow *
sizeof(
double));
1303 double data_carrier = 0.0;
1306 int int_carrier = 0;
1307 for (cpl_size row = - DIT_smooth; row < 0; row ++)
1309 data_carrier+=input[row+DIT_smooth];
1312 for (cpl_size row = 0; row < DIT_smooth+1; row ++)
1314 data_carrier+=input[row+DIT_smooth];
1316 output_smooth[row]=data_carrier/int_carrier;
1318 double inv_int_carrier= 1.0/int_carrier;
1319 for (cpl_size row = DIT_smooth+1; row < nrow-DIT_smooth; row ++)
1321 data_carrier-=input[row-DIT_smooth-1];
1322 data_carrier+=input[row+DIT_smooth];
1323 output_smooth[row]=data_carrier*inv_int_carrier;
1325 for (cpl_size row = nrow-DIT_smooth; row < nrow; row ++)
1327 data_carrier-=input[row-DIT_smooth-1];
1329 output_smooth[row]=data_carrier/int_carrier;
1333 output_smooth_array=cpl_array_wrap_double (output_smooth, nrow);
1335 }
else if ( type == CPL_TYPE_DOUBLE_COMPLEX ){
1336 double complex * input = cpl_array_get_data_double_complex (input_array);
1337 double complex * output_smooth = cpl_malloc (nrow *
sizeof(
double complex));
1338 double complex data_carrier = 0.0;
1341 int int_carrier = 0;
1342 for (cpl_size row = - DIT_smooth; row < 0; row ++)
1344 data_carrier+=input[row+DIT_smooth];
1347 for (cpl_size row = 0; row < DIT_smooth+1; row ++)
1349 data_carrier+=input[row+DIT_smooth];
1351 output_smooth[row]=data_carrier/int_carrier;
1353 double inv_int_carrier= 1.0/int_carrier;
1354 for (cpl_size row = DIT_smooth+1; row < nrow-DIT_smooth; row ++)
1356 data_carrier-=input[row-DIT_smooth-1];
1357 data_carrier+=input[row+DIT_smooth];
1358 output_smooth[row]=data_carrier*inv_int_carrier;
1360 for (cpl_size row = nrow-DIT_smooth; row < nrow; row ++)
1362 data_carrier-=input[row-DIT_smooth-1];
1364 output_smooth[row]=data_carrier/int_carrier;
1368 output_smooth_array=cpl_array_wrap_double_complex (output_smooth, nrow);
1372 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1373 "This type is not supported... report this error to DRS team !!");
1376 return output_smooth_array;
1406 double * gd, cpl_size nrow,
1411 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1412 cpl_ensure_code (sigma, CPL_ERROR_NULL_INPUT);
1413 cpl_ensure_code (gd, CPL_ERROR_ILLEGAL_OUTPUT);
1416 cpl_size nsigma = cpl_array_get_size (sigma);
1417 double width1, step1, width2, step2, width3, step3;
1418 cpl_size w, s, nstep1, nstep2, nstep3;
1419 double x, gd0, gd1, gd2, gd3, current_max = -1.0;
1420 double lbd = 1.0 / cpl_array_get (sigma,nsigma/2,&nv);
1423 double coherence = 0.5 * nsigma / fabs (cpl_array_get (sigma,0,&nv) - cpl_array_get (sigma,nsigma-1,&nv));
1426 width1 = CPL_MIN (coherence, max_width);
1428 nstep1 = (cpl_size)(width1/step1);
1431 width2 = 3.0 * step1;
1433 nstep2 = (cpl_size)(width2/step2);
1436 width3 = 3.0 * step2;
1438 nstep3 = (cpl_size)(width3/step3);
1442 double * sigdata = cpl_malloc (
sizeof(
double complex) * nsigma);
1443 double complex * visdata = cpl_malloc (
sizeof(
double complex) * nsigma);
1444 double complex * waveform1 = cpl_malloc (
sizeof(
double complex) * (nstep1+2) * nsigma);
1445 double complex * waveform2 = cpl_malloc (
sizeof(
double complex) * (nstep2+2) * nsigma);
1446 double complex * waveform3 = cpl_malloc (
sizeof(
double complex) * (nstep3+2) * nsigma);
1449 for (w=0; w<nsigma; w++) sigdata[w] = cpl_array_get (sigma, w, &nv);
1453 for (w=1; w<nsigma; w++) ds += sigdata[w] - sigdata[w-1];
1457 cpl_msg_debug (cpl_func,
"Build waveform for 3 pass -- %lli %lli %lli steps", nstep1, nstep2, nstep3);
1459 for (s=0, x = -width1/2.0; x < +width1/2.0; x+=step1)
1460 for (w=0; w<nsigma; w++) { waveform1[s] = cexp (-2.*I*CPL_MATH_PI * x * sigdata[w]); s++;}
1461 for (s=0, x = -width2/2.0; x < +width2/2.0; x+=step2)
1462 for (w=0; w<nsigma; w++) { waveform2[s] = cexp (-2.*I*CPL_MATH_PI * x * sigdata[w]); s++;}
1463 for (s=0, x = -width3/2.0; x < +width3/2.0; x+=step3)
1464 for (w=0; w<nsigma; w++) { waveform3[s] = cexp (-2.*I*CPL_MATH_PI * x * sigdata[w]); s++;}
1466 cpl_msg_debug (cpl_func,
"Loop on %lli rows to compute gdelay", nrow);
1469 for (cpl_size row = 0; row<nrow; row++) {
1473 for (w=0; w<nsigma; w++) {
1474 if (flag && cpl_array_get (flag[row], w, &nv)) visdata[w] = 0. + I*0.;
1475 else visdata[w] = cpl_array_get_complex (input[row], w, &nv);
1480 double complex is = 0.0 + I * 0.0;
1481 for (w=1; w<nsigma; w++) {
1482 is += visdata[w] * conj(visdata[w-1]) / CPL_MAX(cabs(visdata[w]) * cabs(visdata[w-1]), 1e-15);
1484 gd0 = carg (is) / ds / CPL_MATH_2PI;
1487 for (w=0; w<nsigma; w++) visdata[w] *= cexp (-2.*I*CPL_MATH_PI*gd0*sigdata[w]);
1490 for (current_max = -1.0, s = 0, x = -width1/2; x < +width1/2; x+=step1) {
1491 double complex tmp = 0.0 * I + 0.0;
1492 for (w=0; w<nsigma; w++) {tmp += visdata[w] * waveform1[s]; s++;}
1494 if ( P > current_max) { current_max = P; gd1 = x; }
1498 for (w=0; w<nsigma; w++) visdata[w] *= cexp (-2.*I*CPL_MATH_PI*gd1*sigdata[w]);
1501 for (current_max = -1.0, s = 0, x = -width2/2; x < +width2/2; x+=step2) {
1502 double complex tmp = 0.0 * I + 0.0;
1503 for (w=0; w<nsigma; w++) {tmp += visdata[w] * waveform2[s]; s++;}
1505 if ( P > current_max) { current_max = P; gd2 = x; }
1509 for (w=0; w<nsigma; w++) visdata[w] *= cexp (-2.*I*CPL_MATH_PI*gd2*sigdata[w]);
1512 for (current_max = -1.0, s = 0, x = -width3/2; x < +width3/2; x+=step3) {
1513 double complex tmp = 0.0 * I + 0.0;
1514 for (w=0; w<nsigma; w++) {tmp += visdata[w] * waveform3[s]; s++;}
1516 if ( P > current_max) { current_max = P; gd3 = x; }
1519 gd[row] = gd0 + gd1 + gd2 + gd3;
1525 FREE (cpl_free, visdata);
1526 FREE (cpl_free, sigdata);
1527 FREE (cpl_free, waveform1);
1528 FREE (cpl_free, waveform2);
1529 FREE (cpl_free, waveform3);
1532 return CPL_ERROR_NONE;
1538 const char *output, cpl_table * oi_wave)
1541 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1542 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1543 cpl_ensure_code (flag, CPL_ERROR_NULL_INPUT);
1544 cpl_ensure_code (output, CPL_ERROR_NULL_INPUT);
1545 cpl_ensure_code (oi_wave, CPL_ERROR_NULL_INPUT);
1548 cpl_size nwave = cpl_table_get_nrow (oi_wave);
1549 cpl_array * sigma = cpl_array_new (nwave, CPL_TYPE_DOUBLE);
1550 for (cpl_size wave = 0; wave < nwave ; wave ++)
1551 cpl_array_set (sigma, wave, 1./cpl_table_get (oi_wave,
"EFF_WAVE", wave, NULL));
1555 double * gdelay = cpl_table_get_data_double (table, output);
1558 cpl_array ** input_arrays = cpl_table_get_data_array (table, input);
1559 cpl_array ** flag_arrays = cpl_table_get_data_array (table, flag);
1560 cpl_size nrow = cpl_table_get_nrow (table);
1568 nrow, 1.e-3, CPL_TRUE);
1569 FREE (cpl_array_delete, sigma);
1572 return CPL_ERROR_NONE;
1588 cpl_ensure_code (first, CPL_ERROR_NULL_INPUT);
1589 cpl_ensure_code (second, CPL_ERROR_NULL_INPUT);
1591 cpl_size nrow = cpl_table_get_nrow (first);
1592 cpl_size ncol = cpl_table_get_ncol (first);
1595 if (nrow != cpl_table_get_nrow (second)) {
cpl_msg_info(cpl_func,
"Different rows");
return 0;}
1596 if (ncol != cpl_table_get_ncol (second)) {
cpl_msg_info(cpl_func,
"Different cols");
return 0;}
1597 if (cpl_table_compare_structure (first, second)) {
cpl_msg_info(cpl_func,
"Different structure");
return 0;}
1600 cpl_array *names = cpl_table_get_column_names (first);
1603 for (cpl_size c = 0; c<ncol; c++) {
1604 const char * name = cpl_array_get_string (names, c);
1608 int type = cpl_table_get_column_type (first, name);
1611 case CPL_TYPE_STRING:
1612 for (cpl_size r = 0; r<nrow; r++)
1613 if (strcmp (cpl_table_get_string (first, name, r),
1614 cpl_table_get_string (second, name, r) ) )
1615 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1617 case CPL_TYPE_DOUBLE:
1618 case CPL_TYPE_FLOAT:
1620 for (cpl_size r = 0; r<nrow; r++)
1621 if (cpl_table_get (first, name, r, &nv) !=
1622 cpl_table_get (second, name, r, &nv) )
1623 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1625 case CPL_TYPE_POINTER|CPL_TYPE_STRING:
1626 for (cpl_size r = 0; r<nrow; r++)
1627 for (cpl_size p = 0; p<cpl_table_get_column_depth (first,name); p++)
1628 if ( strcmp (cpl_array_get_string (cpl_table_get_array (first, name, r), p),
1629 cpl_array_get_string (cpl_table_get_array (second, name, r), p)) )
1630 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1632 case CPL_TYPE_POINTER|CPL_TYPE_DOUBLE:
1633 case CPL_TYPE_POINTER|CPL_TYPE_FLOAT:
1634 case CPL_TYPE_POINTER|CPL_TYPE_INT:
1635 for (cpl_size r = 0; r<nrow; r++)
1636 for (cpl_size p = 0; p<cpl_table_get_column_depth (first,name); p++) {
1637 if (cpl_array_get (cpl_table_get_array (first, name, r), p, NULL) !=
1638 cpl_array_get (cpl_table_get_array (second, name, r), p, NULL) )
1639 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1643 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"Cannot compare these tables (TBD, FIXME)");
1650 FREE (cpl_array_delete, names);
1658 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1659 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1661 if ( cpl_table_has_column (table, name) &&
1662 cpl_table_get_column_type (table, name) == type) {
1663 cpl_msg_info (cpl_func,
"Column %s already exists", name);
1665 cpl_table_new_column (table, name, type);
1668 if (type == CPL_TYPE_DOUBLE_COMPLEX || type == CPL_TYPE_FLOAT_COMPLEX)
1669 cpl_table_fill_column_window_complex (table, name, 0, cpl_table_get_nrow (table), 0.0 + I*0.0);
1671 cpl_table_fill_column_window (table, name, 0, cpl_table_get_nrow (table), 0.0);
1673 if (unit) cpl_table_set_column_unit (table, name, unit);
1675 return CPL_ERROR_NONE;
1680 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1681 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1683 if ( cpl_table_has_column (table, name) )
1684 cpl_table_erase_column (table, name);
1686 cpl_table_new_column_array (table, name, type, size);
1687 if (unit) cpl_table_set_column_unit (table, name, unit);
1689 return CPL_ERROR_NONE;
1694 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1695 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1697 if ( cpl_table_has_column (table, name) )
1698 cpl_table_erase_column (table, name);
1700 cpl_table_new_column_array (table, name, type, size);
1701 if (unit) cpl_table_set_column_unit (table, name, unit);
1703 cpl_array * array = cpl_array_new (size, type);
1704 cpl_array_fill_window (array, 0, size, 0.0);
1706 cpl_size nrow = cpl_table_get_nrow (table);
1707 for (cpl_size row = 0; row < nrow; row++)
1708 cpl_table_set_array (table, name, row, array);
1710 FREE (cpl_array_delete, array);
1712 return CPL_ERROR_NONE;
1729 cpl_ensure_code (imglist, CPL_ERROR_NULL_INPUT);
1731 cpl_size nrow = cpl_imagelist_get_size (imglist);
1733 for (cpl_size i = nrow-1; i>=0 ; i--) {
1734 cpl_image_unwrap (cpl_imagelist_unset (imglist, i));
1738 cpl_imagelist_delete (imglist);
1741 return CPL_ERROR_NONE;
1760 cpl_ensure (table_data, CPL_ERROR_NULL_INPUT, NULL);
1761 cpl_ensure (data_x, CPL_ERROR_NULL_INPUT, NULL);
1765 int type_column = cpl_table_get_column_type (table_data, data_x);
1768 cpl_size nrow = cpl_table_get_nrow (table_data);
1769 cpl_array ** array = cpl_table_get_data_array (table_data, data_x);
1770 cpl_ensure (array, CPL_ERROR_ILLEGAL_INPUT, NULL);
1774 if (cpl_table_get_column_dimensions (table_data, data_x)<2) {
1775 nx = cpl_table_get_column_depth (table_data, data_x);
1778 nx = cpl_table_get_column_dimension (table_data, data_x, 0);
1779 ny = cpl_table_get_column_dimension (table_data, data_x, 1);
1785 cpl_imagelist * imglist = cpl_imagelist_new();
1788 switch (type_column)
1790 case CPL_TYPE_POINTER|CPL_TYPE_DOUBLE :
1792 for (cpl_size j = 0; j < nrow ; j++)
1794 img = cpl_image_wrap_double (nx, ny, cpl_array_get_data_double(array[j]));
1795 cpl_imagelist_set (imglist, img, j);
1800 case CPL_TYPE_POINTER|CPL_TYPE_INT :
1802 for (cpl_size j = 0; j < nrow ; j++)
1804 img = cpl_image_wrap_int (nx, ny, cpl_array_get_data_int(array[j]));
1805 cpl_imagelist_set (imglist, img,j);
1810 case CPL_TYPE_POINTER|CPL_TYPE_FLOAT :
1811 for (cpl_size j = 0; j < nrow ; j++)
1813 img = cpl_image_wrap_float (nx, ny, cpl_array_get_data_float(array[j]));
1814 cpl_imagelist_set (imglist, img, j);
1821 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
1822 "invalid type of image coming from %s", data_x);
1823 cpl_imagelist_delete (imglist);
1840 cpl_size llx, cpl_size lly,
1841 cpl_size urx, cpl_size ury)
1844 cpl_ensure (img, CPL_ERROR_NULL_INPUT, -1);
1848 cpl_vector * flux = cpl_vector_new ((urx-llx+1)*(ury-lly+1));
1850 for (cpl_size v = 0, x = llx; x <= urx; x++) {
1851 for (cpl_size y = lly; y <= ury; y++) {
1852 cpl_vector_set (flux, v, cpl_image_get (img, x, y, &nv));
1862 cpl_vector_multiply (flux, flux);
1864 double RMS = sqrt (cpl_vector_get_median (flux));
1865 FREE (cpl_vector_delete, flux);
1887 cpl_ensure (img, CPL_ERROR_NULL_INPUT, NULL);
1888 cpl_ensure (drop_from < drop_to, CPL_ERROR_ILLEGAL_INPUT, NULL);
1891 cpl_size nx = cpl_image_get_size_x (img);
1892 cpl_size ny = cpl_image_get_size_y (img);
1895 cpl_ensure (drop_from >0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1896 cpl_ensure (drop_to <=nx, CPL_ERROR_ILLEGAL_INPUT, NULL);
1899 cpl_mask * mask = cpl_mask_new (nx, ny);
1900 for (cpl_size y = 1; y <= ny; y++)
1901 for (cpl_size x = drop_from; x <= drop_to ; x++)
1902 cpl_mask_set (mask, x, y, CPL_BINARY_1);
1905 cpl_mask * bpm = cpl_image_set_bpm (img, mask);
1908 cpl_image * collapse = cpl_image_collapse_median_create (img, 1, 0, 0);
1911 mask = cpl_image_set_bpm (img, bpm);
1912 FREE (cpl_mask_delete, mask);
1922 const cpl_image * collapse,
1926 cpl_ensure_code (img, CPL_ERROR_NULL_INPUT);
1927 cpl_ensure_code (collapse, CPL_ERROR_NULL_INPUT);
1928 cpl_ensure_code (direction==0 || direction==1, CPL_ERROR_ILLEGAL_INPUT);
1933 cpl_size nx = cpl_image_get_size_x (img);
1934 cpl_size ny = cpl_image_get_size_y (img);
1936 if (direction == 0) {
1938 cpl_ensure_code (cpl_image_get_size_x (collapse) == nx &&
1939 cpl_image_get_size_y (collapse) == 1,
1940 CPL_ERROR_ILLEGAL_INPUT);
1942 for (cpl_size x = 0; x < nx ; x++) {
1943 double value = cpl_image_get (collapse, x+1, 1, &nv);
1944 for (cpl_size y = 0; y < ny ; y++) {
1945 cpl_image_set (img, x+1, y+1, cpl_image_get (img, x+1, y+1, &nv) - value);
1952 cpl_ensure_code (cpl_image_get_size_x (collapse) == 1 &&
1953 cpl_image_get_size_y (collapse) == ny,
1954 CPL_ERROR_ILLEGAL_INPUT);
1956 for (cpl_size y = 0; y < ny ; y++) {
1957 double value = cpl_image_get (collapse, 1, y+1, &nv);
1958 for (cpl_size x = 0; x < nx ; x++) {
1959 cpl_image_set (img, x+1, y+1, cpl_image_get (img, x+1, y+1, &nv) - value);
1966 return CPL_ERROR_NONE;
1972 cpl_size llx, cpl_size lly,
1973 cpl_size urx, cpl_size ury,
1974 cpl_size llx2, cpl_size lly2)
1977 cpl_ensure_code (img1, CPL_ERROR_NULL_INPUT);
1978 cpl_ensure_code (img2, CPL_ERROR_NULL_INPUT);
1981 cpl_size nx = cpl_image_get_size_x (img1);
1982 cpl_size ny = cpl_image_get_size_y (img1);
1984 urx = CPL_MIN (urx, nx);
1985 ury = CPL_MIN (ury, ny);
1990 for (cpl_size x=llx; x<=urx; x++) {
1991 for (cpl_size y=lly; y<=ury; y++) {
1992 cpl_image_set (img1, x, y,
1993 cpl_image_get (img1,x,y,&nv) -
1994 cpl_image_get (img2,x+llx2,y+lly2,&nv));
1999 return CPL_ERROR_NONE;
2005 cpl_size llx, cpl_size lly,
2006 cpl_size urx, cpl_size ury,
2007 cpl_size llx2, cpl_size lly2)
2010 cpl_ensure_code (img1, CPL_ERROR_NULL_INPUT);
2011 cpl_ensure_code (img2, CPL_ERROR_NULL_INPUT);
2014 cpl_size nx = cpl_image_get_size_x (img1);
2015 cpl_size ny = cpl_image_get_size_y (img1);
2016 cpl_size nx2 = cpl_image_get_size_x (img2);
2017 cpl_size ny2 = cpl_image_get_size_y (img2);
2018 cpl_msg_info(cpl_func,
"Size image 1 %lli/%lli, Size window %lli/%lli" , nx,ny,nx2,ny2);
2020 urx = CPL_MIN (urx, nx);
2021 ury = CPL_MIN (ury, ny);
2026 for (cpl_size x=llx; x<=urx; x++) {
2027 for (cpl_size y=lly; y<=ury; y++) {
2028 cpl_image_set (img1, x, y,
2029 cpl_image_get (img2,x+llx2,y+lly2,&nv));
2034 return CPL_ERROR_NONE;
2055 cpl_ensure (table_data, CPL_ERROR_NULL_INPUT, NULL);
2056 cpl_ensure (data_x, CPL_ERROR_NULL_INPUT, NULL);
2057 cpl_ensure (row < cpl_table_get_nrow (table_data), CPL_ERROR_ILLEGAL_INPUT, NULL);
2060 cpl_ensure (wrap_imglist, CPL_ERROR_ILLEGAL_INPUT, NULL);
2062 cpl_image * out_img = cpl_image_duplicate (cpl_imagelist_get (wrap_imglist, row));
2087 cpl_ensure (table_data, CPL_ERROR_NULL_INPUT, NULL);
2088 cpl_ensure (data_x, CPL_ERROR_NULL_INPUT, NULL);
2091 cpl_ensure (wrap_imglist, CPL_ERROR_ILLEGAL_INPUT, NULL);
2093 cpl_imagelist * out_imglist = cpl_imagelist_duplicate (wrap_imglist);
2116 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
2117 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
2119 cpl_size ndim = cpl_table_get_column_dimensions (table, name);
2120 cpl_array * dimension = cpl_array_new (ndim, CPL_TYPE_INT);
2121 for (cpl_size dim = 0; dim < ndim; dim++) {
2122 int value = cpl_table_get_column_dimension (table, name, dim);
2123 cpl_array_set (dimension, dim, value);
2143 cpl_ensure (img, CPL_ERROR_NULL_INPUT, NULL);
2145 cpl_type type_img = cpl_image_get_type (img);
2146 int x = cpl_image_get_size_x (img);
2147 int y = cpl_image_get_size_y (img);
2151 cpl_array * array = NULL;
2153 case CPL_TYPE_FLOAT :
2154 array = cpl_array_wrap_float (cpl_image_get_data_float(img), x*y);
2156 case CPL_TYPE_DOUBLE :
2157 array = cpl_array_wrap_double (cpl_image_get_data_double(img), x*y);
2160 array = cpl_array_wrap_int (cpl_image_get_data_int(img), x*y);
2163 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
2164 "invalid type of image");
2186 cpl_vector * vector2)
2188 cpl_ensure (vector1, CPL_ERROR_NULL_INPUT, NULL);
2190 cpl_matrix * matrix, * matrix_wrap;
2191 int size = cpl_vector_get_size(vector1);
2192 double * data1, * data2;
2194 if( vector2 != NULL ){
2195 int size2 = cpl_vector_get_size(vector2);
2196 cpl_ensure (size == size2, CPL_ERROR_ILLEGAL_INPUT, NULL);
2198 data1 = cpl_malloc(2 * size *
sizeof(
double));
2199 memcpy(data1, cpl_vector_get_data(vector1), size *
sizeof(
double));
2201 data2 = cpl_vector_get_data(vector2);
2202 memcpy(data1 + size, data2, size *
sizeof(
double));
2204 matrix_wrap = cpl_matrix_wrap(2, size, data1);
2205 matrix = cpl_matrix_transpose_create(matrix_wrap);
2207 cpl_matrix_unwrap(matrix_wrap);
2210 data1 = cpl_malloc(size *
sizeof(
double));
2211 memcpy(data1, cpl_vector_get_data(vector1), size *
sizeof(
double));
2213 matrix = cpl_matrix_wrap(size, 1, data1);
2237 const char * regname)
2240 cpl_ensure (spectrum_data, CPL_ERROR_NULL_INPUT, NULL);
2241 cpl_ensure (regname, CPL_ERROR_NULL_INPUT, NULL);
2242 cpl_ensure (index>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2245 cpl_size size = cpl_table_get_column_depth (spectrum_data, regname);
2246 cpl_ensure (index<size, CPL_ERROR_ILLEGAL_INPUT, NULL);
2249 cpl_size nrow = cpl_table_get_nrow (spectrum_data);
2250 cpl_vector * data_value = cpl_vector_new (nrow);
2255 cpl_array ** column_array = cpl_table_get_data_array (spectrum_data, regname);
2256 cpl_ensure (column_array, CPL_ERROR_ILLEGAL_INPUT, NULL);
2260 for (cpl_size row = 0; row < nrow; row ++){
2261 value = cpl_array_get (column_array[row], index, NULL);
2262 cpl_vector_set (data_value, row, value);
2264 }
else if (cpl_table_get_column_type (spectrum_data, regname)
2265 == CPL_TYPE_DOUBLE) {
2267 double * data = cpl_table_get_data_double (spectrum_data, regname);
2268 for (cpl_size row = 0; row < nrow; row++) {
2269 cpl_vector_set (data_value, row, data[row]);
2272 }
else if (cpl_table_get_column_type (spectrum_data, regname)
2275 int * data = cpl_table_get_data_int (spectrum_data, regname);
2276 for (cpl_size row = 0; row < nrow; row++) {
2277 cpl_vector_set (data_value, row, data[row]);
2281 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
2282 "This type is not supported"
2283 "(report to DRS team).");
2284 FREE (cpl_vector_delete, data_value);
2288 return (data_value);
2297 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
2298 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
2299 cpl_ensure (base>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2300 cpl_ensure (nbase>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2303 cpl_size size = cpl_table_get_column_depth (table, name);
2304 cpl_ensure (size==0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2307 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
2308 cpl_vector * vector = cpl_vector_new (nrow);
2311 cpl_type type = cpl_table_get_column_type (table, name);
2313 if (type == CPL_TYPE_DOUBLE) {
2314 double * data = cpl_table_get_data_double (table, name);
2315 for (cpl_size row = 0; row < nrow; row++)
2316 cpl_vector_set (vector, row, data[row*nbase+base]);
2318 else if (type == CPL_TYPE_FLOAT) {
2319 float * data = cpl_table_get_data_float (table, name);
2320 for (cpl_size row = 0; row < nrow; row++)
2321 cpl_vector_set (vector, row, data[row*nbase+base]);
2323 else if (type == CPL_TYPE_INT) {
2324 int * data = cpl_table_get_data_int (table, name);
2325 for (cpl_size row = 0; row < nrow; row++)
2326 cpl_vector_set (vector, row, data[row*nbase+base]);
2329 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
2330 "This type is not supported"
2331 "(report to DRS team).");
2332 FREE (cpl_vector_delete, vector);
2357 const char * regname1,
2358 const char * regname2)
2361 cpl_ensure (spectrum_data, CPL_ERROR_NULL_INPUT, NULL);
2362 cpl_ensure (regname1, CPL_ERROR_NULL_INPUT, NULL);
2363 cpl_ensure (regname2, CPL_ERROR_NULL_INPUT, NULL);
2364 cpl_ensure (index>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2367 cpl_size size1 = cpl_table_get_column_depth (spectrum_data, regname1);
2368 cpl_size size2 = cpl_table_get_column_depth (spectrum_data, regname2);
2369 cpl_ensure (index<size1, CPL_ERROR_ILLEGAL_INPUT, NULL);
2370 cpl_ensure (index<size2, CPL_ERROR_ILLEGAL_INPUT, NULL);
2373 cpl_array ** column_array1 = cpl_table_get_data_array (spectrum_data, regname1);
2374 cpl_array ** column_array2 = cpl_table_get_data_array (spectrum_data, regname2);
2375 cpl_ensure (column_array1, CPL_ERROR_ILLEGAL_INPUT, NULL);
2376 cpl_ensure (column_array2, CPL_ERROR_ILLEGAL_INPUT, NULL);
2379 cpl_size nrow = cpl_table_get_nrow (spectrum_data);
2380 cpl_vector * data_value = cpl_vector_new (nrow);
2384 for (cpl_size row = 0; row < nrow; row++){
2385 value = cpl_array_get (column_array1[row], index, NULL) - cpl_array_get (column_array2[row], index, NULL);
2386 cpl_vector_set (data_value, row, value);
2389 return (data_value);
2400 cpl_ensure_code (img, CPL_ERROR_NULL_INPUT);
2402 cpl_size nx = cpl_image_get_size_x (img);
2403 cpl_size ny = cpl_image_get_size_y (img);
2404 cpl_image_fill_window (img, 1,1,nx,ny, value);
2406 return CPL_ERROR_NONE;
2417 cpl_ensure (matrix, CPL_ERROR_NULL_INPUT, NULL);
2418 cpl_size nx = cpl_matrix_get_ncol (matrix);
2419 cpl_size ny = cpl_matrix_get_nrow (matrix);
2420 return cpl_image_wrap_double (nx, ny, cpl_matrix_get_data (matrix));
2425 cpl_ensure (matrix, CPL_ERROR_NULL_INPUT, NULL);
2426 cpl_size nx = cpl_matrix_get_ncol (matrix);
2427 cpl_size ny = cpl_matrix_get_nrow (matrix);
2429 cpl_image * image = cpl_image_new (nx,ny,CPL_TYPE_DOUBLE);
2430 for (cpl_size i = 0; i < nx; i++)
2431 for (cpl_size j = 0; j < ny; j++)
2432 cpl_image_set (image, i+1, j+1, cpl_matrix_get (matrix,j,i));
2445 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, NULL);
2446 cpl_size nx = cpl_vector_get_size (vector);
2448 return cpl_image_wrap_double (nx, ny, cpl_vector_get_data (vector));
2453 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, NULL);
2454 cpl_size nx = cpl_vector_get_size (vector);
2457 cpl_image * image = cpl_image_new (nx,ny,CPL_TYPE_DOUBLE);
2458 for (cpl_size i = 0; i < nx; i++)
2459 cpl_image_set (image, i+1, 1, cpl_vector_get (vector,i));
2479 cpl_ensure (img, CPL_ERROR_NULL_INPUT, -1);
2480 cpl_ensure (thr>0 && thr<1, CPL_ERROR_ILLEGAL_INPUT, -1);
2482 cpl_size nx = cpl_image_get_size_x (img);
2483 cpl_size ny = cpl_image_get_size_y (img);
2484 cpl_size nq = (cpl_size)(thr * nx * ny);
2486 cpl_ensure (nq>=0 && nq<=nx*ny, CPL_ERROR_ILLEGAL_INPUT, -1);
2490 cpl_vector * vect = cpl_vector_new (nx*ny);
2491 for (cpl_size ix = 0; ix < nx ; ix++)
2492 for (cpl_size iy = 0; iy < ny ; iy++)
2493 cpl_vector_set (vect, ix * ny + iy, cpl_image_get (img, ix+1, iy+1, &nv));
2496 cpl_vector_sort (vect, CPL_SORT_ASCENDING);
2497 double value = cpl_vector_get (vect, nq);
2498 cpl_vector_delete (vect);
2513 cpl_ensure (arr, CPL_ERROR_NULL_INPUT, -1);
2514 cpl_ensure (thr>0 && thr<1, CPL_ERROR_ILLEGAL_INPUT, -1);
2516 cpl_size nx = cpl_array_get_size (arr);
2517 cpl_size nq = (cpl_size)(thr * nx);
2519 cpl_ensure (nq>=0 && nq<=nx, CPL_ERROR_ILLEGAL_INPUT, -1);
2523 cpl_vector * vect = cpl_vector_new (nx);
2524 for (cpl_size ix = 0; ix < nx ; ix++)
2525 cpl_vector_set (vect, ix, cpl_array_get (arr, ix, &nv));
2528 cpl_vector_sort (vect, CPL_SORT_ASCENDING);
2529 double value = cpl_vector_get (vect, nq);
2530 cpl_vector_delete (vect);
2549 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, NULL);
2550 cpl_ensure (hw>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2552 cpl_size size = cpl_vector_get_size (vector);
2553 cpl_vector * median = NULL;
2558 median = cpl_vector_new (size);
2559 cpl_vector_fill (median, cpl_vector_get_median_const (vector));
2564 median = cpl_vector_filter_median_create (vector, hw);
2565 cpl_ensure (median, CPL_ERROR_DATA_NOT_FOUND, NULL);
2567 double * data = cpl_vector_get_data (median);
2568 cpl_ensure (data, CPL_ERROR_DATA_NOT_FOUND, NULL);
2570 for (
int i = 0; i < hw; i++) data[i] = data[hw];
2571 for (
int i = size-hw; i < size; i++) data[i] = data[size-hw-1];
2590 cpl_ensure_code (vector, CPL_ERROR_NULL_INPUT);
2593 cpl_size size = cpl_vector_get_size (vector);
2594 cpl_ensure_code (size > 0, CPL_ERROR_ILLEGAL_INPUT);
2596 double * data = cpl_vector_get_data (vector);
2597 cpl_ensure_code (data, CPL_ERROR_ILLEGAL_INPUT);
2600 for (
int i = 0; i < size; i++) data[i] = fabs (data[i]);
2602 return CPL_ERROR_NONE;
2616 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, -1);
2617 cpl_size size = cpl_vector_get_size (vector);
2620 double value = cpl_vector_get (vector, 0);
2621 for (
int s = 1; s < size; s++) {
2622 if (cpl_vector_get (vector, s) > value) {
2624 value = cpl_vector_get (vector, s);
2646 cpl_ensure (vector_in, CPL_ERROR_NULL_INPUT, 0.0);
2647 cpl_ensure (percent > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0);
2648 cpl_ensure (percent < 0.5, CPL_ERROR_ILLEGAL_INPUT, 0.0);
2649 cpl_ensure (nsigma > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0);
2652 cpl_vector * sort_vector = cpl_vector_duplicate (vector_in);
2653 cpl_vector_sort (sort_vector, CPL_SORT_ASCENDING);
2656 cpl_size size = cpl_vector_get_size (vector_in);
2657 cpl_size sizeout = size*(1-percent*2);
2658 cpl_size start = (size-sizeout)/2;
2660 cpl_vector * vector = cpl_vector_new (sizeout);
2661 for (cpl_size i = 0 ; i < sizeout ; i++)
2662 cpl_vector_set (vector, i, cpl_vector_get (sort_vector, i+start));
2665 cpl_vector * vector_med = cpl_vector_new (sizeout);
2666 double med = cpl_vector_get_median (vector);
2667 double rms = nsigma * cpl_vector_get_stdev (vector);
2669 cpl_size size_med = 0;
2670 for (cpl_size i = 0 ; i < cpl_vector_get_size (vector) ; i++)
2671 if ( (cpl_vector_get (vector, i) > med-rms) &&
2672 (cpl_vector_get (vector, i) < med+rms) ) {
2673 cpl_vector_set (vector_med, size_med, cpl_vector_get (vector, i));
2676 cpl_vector_set_size (vector_med, size_med);
2679 double output = cpl_vector_get_mean (vector_med);
2681 FREE (cpl_vector_delete, vector_med);
2682 FREE (cpl_vector_delete, sort_vector);
2698 cpl_size size = cpl_vector_get_size (vector);
2699 cpl_size newsize = size / step;
2700 cpl_vector * out = cpl_vector_new (newsize);
2702 for (
int s = 0; s < newsize; s++)
2703 cpl_vector_set (out, s, cpl_vector_get (vector, s*step+start));
2721 cpl_ensure_code (vector, CPL_ERROR_NULL_INPUT);
2722 cpl_ensure_code (ref, CPL_ERROR_NULL_INPUT);
2724 cpl_size nrow = cpl_vector_get_size (vector);
2726 double referenced, referenced_prev = 0.0;
2729 for (cpl_size row = 0 ; row < nrow; row ++) {
2730 double phase_ref = ref_to_phase * cpl_vector_get (ref, row);
2733 referenced = (cpl_vector_get (vector, row) - phase_ref);
2734 referenced = fmod (referenced, CPL_MATH_2PI);
2735 if (referenced < 0) referenced += CPL_MATH_2PI;
2738 if ( referenced - referenced_prev > CPL_MATH_PI ) wrap --;
2739 if ( referenced - referenced_prev < -CPL_MATH_PI ) wrap ++;
2740 referenced_prev = referenced;
2743 cpl_vector_set (vector, row, phase_ref + referenced + wrap * CPL_MATH_2PI);
2748 return CPL_ERROR_NONE;
2767 int base,
int nbase,
double value)
2769 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
2770 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
2771 cpl_ensure_code (nbase==1 || nbase==4 || nbase==6, CPL_ERROR_ILLEGAL_INPUT);
2772 cpl_ensure_code (base>=0 && base <nbase, CPL_ERROR_ILLEGAL_INPUT);
2774 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
2776 if (cpl_table_get_column_depth (table, name) > 0) {
2777 cpl_array ** array = cpl_table_get_data_array (table, name);
2778 for (cpl_size row = 0 ; row < nrow ; row ++) {
2779 cpl_array_multiply_scalar (array[row*nbase+base], value);
2780 CPLCHECK_MSG (
"Cannot multiply (array may not be numerical)");
2782 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_DOUBLE) {
2783 double * array = cpl_table_get_data_double (table, name);
2784 for (cpl_size row = 0 ; row < nrow ; row ++) {
2785 array[row*nbase+base] *= value;
2787 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_INT) {
2788 int * array = cpl_table_get_data_int (table, name);
2789 for (cpl_size row = 0 ; row < nrow ; row ++) {
2790 array[row*nbase+base] *= value;
2793 return cpl_error_set_message (cpl_func, CPL_ERROR_INVALID_TYPE,
2794 "Column type is not supported");
2798 return CPL_ERROR_NONE;
2817 int base,
int nbase,
double value)
2819 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
2820 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
2821 cpl_ensure_code (nbase==1 || nbase==4 || nbase==6, CPL_ERROR_ILLEGAL_INPUT);
2822 cpl_ensure_code (base>=0 && base <nbase, CPL_ERROR_ILLEGAL_INPUT);
2824 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
2826 if (cpl_table_get_column_depth (table, name) > 0) {
2827 cpl_array ** array = cpl_table_get_data_array (table, name);
2828 for (cpl_size row = 0 ; row < nrow ; row ++) {
2829 cpl_array_add_scalar (array[row*nbase+base], value);
2830 CPLCHECK_MSG (
"Cannot multiply (array may not be numerical)");
2832 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_DOUBLE) {
2833 double * array = cpl_table_get_data_double (table, name);
2834 for (cpl_size row = 0 ; row < nrow ; row ++) {
2835 array[row*nbase+base] += value;
2837 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_INT) {
2838 int * array = cpl_table_get_data_int (table, name);
2839 for (cpl_size row = 0 ; row < nrow ; row ++) {
2840 array[row*nbase+base] += value;
2843 return cpl_error_set_message (cpl_func, CPL_ERROR_INVALID_TYPE,
2844 "Column type is not supported");
2848 return CPL_ERROR_NONE;
2873 cpl_ensure (matrix, CPL_ERROR_NULL_INPUT, NULL);
2874 cpl_ensure (xref, CPL_ERROR_NULL_INPUT, NULL);
2875 cpl_ensure (xout, CPL_ERROR_NULL_INPUT, NULL);
2877 cpl_size nrow = cpl_matrix_get_nrow (matrix);
2878 cpl_size ncol = cpl_matrix_get_ncol (matrix);
2879 cpl_size nxref = cpl_vector_get_size (xref);
2880 cpl_size nxout = cpl_vector_get_size (xout);
2882 cpl_ensure (ncol == nxref, CPL_ERROR_ILLEGAL_INPUT, NULL);
2883 cpl_ensure (nxout > 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2886 cpl_matrix * outmatrix = cpl_matrix_new (nrow, nxout);
2887 cpl_vector * yref = cpl_vector_new (nxref);
2888 cpl_vector * yout = cpl_vector_new (nxout);
2889 cpl_bivector * fref = cpl_bivector_wrap_vectors (xref, yref);
2890 cpl_bivector * fout = cpl_bivector_wrap_vectors (xout, yout);
2893 for (cpl_size row = 0; row < nrow; row++) {
2894 for (cpl_size x = 0; x < nxref; x++)
2895 cpl_vector_set (yref, x, cpl_matrix_get (matrix, row, x));
2896 cpl_bivector_interpolate_linear (fout, fref);
2897 for (cpl_size x = 0; x < nxout; x++)
2898 cpl_matrix_set (outmatrix, row, x, cpl_vector_get (yout, x));
2902 FREE (cpl_bivector_unwrap_vectors, fref);
2903 FREE (cpl_bivector_unwrap_vectors, fout);
2904 FREE (cpl_vector_delete, yref);
2905 FREE (cpl_vector_delete, yout);
2925 cpl_ensure (a_in, CPL_ERROR_NULL_INPUT, NULL);
2927 cpl_size m = cpl_matrix_get_nrow (a_in);
2928 cpl_size n = cpl_matrix_get_ncol (a_in);
2930 cpl_vector * w = cpl_vector_new (n);
2931 cpl_matrix * v = cpl_matrix_new (n, n);
2937 cpl_matrix * a_out =
svdcmp (a_in, w, v);
2941 for (cpl_size ii = 0; ii < n; ii++) {
2942 if (cpl_vector_get (w, ii) < 0.1)
2943 cpl_msg_warning (cpl_func,
"Singular Value %lld = %e",
2944 ii, cpl_vector_get (w, ii));
2950 cpl_matrix * a_inv = cpl_matrix_new (n,m);
2951 double * a_inv_data = cpl_matrix_get_data (a_inv);
2953 for (cpl_size j = 0; j < m; j++) {
2954 for (cpl_size i = 0; i < n; i++){
2957 for (cpl_size ii = 0; ii < n; ii++)
2958 if (cpl_vector_get (w, ii) > 1e-15)
2959 wv_at += cpl_matrix_get (v, i, ii) /
2960 cpl_vector_get (w, ii) *
2961 cpl_matrix_get (a_out, j, ii);
2963 a_inv_data[j + i * m] = wv_at;
2968 cpl_vector_delete (w);
2969 cpl_matrix_delete (v);
2970 cpl_matrix_delete (a_out);
2982 double absa=fabs(a);
2983 double absb=fabs(b);
2985 return absa*sqrt(1.0+pow(absb/absa, 2));
2987 return (absb == 0.0 ? 0.0 : absb*sqrt(1.0+pow(absa/absb, 2)));
2995cpl_matrix *
svdcmp (cpl_matrix * a_in, cpl_vector * w, cpl_matrix * v)
2998 cpl_ensure (a_in, CPL_ERROR_NULL_INPUT, NULL);
3000 int flag, i, its, j, jj, k, l, nm, n, m;
3001 double anorm, c, f, g, h, s, scale, x, y, z;
3005 a = cpl_matrix_duplicate(a_in);
3006 m = cpl_matrix_get_nrow (a_in);
3007 n = cpl_matrix_get_ncol (a_in);
3008 rv1 = cpl_vector_new(n);
3010 g = scale = anorm = 0.0;
3011 for (i = 0; i < n; i++) {
3013 cpl_vector_set(rv1, i, scale*g);
3014 g = s = scale = 0.0;
3016 for (k = i; k < m; k++)
3017 scale += fabs(cpl_matrix_get(a, k, i));
3020 for (k = i; k < m; k++) {
3022 cpl_matrix_set (a, k, i, cpl_matrix_get(a, k, i)/scale);
3023 s += cpl_matrix_get(a, k, i) * cpl_matrix_get(a, k, i);
3025 f = cpl_matrix_get(a, i, i);
3026 g = -
SIGN(sqrt(s),f);
3028 cpl_matrix_set (a, i, i, f - g);
3029 for (j = l; j < n; j++) {
3030 for (s = 0.0, k = i; k < m; k++)
3031 s += cpl_matrix_get(a, k, i) * cpl_matrix_get(a, k, j);
3034 for (k = i; k < m; k++)
3035 cpl_matrix_set (a, k, j, cpl_matrix_get(a, k, j) +
3036 f * cpl_matrix_get(a, k, i));
3039 for (k = i; k < m; k++)
3040 cpl_matrix_set (a, k, i, cpl_matrix_get(a, k, i) * scale);
3045 cpl_vector_set(w, i, scale *g);
3047 g = s = scale = 0.0;
3048 if (i < m && i != (n - 1)) {
3049 for (k = l; k < n; k++)
3050 scale += fabs(cpl_matrix_get(a, i, k));;
3052 for (k = l; k < n; k++) {
3053 cpl_matrix_set (a, i, k, cpl_matrix_get(a, i, k) / scale);
3054 s += cpl_matrix_get(a, i, k) * cpl_matrix_get(a, i, k);
3056 f = cpl_matrix_get(a, i, l);
3057 g = -
SIGN(sqrt(s),f);
3059 cpl_matrix_set (a, i, l, f - g);
3060 for (k = l; k < n; k++)
3061 cpl_vector_set(rv1, k, cpl_matrix_get(a, i, k)/h);
3062 for (j = l; j < m; j++) {
3063 for (s = 0.0, k = l; k < n; k++)
3064 s += cpl_matrix_get(a, j, k) * cpl_matrix_get(a, i, k);
3065 for (k = l; k < n; k++)
3066 cpl_matrix_set (a, j, k, cpl_matrix_get(a, j, k) + s * cpl_vector_get(rv1, k));
3068 for (k = l; k < n; k++)
3069 cpl_matrix_set (a, i, k, cpl_matrix_get(a, i, k) * scale);
3073 anorm = fmax(anorm,(fabs(cpl_vector_get(w, i)) +
3074 fabs(cpl_vector_get(rv1, i))));
3078 for (i = (n - 1); i >= 0; i--) {
3081 for (j = l; j < n; j++)
3082 cpl_matrix_set(v, j, i, (cpl_matrix_get(a, i, j) /
3083 cpl_matrix_get(a, i, l)) / g);
3085 for (j = l;j < n; j++) {
3086 for (s = 0.0, k = l; k < n; k++)
3087 s += cpl_matrix_get(a, i, k) * cpl_matrix_get(v, k, j);
3089 for (k = l; k < n; k++)
3090 cpl_matrix_set(v, k, j, cpl_matrix_get(v, k, j) + s *
3091 cpl_matrix_get(v, k, i));
3095 for (j = l; j < n; j++) {
3096 cpl_matrix_set(v, i, j, 0.0);
3097 cpl_matrix_set(v, j, i, 0.0);
3100 cpl_matrix_set(v, i, i, 1.0);
3102 g = cpl_vector_get(rv1, i);
3106 for (i = (
IMIN(m,n) - 1); i >= 0; i--) {
3108 g = cpl_vector_get(w, i);
3109 for (j = l; j < n; j++)
3110 cpl_matrix_set(a, i, j, 0.0);
3114 for (j = l; j < n; j++) {
3115 for (s = 0.0, k = l; k < m; k++)
3116 s += cpl_matrix_get(a, k, i) * cpl_matrix_get(a, k, j);
3118 f = (s / cpl_matrix_get(a, i, i)) * g;
3120 for (k = i; k < m; k++)
3121 cpl_matrix_set(a, k, j, cpl_matrix_get(a, k, j) + f *
3122 cpl_matrix_get(a, k, i));
3125 for (j = i; j < m; j++)
3126 cpl_matrix_set(a, j, i, cpl_matrix_get(a, j, i) * g);
3130 for (j = i; j < m; j++)
3131 cpl_matrix_set(a, j, i, 0.0);
3133 cpl_matrix_set(a, i, i, cpl_matrix_get(a, i, i) + 1);
3137 for (k = (n - 1); k >= 0; k--) {
3138 for (its = 1; its <= 60; its ++) {
3141 for (l = k; l >= 0; l--) {
3143 if ((fabs(cpl_vector_get(rv1, l)) + anorm) == anorm) {
3147 if ((fabs(cpl_vector_get(w, nm)) + anorm) == anorm)
3154 for (i = l; i <= k; i++) {
3155 f = s * cpl_vector_get(rv1, i);
3156 cpl_vector_set(rv1, i, c * cpl_vector_get(rv1, i));
3157 if ((fabs(f) + anorm) == anorm)
3159 g = cpl_vector_get(w, i);
3161 cpl_vector_set(w, i, h);
3165 for (j = 0; j < m; j++) {
3166 y = cpl_matrix_get(a, j, nm);
3167 z = cpl_matrix_get(a, j, i);
3168 cpl_matrix_set(a, j, nm, y*c+z*s);
3169 cpl_matrix_set(a, j, i, z*c-y*s);
3173 z = cpl_vector_get(w, k);
3176 cpl_vector_set(w, k, -z);
3177 for (j = 0; j < n; j++)
3178 cpl_matrix_set(v, j, k, -cpl_matrix_get(v, j, k));
3185 cpl_error_set_message(cpl_func,
3186 CPL_ERROR_ILLEGAL_INPUT,
3187 "no convergence in 120 svdcmp iterations");
3188 cpl_vector_delete(rv1);
3189 cpl_matrix_delete(a);
3192 x = cpl_vector_get(w, l);
3194 y = cpl_vector_get(w, nm); ;
3195 g = cpl_vector_get(rv1, nm);
3196 h = cpl_vector_get(rv1, k);
3197 f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y);
3199 f = ((x - z) * (x + z) + h * ((y / (f +
SIGN(g, f))) - h)) / x;
3201 for (j = l; j < nm; j++) {
3203 g = cpl_vector_get(rv1, i);
3204 y = cpl_vector_get(w, i);
3208 cpl_vector_set(rv1, j, z);
3215 for (jj = 0; jj < n; jj++) {
3216 x = cpl_matrix_get(v, jj, j);
3217 z=cpl_matrix_get(v, jj, i);
3218 cpl_matrix_set(v, jj, j, x*c+z*s);
3219 cpl_matrix_set(v, jj, i, z*c-x*s);
3222 cpl_vector_set(w, j, z);
3231 for (jj = 0; jj < m; jj++) {
3232 y = cpl_matrix_get(a, jj, j);
3233 z = cpl_matrix_get(a, jj, i);
3234 cpl_matrix_set(a, jj, j, y*c+z*s);
3235 cpl_matrix_set(a, jj, i, z*c-y*s);
3238 cpl_vector_set(rv1, l, 0.0);
3239 cpl_vector_set(rv1, k, f);
3240 cpl_vector_set(w, k, x);
3244 cpl_vector_delete(rv1);
3264 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
3267 cpl_table_select_all (table);
3268 cpl_table_and_selected_double (table,
"TIME", CPL_NOT_LESS_THAN, start);
3269 cpl_table_and_selected_double (table,
"TIME", CPL_LESS_THAN, end);
3270 cpl_table * out = cpl_table_extract_selected (table);
#define gravi_table_set_value(table, name, row, value, val)
#define gravi_table_get_value(table, name, row, value)
cpl_msg_debug(cpl_func, "Spectra has <50 pixels -> don't flat")
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
#define CPLCHECK_INT(msg)
#define gravi_msg_function_exit(flag)
#define FREE(function, variable)
#define CPLCHECK_NUL(msg)
#define gravi_msg_function_start(flag)
#define CPLCHECK_MSG(msg)
cpl_array * gravi_array_init_int(long n, int value)
double pythag(double, double)
cpl_error_code gravi_table_set_array_double_complex(cpl_table *table, const char *name, cpl_size row, cpl_array *visR, cpl_array *visI)
cpl_array * gravi_array_smooth(cpl_array *input_array, int DIT_smooth)
cpl_table * gravi_table_extract_time_interval(cpl_table *table, double start, double end)
Extract rows from table based on the TIME column.
cpl_error_code gravi_table_smooth_column(cpl_table *oi_vis, const char *input_name, const char *output_name, int nsmooth, int nbase)
cpl_error_code gravi_table_add_columns(cpl_table *oi_vis1, const char *name1, cpl_table *oi_vis2, const char *name2)
float complex ** gravi_table_get_data_array_float_complex(cpl_table *table, const char *name)
cpl_error_code gravi_table_runint_column(cpl_table *oi_vis, const char *input_name, const char *output_name, int nsmooth, int nbase)
cpl_vector * gravi_vector_extract(const cpl_vector *vector, int start, int step)
Extract part of a vector.
double gravi_table_get_column_flagged_mean(cpl_table *table, const char *name)
Function to compute the mean of a column table with arrays.
double gravi_image_get_noise_window(cpl_image *img, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury)
Estimate the median noise in a window. This noise is estimated as the median{img**2}**0....
cpl_array * gravi_array_create_inverse(cpl_array *input)
cpl_array * gravi_table_get_column_dimension(const cpl_table *table, const char *name)
Return an array ready for cpl_table_set_column_dimension.
double gravi_table_get_column_mean(cpl_table *table, const char *name, int base, int nbase)
cpl_image * gravi_image_wrap_matrix(cpl_matrix *matrix)
Wrap matrix into an image (data not duplicated)
cpl_error_code gravi_table_new_column(cpl_table *table, const char *name, const char *unit, cpl_type type)
double complex ** gravi_table_get_data_array_double_complex(cpl_table *table, const char *name)
cpl_image * gravi_image_from_vector(cpl_vector *vector)
cpl_array * gravi_array_cexp(double complex factor, const cpl_array *input)
Compute the complex exponention of an array: cexp (factor * input)
cpl_vector * gravi_table_get_vector_scalar(cpl_table *table, const char *name, cpl_size base, cpl_size nbase)
cpl_vector * gravi_table_get_vector_diff(cpl_table *spectrum_data, int index, const char *regname1, const char *regname2)
Create a vector from the row index of the column regname.
cpl_error_code gravi_table_compute_group_delay(cpl_table *table, const char *input, const char *flag, const char *output, cpl_table *oi_wave)
cpl_array * gravi_array_init_float_complex(long n, float complex value)
cpl_image * gravi_image_from_column(cpl_table *table_data, const char *data_x, cpl_size row)
Create an image from a column array in table.
cpl_error_code gravi_image_fill(cpl_image *img, double value)
Fill entire image with value.
cpl_matrix * gravi_matrix_invertSV_create(cpl_matrix *a_in)
Invers a matrix with singular value decomposition.
cpl_imagelist * gravi_imagelist_from_column(cpl_table *table_data, const char *data_x)
Create an imagelist from a column array in table.
cpl_error_code gravi_array_phase_unwrap(cpl_array *input)
cpl_error_code gravi_table_init_column_array(cpl_table *table, const char *name, const char *unit, cpl_type type, cpl_size size)
cpl_error_code gravi_array_add_phase(cpl_array *input, double factor, cpl_array *phase)
Add a REAL phase to a REAL phase array, in-place: input = input + factor * phase.
cpl_error_code gravi_vector_abs(cpl_vector *vector)
Return the running median of a vector, with special care for the boundaray, that are filled with the ...
double gravi_image_get_quantile(const cpl_image *img, double thr)
Compute the quantile of an image.
double gravi_table_get_column_flagged_max(cpl_table *table, const char *name)
Function to compute the maximum of a column table with arrays.
cpl_error_code gravi_vector_unwrap_with_guess(cpl_vector *vector, cpl_vector *ref, double ref_to_phase)
Unwrap a phase vector following a guess vector. The difference is actually unwrap and shall thus be s...
cpl_array * gravi_table_create_wave_array(cpl_table *oi_wave)
cpl_array * gravi_array_wrap_image(cpl_image *img)
Wrap the data of na image into an array.
cpl_error_code gravi_table_set_array_phase(cpl_table *table, const char *name, cpl_size row, cpl_array *phase)
cpl_array * gravi_array_init_double(long n, double value)
double ** gravi_table_get_data_array_double(cpl_table *table, const char *name)
cpl_error_code gravi_array_normalize_complex(cpl_array *input)
cpl_imagelist * gravi_imagelist_wrap_column(cpl_table *table_data, const char *data_x)
Wrap a column array of a table into an imagelist.
cpl_vector * gravi_vector_median(const cpl_vector *vector, cpl_size hw)
Return the running median of a vector, with special care for the boundaray, that are filled with the ...
cpl_error_code gravi_image_subtract_window(cpl_image *img1, const cpl_image *img2, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury, cpl_size llx2, cpl_size lly2)
double gravi_array_get_quantile(cpl_array *arr, double thr)
Compute the value of the vector corresponding to the quantile 'thr' (0 < thr < 1)
cpl_error_code gravi_imagelist_unwrap_images(cpl_imagelist *imglist)
Unwrap an imagelist an all its images.
cpl_error_code gravi_array_get_group_delay_loop(cpl_array **input, cpl_array **flag, cpl_array *sigma, double *gd, cpl_size nrow, double max_width, int verbose)
Optimized computation of GDELAY for a list of arrays.
cpl_array * gravi_table_get_column_sum_array(cpl_table *table, const char *name, int base, int nbase)
cpl_image * gravi_image_from_matrix(cpl_matrix *matrix)
cpl_error_code gravi_array_add_phasor(cpl_array *input, double complex factor, cpl_array *phase)
Add a REAL phase to a COMPLEX array, in-place: input = input + cexp (factor * phase)
cpl_matrix * gravi_matrix_interpolate_col(cpl_matrix *matrix, cpl_vector *xref, cpl_vector *xout)
Linear interpolation of matrix column.
cpl_vector * gravi_table_get_vector(cpl_table *spectrum_data, cpl_size index, const char *regname)
Create a vector from the row index of the column regname.
cpl_error_code gravi_table_set_string_fixlen(cpl_table *table, const char *name, int row, const char *value, int len)
Set string in table, ensuring fixed length (right space padding). see cpl_table_set_string.
cpl_array * gravi_array_wrap_float_complex(cpl_array *input_re, cpl_array *input_im)
cpl_array * gravi_array_compute_norm2(cpl_array *input_re, cpl_array *input_im)
int gravi_array_threshold_min(cpl_array *array, double lo_cut)
cpl_error_code gravi_image_replace_window(cpl_image *img1, const cpl_image *img2, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury, cpl_size llx2, cpl_size lly2)
cpl_matrix * svdcmp(cpl_matrix *, cpl_vector *, cpl_matrix *)
double gravi_table_get_column_std(cpl_table *table, const char *name, int base, int nbase)
cpl_array * gravi_table_get_column_mean_array(cpl_table *table, const char *name, int base, int nbase)
cpl_error_code gravi_image_subtract_collapse(cpl_image *img, const cpl_image *collapse, int direction)
cpl_image * gravi_image_wrap_vector(cpl_vector *vector)
Wrap vector into an image (data not duplicated)
cpl_array * gravi_array_rebin(const cpl_array *input, const cpl_array *errs, cpl_table *oi_wave_sc, cpl_table *oi_wave_ft)
cpl_array * gravi_table_create_sigma_array(cpl_table *oi_wave)
double gravi_vector_get_mean_clip(cpl_vector *vector_in, double percent, double nsigma)
Return the mean of a vector after extrema and RMS clipping.
cpl_error_code gravi_table_multiply_scalar(cpl_table *table, const char *name, int base, int nbase, double value)
Multiply scalar or array column by scalar.
cpl_matrix * get_matrix_from_vector(cpl_vector *vector1, cpl_vector *vector2)
Copy the content of two vector into a newly allocated 2D matrix.
cpl_error_code gravi_array_phase_wrap(cpl_array *input)
cpl_array * gravi_array_init_double_complex(long n, double complex value)
int ** gravi_table_get_data_array_int(cpl_table *table, const char *name)
cpl_array ** gravi_array_new_list(int n, cpl_type type, int size)
Allocate a list of arrays, pre-filled with 0.0.
cpl_error_code gravi_array_multiply_phasor(cpl_array *input, double complex factor, cpl_array *phase)
Multiply a REAL phase to a COMPLEX array, in-place: input = input * cexp (factor * phase)
cpl_size gravi_vector_get_maxpos(cpl_vector *vector)
Return the index of maximum in a vector. If several indexes exists with the maximum value,...
cpl_error_code gravi_table_add_scalar(cpl_table *table, const char *name, int base, int nbase, double value)
Multply scalar or array column by scalar.
cpl_error_code gravi_array_add_phasors(cpl_array *input, cpl_array *add, cpl_array *sub)
Add a pair of COMPLEX arrays to a COMPLEX array, in-place: input = input + add*conj(sub)
float ** gravi_table_get_data_array_float(cpl_table *table, const char *name)
cpl_array * gravi_array_wrap_complex(cpl_array *input_re, cpl_array *input_im)
cpl_error_code gravi_table_interpolate_column(cpl_table *to_table, const char *to_x, const char *to_y, const cpl_table *from_table, const char *from_x, const char *from_y)
cpl_error_code gravi_table_new_column_array(cpl_table *table, const char *name, const char *unit, cpl_type type, cpl_size size)
int gravi_table_are_equal(cpl_table *first, cpl_table *second)
Check if two tables have the same content.
cpl_error_code gravi_array_multiply_conj(cpl_array *input1, cpl_array *input2)
cpl_image * gravi_image_collapse_median_x(cpl_image *img, cpl_size drop_from, cpl_size drop_to)
collapse image along the x direction, droping a part of the image