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);
297 cpl_size nrow = cpl_table_get_nrow (table);
298 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, 0.0);
300 cpl_type type = cpl_table_get_column_type (table, name);
301 cpl_size depth = cpl_table_get_column_depth (table, name);
303 cpl_array ** flags = cpl_table_get_data_array (table,
"FLAG");
306 cpl_array ** arrays = cpl_table_get_data_array (table, name);
307 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, 0.0);
308 cpl_size array_size = cpl_array_get_size(arrays[0]);
309 for (cpl_size r=0; r<nrow;r++)
310 for(cpl_size el=0; el<array_size; el++)
311 if (!cpl_array_get_int(flags[r], el, &valid))
313 if(cpl_array_get_double(arrays[r], el, &valid) > max)
314 max = cpl_array_get_double(arrays[r], el, &valid);
317 else if (depth == 0 && type == CPL_TYPE_DOUBLE) {
318 double * data = cpl_table_get_data_double (table, name);
319 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
320 cpl_size array_size = cpl_array_get_size(flags[0]);
321 for (cpl_size r=0; r<nrow;r++)
323 for(cpl_size el=0; el<array_size; el++)
325 if (!cpl_array_get_int(flags[r], el, &valid))
335 cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
"unknow type");
344 cpl_ensure (table, CPL_ERROR_NULL_INPUT, 0.0);
345 cpl_ensure (name, CPL_ERROR_NULL_INPUT, 0.0);
348 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
349 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, 0.0);
351 cpl_type type = cpl_table_get_column_type (table, name);
352 cpl_size depth = cpl_table_get_column_depth (table, name);
354 if (depth == 0 && type == CPL_TYPE_DOUBLE) {
355 double * data = cpl_table_get_data_double (table, name);
356 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
357 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
359 else if (depth == 0 && type == CPL_TYPE_FLOAT) {
360 float * data = cpl_table_get_data_float (table, name);
361 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
362 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
364 else if (depth == 0 && type == CPL_TYPE_INT) {
365 int * data = cpl_table_get_data_int (table, name);
366 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
367 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
369 else if (depth > 0) {
370 cpl_array ** arrays = cpl_table_get_data_array (table, name);
371 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, 0.0);
372 cpl_array * output = cpl_array_duplicate (arrays[base]);
373 cpl_ensure (output, CPL_ERROR_ILLEGAL_INPUT, 0.0);
374 for (cpl_size r=1; r<nrow;r++)
375 cpl_array_add (output, arrays[r*nbase+base]);
376 mean = cpl_array_get_mean (output);
377 FREE (cpl_array_delete, output);
380 cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
"unknow type");
389 cpl_ensure (table, CPL_ERROR_NULL_INPUT, 0.0);
390 cpl_ensure (name, CPL_ERROR_NULL_INPUT, 0.0);
394 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
395 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, 0.0);
397 cpl_type type = cpl_table_get_column_type (table, name);
398 cpl_size depth = cpl_table_get_column_depth (table, name);
400 if (depth == 0 && type == CPL_TYPE_DOUBLE) {
401 double * data = cpl_table_get_data_double (table, name);
402 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
403 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
404 for (cpl_size r=0; r<nrow;r++) mean2 += data[r*nbase+base] * data[r*nbase+base];
406 else if (depth == 0 && type == CPL_TYPE_FLOAT) {
407 float * data = cpl_table_get_data_float (table, name);
408 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
409 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
410 for (cpl_size r=0; r<nrow;r++) mean2 += data[r*nbase+base] * data[r*nbase+base];
412 else if (depth == 0 && type == CPL_TYPE_INT) {
413 int * data = cpl_table_get_data_int (table, name);
414 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
415 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
416 for (cpl_size r=0; r<nrow;r++) mean2 += data[r*nbase+base] * data[r*nbase+base];
419 cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
"unknow type");
423 return sqrt (mean2 / nrow - mean*mean / nrow / nrow);
428 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
429 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
431 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
432 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
435 cpl_array ** arrays = cpl_table_get_data_array (table, name);
436 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, NULL);
439 cpl_array * output = cpl_array_duplicate (arrays[base]);
442 for (cpl_size r=1; r<nrow;r++)
443 cpl_array_add (output, arrays[r*nbase+base]);
450 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
451 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
453 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
454 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
457 cpl_array ** arrays = cpl_table_get_data_array (table, name);
458 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, NULL);
461 cpl_array * output = cpl_array_duplicate (arrays[base]);
464 for (cpl_size r=1; r<nrow;r++)
465 cpl_array_add (output, arrays[r*nbase+base]);
467 cpl_array_divide_scalar (output, nrow);
474 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
475 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
477 cpl_size nrow = cpl_table_get_nrow (table);
478 cpl_array ** pdata = cpl_table_get_data_array (table, name);
480 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
481 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
484 double ** data = cpl_malloc (
sizeof(
double*) * nrow);
487 for (cpl_size row=0; row<nrow; row++) {
488 data[row] = cpl_array_get_data_double (pdata[row]);
498 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
499 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
501 cpl_size nrow = cpl_table_get_nrow (table);
502 cpl_array ** pdata = cpl_table_get_data_array (table, name);
504 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
505 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
508 float ** data = cpl_malloc (
sizeof(
float*) * nrow);
511 for (cpl_size row=0; row<nrow; row++) {
512 data[row] = cpl_array_get_data_float (pdata[row]);
522 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
523 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
525 cpl_size nrow = cpl_table_get_nrow (table);
526 cpl_array ** pdata = cpl_table_get_data_array (table, name);
528 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
529 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
532 float complex ** data = cpl_malloc (
sizeof(
float complex*) * nrow);
535 for (cpl_size row=0; row<nrow; row++) {
536 data[row] = cpl_array_get_data_float_complex (pdata[row]);
547 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
548 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
550 cpl_size nrow = cpl_table_get_nrow (table);
551 cpl_array ** pdata = cpl_table_get_data_array (table, name);
553 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
554 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
557 double complex ** data = cpl_malloc (
sizeof(
double complex*) * nrow);
560 for (cpl_size row=0; row<nrow; row++) {
561 data[row] = cpl_array_get_data_double_complex (pdata[row]);
571 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
572 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
574 cpl_size nrow = cpl_table_get_nrow (table);
575 cpl_array ** pdata = cpl_table_get_data_array (table, name);
577 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
578 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
581 int ** data = cpl_malloc (
sizeof(
int*) * nrow);
584 for (cpl_size row=0; row<nrow; row++) {
585 data[row] = cpl_array_get_data_int (pdata[row]);
598 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
599 cpl_array * output = cpl_array_new (n, CPL_TYPE_DOUBLE);
600 cpl_array_fill_window_double (output, 0, n, value);
609 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
610 cpl_array * output = cpl_array_new (n, CPL_TYPE_INT);
611 cpl_array_fill_window_int (output, 0, n, value);
620 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
621 cpl_array * output = cpl_array_new (n, CPL_TYPE_DOUBLE_COMPLEX);
622 cpl_array_fill_window_double_complex (output, 0, n, value);
631 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
632 cpl_array * output = cpl_array_new (n, CPL_TYPE_FLOAT_COMPLEX);
633 cpl_array_fill_window_float_complex (output, 0, n, value);
642 cpl_ensure (input_re, CPL_ERROR_NULL_INPUT, NULL);
643 cpl_ensure (input_im, CPL_ERROR_NULL_INPUT, NULL);
645 cpl_size size_re = cpl_array_get_size (input_re);
646 cpl_size size_im = cpl_array_get_size (input_im);
648 cpl_ensure (size_re == size_im, CPL_ERROR_ILLEGAL_INPUT, NULL);
650 cpl_array * output = cpl_array_new (size_re, CPL_TYPE_DOUBLE_COMPLEX);
652 for (cpl_size n = 0; n < size_re; n ++) {
653 cpl_array_set_complex (output, n, 1.* I * cpl_array_get (input_im, n, NULL) +
654 cpl_array_get (input_re, n, NULL));
665 cpl_ensure (input_re, CPL_ERROR_NULL_INPUT, NULL);
666 cpl_ensure (input_im, CPL_ERROR_NULL_INPUT, NULL);
668 cpl_size size_re = cpl_array_get_size (input_re);
669 cpl_size size_im = cpl_array_get_size (input_im);
671 cpl_ensure (size_re == size_im, CPL_ERROR_ILLEGAL_INPUT, NULL);
673 cpl_array * output = cpl_array_new (size_re, CPL_TYPE_FLOAT_COMPLEX);
676 for (cpl_size n = 0; n < size_re; n ++) {
677 cpl_array_set_float_complex (output, n, 1.* I * cpl_array_get (input_im, n, &nv) +
678 cpl_array_get (input_re, n, &nv));
689 cpl_ensure (input_re, CPL_ERROR_NULL_INPUT, NULL);
690 cpl_ensure (input_im, CPL_ERROR_NULL_INPUT, NULL);
692 cpl_size size_re = cpl_array_get_size (input_re);
693 cpl_size size_im = cpl_array_get_size (input_im);
695 cpl_ensure (size_re == size_im, CPL_ERROR_ILLEGAL_INPUT, NULL);
697 cpl_array * output = cpl_array_new (size_re, CPL_TYPE_DOUBLE);
698 cpl_array_fill_window_double (output, 0, size_re, 0.0);
701 for (cpl_size n = 0; n < size_re; n ++) {
702 cpl_array_set_double (output, n, pow(cpl_array_get (input_im, n, &nv),2) +
703 pow(cpl_array_get (input_re, n, &nv),2) );
719 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
720 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
721 cpl_ensure_code (visR, CPL_ERROR_NULL_INPUT);
722 cpl_ensure_code (visI, CPL_ERROR_NULL_INPUT);
725 cpl_table_set_array (table, name, row, tmp_cast);
726 cpl_array_delete (tmp_cast);
730 return CPL_ERROR_NONE;
739 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
740 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
741 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
743 cpl_array * tmp_cast;
744 if (cpl_array_get_type (phase) == CPL_TYPE_FLOAT_COMPLEX ||
745 cpl_array_get_type (phase) == CPL_TYPE_DOUBLE_COMPLEX ) {
746 tmp_cast = cpl_array_cast (phase, CPL_TYPE_DOUBLE_COMPLEX);
747 cpl_array_arg (tmp_cast);
749 tmp_cast = cpl_array_cast (phase, CPL_TYPE_DOUBLE);
751 cpl_array_multiply_scalar (tmp_cast, 180.0/ CPL_MATH_PI);
752 cpl_table_set_array (table, name, row, tmp_cast);
753 cpl_array_delete (tmp_cast);
757 return CPL_ERROR_NONE;
771 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
772 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
773 cpl_ensure_code (row>-1, CPL_ERROR_ILLEGAL_INPUT);
774 cpl_ensure_code (len>0, CPL_ERROR_ILLEGAL_INPUT);
776 char * str = cpl_sprintf (
"%-*.*s", len, len, value);
777 cpl_table_set_string (table, name, row, str);
779 FREE (cpl_free, str);
783 return CPL_ERROR_NONE;
792 cpl_table * oi_wave_sc, cpl_table * oi_wave_ft)
795 cpl_ensure (input, CPL_ERROR_NULL_INPUT, NULL);
796 cpl_ensure (errs, CPL_ERROR_NULL_INPUT, NULL);
797 cpl_ensure (oi_wave_sc, CPL_ERROR_NULL_INPUT, NULL);
798 cpl_ensure (oi_wave_ft, CPL_ERROR_NULL_INPUT, NULL);
801 float *effWave_sc = cpl_table_get_data_float (oi_wave_sc,
"EFF_WAVE");
802 float *effWave_ft = cpl_table_get_data_float (oi_wave_ft,
"EFF_WAVE");
803 float *effBand_ft = cpl_table_get_data_float (oi_wave_ft,
"EFF_BAND");
804 cpl_size nwave_ft = cpl_table_get_nrow (oi_wave_ft);
805 cpl_size nwave_sc = cpl_table_get_nrow (oi_wave_sc);
809 cpl_array * output = cpl_array_new (nwave_ft, CPL_TYPE_DOUBLE);
810 cpl_array * weight = cpl_array_new (nwave_ft, CPL_TYPE_DOUBLE);
813 for (cpl_size wft = 0; wft < nwave_ft; wft++) {
814 for (cpl_size wsc = 0; wsc < nwave_sc; wsc++)
815 if ( fabs (effWave_sc[wsc] - effWave_ft[wft]) < 0.5 * effBand_ft[wft] ) {
817 double v = cpl_array_get (input, wsc, NULL);
818 double w = cpl_array_get (errs, wsc, NULL);
821 cpl_array_set (output, wft, cpl_array_get (output, wft, NULL) + v * w);
822 cpl_array_set (weight, wft, cpl_array_get (weight, wft, NULL) + w);
828 cpl_array_divide (output, weight);
829 cpl_array_delete (weight);
840 cpl_table * oi_vis2,
const char *name2)
843 cpl_ensure_code (oi_vis1, CPL_ERROR_NULL_INPUT);
844 cpl_ensure_code (oi_vis2, CPL_ERROR_NULL_INPUT);
845 cpl_ensure_code (name1, CPL_ERROR_NULL_INPUT);
846 cpl_ensure_code (name2, CPL_ERROR_NULL_INPUT);
851 cpl_type type1 = cpl_table_get_column_type (oi_vis1, name1);
852 cpl_type type2 = cpl_table_get_column_type (oi_vis2, name2);
853 cpl_size nrow1 = cpl_table_get_nrow (oi_vis1);
854 cpl_size nrow2 = cpl_table_get_nrow (oi_vis2);
857 if ( type1 != type2 || nrow1 != nrow2) {
858 return cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
859 "input columns not conformables");
862 if ( type1 == CPL_TYPE_DOUBLE ) {
863 double * data1 = cpl_table_get_data_double (oi_vis1, name1);
864 double * data2 = cpl_table_get_data_double (oi_vis2, name2);
867 for (row=0 ; row<nrow1 ; row++) data1[row] += data2[row];
869 else if ( type1 == CPL_TYPE_FLOAT_COMPLEX ) {
870 float complex * data1 = cpl_table_get_data_float_complex (oi_vis1, name1);
871 float complex * data2 = cpl_table_get_data_float_complex (oi_vis2, name2);
874 for (row=0 ; row<nrow1; row++) data1[row] += data2[row];
876 else if ( type1 == CPL_TYPE_DOUBLE_COMPLEX ) {
877 double complex * data1 = cpl_table_get_data_double_complex (oi_vis1, name1);
878 double complex * data2 = cpl_table_get_data_double_complex (oi_vis2, name2);
881 for (row=0 ; row<nrow1; row++) data1[row] += data2[row];
883 else if ( type1 & CPL_TYPE_POINTER ) {
884 cpl_array ** data1 = cpl_table_get_data_array (oi_vis1, name1);
885 cpl_array ** data2 = cpl_table_get_data_array (oi_vis2, name2);
888 for (row=0 ; row<nrow1; row++) {
889 cpl_array_add (data1[row], data2[row]);
893 return cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
894 "unknow type -- report to DRS team");
899 return CPL_ERROR_NONE;
911 const char *input_name,
912 const char *output_name,
913 int nsmooth,
int nbase)
916 cpl_ensure_code (oi_vis, CPL_ERROR_NULL_INPUT);
917 cpl_ensure_code (input_name, CPL_ERROR_NULL_INPUT);
918 cpl_ensure_code (output_name, CPL_ERROR_NULL_INPUT);
919 cpl_ensure_code (nsmooth>=0, CPL_ERROR_ILLEGAL_INPUT);
920 cpl_ensure_code (nbase>0, CPL_ERROR_ILLEGAL_INPUT);
923 int row_add, row_sub;
925 cpl_type type = cpl_table_get_column_type (oi_vis, input_name);
926 cpl_size nrow = cpl_table_get_nrow (oi_vis) / nbase;
928 if ( type == CPL_TYPE_DOUBLE ) {
929 double * data = cpl_table_get_data_double (oi_vis, input_name);
930 double * output = cpl_malloc (
sizeof(
double) * nrow * nbase);
936 for ( base=0 ; base<nbase ; base++) {
939 for ( row=-nsmooth ; row<nrow ; row++) {
940 row_add = row+nsmooth;
941 row_sub = row-nsmooth-1;
942 if ( row_add < nrow ) buffer += data[row_add * nbase + base];
943 if ( row_sub >= 0 ) buffer -= data[row_sub * nbase + base];
944 if( row>=0 && row<nrow ) output[row * nbase + base] = (double)(buffer);
951 if ( !strcmp (input_name, output_name)) {
952 for (row = 0; row < nrow * nbase; row++) data[row] = output[row];
955 if (cpl_table_has_column (oi_vis, output_name))
956 cpl_table_erase_column (oi_vis, output_name);
957 cpl_table_wrap_double (oi_vis, output, output_name);
961 else if ( type == CPL_TYPE_DOUBLE_COMPLEX ) {
962 double complex * data = cpl_table_get_data_double_complex (oi_vis, input_name);
963 double complex * output = cpl_malloc (
sizeof(
double complex) * nrow * nbase);
964 double complex buffer = 0.0;
969 for ( base=0 ; base<nbase ; base++) {
972 for ( row=-nsmooth ; row<nrow ; row++) {
973 row_add = row+nsmooth;
974 row_sub = row-nsmooth-1;
975 if ( row_add < nrow ) buffer += data[row_add * nbase + base];
976 if ( row_sub >= 0 ) buffer -= data[row_sub * nbase + base];
977 if( row>=0 && row<nrow ) output[row * nbase + base] = (
double complex)(buffer);
983 if ( !strcmp (input_name, output_name)) {
984 for (row = 0; row < nrow * nbase; row++) data[row] = output[row];
987 if (cpl_table_has_column (oi_vis, output_name))
988 cpl_table_erase_column (oi_vis, output_name);
989 cpl_table_wrap_double_complex (oi_vis, output, output_name);
994 return cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
995 "This type is not supported..."
996 "report this error to DRS team !!");
1000 return CPL_ERROR_NONE;
1004 const char *input_name,
1005 const char *output_name,
1006 int nsmooth,
int nbase)
1009 cpl_ensure_code (oi_vis, CPL_ERROR_NULL_INPUT);
1010 cpl_ensure_code (input_name, CPL_ERROR_NULL_INPUT);
1011 cpl_ensure_code (output_name, CPL_ERROR_NULL_INPUT);
1012 cpl_ensure_code (nsmooth>0, CPL_ERROR_ILLEGAL_INPUT);
1013 cpl_ensure_code (nbase>0, CPL_ERROR_ILLEGAL_INPUT);
1017 cpl_table_divide_scalar (oi_vis, output_name, 2.0*(
double)nsmooth+1.0);
1020 return CPL_ERROR_NONE;
1026 cpl_size size = cpl_table_get_nrow (oi_wave);
1027 cpl_array * sigma = cpl_array_new (size, CPL_TYPE_DOUBLE);
1029 for (cpl_size w = 0; w<size; w++ )
1030 cpl_array_set (sigma, w, 1./cpl_table_get (oi_wave,
"EFF_WAVE", w, &nv));
1032 CPLCHECK_NUL(
"Cannot compute the sigma array from EFF_WAVE");
1038 cpl_ensure (oi_wave, CPL_ERROR_NULL_INPUT, NULL);
1041 cpl_size size = cpl_table_get_nrow (oi_wave);
1042 cpl_array * wave = cpl_array_new (size, CPL_TYPE_FLOAT);
1044 for (cpl_size w = 0; w<size; w++ )
1045 cpl_array_set (wave, w, cpl_table_get (oi_wave,
"EFF_WAVE", w, &nv));
1047 CPLCHECK_NUL(
"Cannot compute the wave array from EFF_WAVE");
1054 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1057 cpl_size size = cpl_array_get_size (input);
1059 double complex cpx = 0.0 * I + 0.0;
1060 for (cpl_size wave = 0; wave<size; wave++ ) {
1061 cpx = cpl_array_get_complex (input,wave,&nv);
1062 cpl_array_set_complex (input, wave, cpx / cabs (cpx));
1063 if (nv) {cpl_array_set_invalid (input, wave); nv=0;}
1067 return CPL_ERROR_NONE;
1072 cpl_ensure (input, CPL_ERROR_NULL_INPUT, NULL);
1074 cpl_size size = cpl_array_get_size (input);
1076 cpl_array * inv = cpl_array_new (size, CPL_TYPE_DOUBLE);
1077 cpl_array_fill_window (inv, 0, size, 1.0);
1078 cpl_array_divide (inv, input);
1080 CPLCHECK_NUL(
"Cannot compute the sigma array from wave");
1089 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1091 cpl_size size_x = cpl_array_get_size (input);
1092 double phi_i, phi_ii, d_phi;
1095 for (cpl_size i_data = 1; i_data < size_x; i_data++){
1100 phi_i = cpl_array_get(input, i_data, NULL);
1101 phi_ii = cpl_array_get(input, i_data-1, NULL);
1103 d_phi = phi_i + k_wrap * 2 * M_PI - phi_ii;
1105 if (d_phi > M_PI) k_wrap --;
1106 if (d_phi < - M_PI) k_wrap ++;
1108 cpl_array_set(input, i_data, cpl_array_get(input, i_data, NULL) + k_wrap * 2 * M_PI);
1112 return CPL_ERROR_NONE;
1120 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1122 cpl_size size = cpl_array_get_size (input);
1124 for (cpl_size wave = 0; wave<size; wave++ ) {
1125 cpl_array_set (input, wave, carg (cexp ( 1.0 * I * cpl_array_get (input, wave, NULL))));
1129 return CPL_ERROR_NONE;
1138 cpl_ensure (input, CPL_ERROR_NULL_INPUT, NULL);
1140 cpl_size size = cpl_array_get_size (input);
1142 cpl_array * output = cpl_array_new (size, CPL_TYPE_DOUBLE_COMPLEX);
1143 cpl_array_fill_window_complex (output, 0, size, (
double complex)(0.0 + 0.0 * I));
1147 for (n = 0; n < size; n ++) {
1148 cpl_array_set_complex (output, n, cexp (factor * cpl_array_get (input, n, &nv) ) );
1160 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1161 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
1163 cpl_size size_in = cpl_array_get_size (input);
1164 cpl_size size_ph = cpl_array_get_size (phase);
1166 cpl_ensure_code (size_in == size_ph, CPL_ERROR_ILLEGAL_INPUT);
1170 for (n = 0; n < size_in; n ++) {
1171 cpl_array_set_complex( input, n,
1172 cpl_array_get_complex( input, n, &nv) *
1173 cexp ( factor * cpl_array_get( phase, n, &nv) ) );
1177 return CPL_ERROR_NONE;
1186 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1187 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
1189 cpl_size size_in = cpl_array_get_size (input);
1190 cpl_size size_ph = cpl_array_get_size (phase);
1192 cpl_ensure_code (size_in == size_ph, CPL_ERROR_ILLEGAL_INPUT);
1196 for (n = 0; n < size_in; n ++) {
1197 cpl_array_set_complex( input, n,
1198 cpl_array_get_complex( input, n, &nv) +
1199 cexp ( factor * cpl_array_get( phase, n, &nv) ) );
1203 return CPL_ERROR_NONE;
1212 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1213 cpl_ensure_code (add, CPL_ERROR_NULL_INPUT);
1214 cpl_ensure_code (sub, CPL_ERROR_NULL_INPUT);
1216 cpl_size size_in = cpl_array_get_size (input);
1217 cpl_size size_add = cpl_array_get_size (add);
1218 cpl_size size_sub = cpl_array_get_size (sub);
1220 cpl_ensure_code (size_in == size_add, CPL_ERROR_ILLEGAL_INPUT);
1221 cpl_ensure_code (size_in == size_sub, CPL_ERROR_ILLEGAL_INPUT);
1225 for (n = 0; n < size_in; n ++) {
1226 cpl_array_set_complex (input, n,
1227 cpl_array_get_complex (input, n, &nv) +
1228 cpl_array_get_complex (add, n, &nv) *
1229 conj (cpl_array_get_complex (sub, n, &nv)));
1233 return CPL_ERROR_NONE;
1242 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1243 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
1245 cpl_size size_in = cpl_array_get_size (input);
1246 cpl_size size_ph = cpl_array_get_size (phase);
1248 cpl_ensure_code (size_in == size_ph, CPL_ERROR_ILLEGAL_INPUT);
1250 cpl_array * tmp = cpl_array_duplicate (phase);
1252 cpl_array_multiply_scalar (tmp, factor);
1253 cpl_array_add (input, tmp);
1255 cpl_array_delete (tmp);
1258 return CPL_ERROR_NONE;
1263 cpl_ensure_code (input1, CPL_ERROR_NULL_INPUT);
1264 cpl_ensure_code (input2, CPL_ERROR_NULL_INPUT);
1266 cpl_size size_in1 = cpl_array_get_size (input1);
1267 cpl_size size_in2 = cpl_array_get_size (input2);
1269 cpl_ensure_code (size_in1 == size_in2, CPL_ERROR_ILLEGAL_INPUT);
1271 for (cpl_size w = 0 ; w < size_in1 ; w++)
1272 cpl_array_set_complex (input1, w, cpl_array_get_complex (input1, w, NULL) *
1273 conj(cpl_array_get_complex (input2, w, NULL)));
1276 return CPL_ERROR_NONE;
1286 cpl_ensure (DIT_smooth>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1287 cpl_ensure (input_array, CPL_ERROR_NULL_INPUT, NULL);
1289 cpl_type type = cpl_array_get_type (input_array);
1290 cpl_size nrow = cpl_array_get_size ( input_array );
1293 if (nrow-DIT_smooth*2-1<0) DIT_smooth=nrow/2;
1296 cpl_array * output_smooth_array;
1299 if ( type == CPL_TYPE_DOUBLE ) {
1300 double* input = cpl_array_get_data_double (input_array);
1301 double* output_smooth = cpl_malloc (nrow *
sizeof(
double));
1302 double data_carrier = 0.0;
1305 int int_carrier = 0;
1306 for (cpl_size row = - DIT_smooth; row < 0; row ++)
1308 data_carrier+=input[row+DIT_smooth];
1311 for (cpl_size row = 0; row < DIT_smooth+1; row ++)
1313 data_carrier+=input[row+DIT_smooth];
1315 output_smooth[row]=data_carrier/int_carrier;
1317 double inv_int_carrier= 1.0/int_carrier;
1318 for (cpl_size row = DIT_smooth+1; row < nrow-DIT_smooth; row ++)
1320 data_carrier-=input[row-DIT_smooth-1];
1321 data_carrier+=input[row+DIT_smooth];
1322 output_smooth[row]=data_carrier*inv_int_carrier;
1324 for (cpl_size row = nrow-DIT_smooth; row < nrow; row ++)
1326 data_carrier-=input[row-DIT_smooth-1];
1328 output_smooth[row]=data_carrier/int_carrier;
1332 output_smooth_array=cpl_array_wrap_double (output_smooth, nrow);
1334 }
else if ( type == CPL_TYPE_DOUBLE_COMPLEX ){
1335 double complex * input = cpl_array_get_data_double_complex (input_array);
1336 double complex * output_smooth = cpl_malloc (nrow *
sizeof(
double complex));
1337 double complex data_carrier = 0.0;
1340 int int_carrier = 0;
1341 for (cpl_size row = - DIT_smooth; row < 0; row ++)
1343 data_carrier+=input[row+DIT_smooth];
1346 for (cpl_size row = 0; row < DIT_smooth+1; row ++)
1348 data_carrier+=input[row+DIT_smooth];
1350 output_smooth[row]=data_carrier/int_carrier;
1352 double inv_int_carrier= 1.0/int_carrier;
1353 for (cpl_size row = DIT_smooth+1; row < nrow-DIT_smooth; row ++)
1355 data_carrier-=input[row-DIT_smooth-1];
1356 data_carrier+=input[row+DIT_smooth];
1357 output_smooth[row]=data_carrier*inv_int_carrier;
1359 for (cpl_size row = nrow-DIT_smooth; row < nrow; row ++)
1361 data_carrier-=input[row-DIT_smooth-1];
1363 output_smooth[row]=data_carrier/int_carrier;
1367 output_smooth_array=cpl_array_wrap_double_complex (output_smooth, nrow);
1371 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1372 "This type is not supported... report this error to DRS team !!");
1375 return output_smooth_array;
1405 double * gd, cpl_size nrow,
1410 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1411 cpl_ensure_code (sigma, CPL_ERROR_NULL_INPUT);
1412 cpl_ensure_code (gd, CPL_ERROR_ILLEGAL_OUTPUT);
1415 cpl_size nsigma = cpl_array_get_size (sigma);
1416 double width1, step1, width2, step2, width3, step3;
1417 cpl_size w, s, nstep1, nstep2, nstep3;
1418 double x, gd0, gd1, gd2, gd3, current_max = -1.0;
1419 double lbd = 1.0 / cpl_array_get (sigma,nsigma/2,&nv);
1422 double coherence = 0.5 * nsigma / fabs (cpl_array_get (sigma,0,&nv) - cpl_array_get (sigma,nsigma-1,&nv));
1425 width1 = CPL_MIN (coherence, max_width);
1427 nstep1 = (cpl_size)(width1/step1);
1430 width2 = 3.0 * step1;
1432 nstep2 = (cpl_size)(width2/step2);
1435 width3 = 3.0 * step2;
1437 nstep3 = (cpl_size)(width3/step3);
1441 double * sigdata = cpl_malloc (
sizeof(
double complex) * nsigma);
1442 double complex * visdata = cpl_malloc (
sizeof(
double complex) * nsigma);
1443 double complex * waveform1 = cpl_malloc (
sizeof(
double complex) * (nstep1+2) * nsigma);
1444 double complex * waveform2 = cpl_malloc (
sizeof(
double complex) * (nstep2+2) * nsigma);
1445 double complex * waveform3 = cpl_malloc (
sizeof(
double complex) * (nstep3+2) * nsigma);
1448 for (w=0; w<nsigma; w++) sigdata[w] = cpl_array_get (sigma, w, &nv);
1452 for (w=1; w<nsigma; w++) ds += sigdata[w] - sigdata[w-1];
1456 cpl_msg_debug (cpl_func,
"Build waveform for 3 pass -- %lli %lli %lli steps", nstep1, nstep2, nstep3);
1458 for (s=0, x = -width1/2.0; x < +width1/2.0; x+=step1)
1459 for (w=0; w<nsigma; w++) { waveform1[s] = cexp (-2.*I*CPL_MATH_PI * x * sigdata[w]); s++;}
1460 for (s=0, x = -width2/2.0; x < +width2/2.0; x+=step2)
1461 for (w=0; w<nsigma; w++) { waveform2[s] = cexp (-2.*I*CPL_MATH_PI * x * sigdata[w]); s++;}
1462 for (s=0, x = -width3/2.0; x < +width3/2.0; x+=step3)
1463 for (w=0; w<nsigma; w++) { waveform3[s] = cexp (-2.*I*CPL_MATH_PI * x * sigdata[w]); s++;}
1465 cpl_msg_debug (cpl_func,
"Loop on %lli rows to compute gdelay", nrow);
1468 for (cpl_size row = 0; row<nrow; row++) {
1472 for (w=0; w<nsigma; w++) {
1473 if (flag && cpl_array_get (flag[row], w, &nv)) visdata[w] = 0. + I*0.;
1474 else visdata[w] = cpl_array_get_complex (input[row], w, &nv);
1479 double complex is = 0.0 + I * 0.0;
1480 for (w=1; w<nsigma; w++) {
1481 is += visdata[w] * conj(visdata[w-1]) / CPL_MAX(cabs(visdata[w]) * cabs(visdata[w-1]), 1e-15);
1483 gd0 = carg (is) / ds / CPL_MATH_2PI;
1486 for (w=0; w<nsigma; w++) visdata[w] *= cexp (-2.*I*CPL_MATH_PI*gd0*sigdata[w]);
1489 for (current_max = -1.0, s = 0, x = -width1/2; x < +width1/2; x+=step1) {
1490 double complex tmp = 0.0 * I + 0.0;
1491 for (w=0; w<nsigma; w++) {tmp += visdata[w] * waveform1[s]; s++;}
1493 if ( P > current_max) { current_max = P; gd1 = x; }
1497 for (w=0; w<nsigma; w++) visdata[w] *= cexp (-2.*I*CPL_MATH_PI*gd1*sigdata[w]);
1500 for (current_max = -1.0, s = 0, x = -width2/2; x < +width2/2; x+=step2) {
1501 double complex tmp = 0.0 * I + 0.0;
1502 for (w=0; w<nsigma; w++) {tmp += visdata[w] * waveform2[s]; s++;}
1504 if ( P > current_max) { current_max = P; gd2 = x; }
1508 for (w=0; w<nsigma; w++) visdata[w] *= cexp (-2.*I*CPL_MATH_PI*gd2*sigdata[w]);
1511 for (current_max = -1.0, s = 0, x = -width3/2; x < +width3/2; x+=step3) {
1512 double complex tmp = 0.0 * I + 0.0;
1513 for (w=0; w<nsigma; w++) {tmp += visdata[w] * waveform3[s]; s++;}
1515 if ( P > current_max) { current_max = P; gd3 = x; }
1518 gd[row] = gd0 + gd1 + gd2 + gd3;
1524 FREE (cpl_free, visdata);
1525 FREE (cpl_free, sigdata);
1526 FREE (cpl_free, waveform1);
1527 FREE (cpl_free, waveform2);
1528 FREE (cpl_free, waveform3);
1531 return CPL_ERROR_NONE;
1537 const char *output, cpl_table * oi_wave)
1540 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1541 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1542 cpl_ensure_code (flag, CPL_ERROR_NULL_INPUT);
1543 cpl_ensure_code (output, CPL_ERROR_NULL_INPUT);
1544 cpl_ensure_code (oi_wave, CPL_ERROR_NULL_INPUT);
1547 cpl_size nwave = cpl_table_get_nrow (oi_wave);
1548 cpl_array * sigma = cpl_array_new (nwave, CPL_TYPE_DOUBLE);
1549 for (cpl_size wave = 0; wave < nwave ; wave ++)
1550 cpl_array_set (sigma, wave, 1./cpl_table_get (oi_wave,
"EFF_WAVE", wave, NULL));
1554 double * gdelay = cpl_table_get_data_double (table, output);
1557 cpl_array ** input_arrays = cpl_table_get_data_array (table, input);
1558 cpl_array ** flag_arrays = cpl_table_get_data_array (table, flag);
1559 cpl_size nrow = cpl_table_get_nrow (table);
1567 nrow, 1.e-3, CPL_TRUE);
1568 FREE (cpl_array_delete, sigma);
1571 return CPL_ERROR_NONE;
1587 cpl_ensure_code (first, CPL_ERROR_NULL_INPUT);
1588 cpl_ensure_code (second, CPL_ERROR_NULL_INPUT);
1590 cpl_size nrow = cpl_table_get_nrow (first);
1591 cpl_size ncol = cpl_table_get_ncol (first);
1594 if (nrow != cpl_table_get_nrow (second)) {
cpl_msg_info(cpl_func,
"Different rows");
return 0;}
1595 if (ncol != cpl_table_get_ncol (second)) {
cpl_msg_info(cpl_func,
"Different cols");
return 0;}
1596 if (cpl_table_compare_structure (first, second)) {
cpl_msg_info(cpl_func,
"Different structure");
return 0;}
1599 cpl_array *names = cpl_table_get_column_names (first);
1602 for (cpl_size c = 0; c<ncol; c++) {
1603 const char * name = cpl_array_get_string (names, c);
1607 int type = cpl_table_get_column_type (first, name);
1610 case CPL_TYPE_STRING:
1611 for (cpl_size r = 0; r<nrow; r++)
1612 if (strcmp (cpl_table_get_string (first, name, r),
1613 cpl_table_get_string (second, name, r) ) )
1614 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1616 case CPL_TYPE_DOUBLE:
1617 case CPL_TYPE_FLOAT:
1619 for (cpl_size r = 0; r<nrow; r++)
1620 if (cpl_table_get (first, name, r, &nv) !=
1621 cpl_table_get (second, name, r, &nv) )
1622 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1624 case CPL_TYPE_POINTER|CPL_TYPE_STRING:
1625 for (cpl_size r = 0; r<nrow; r++)
1626 for (cpl_size p = 0; p<cpl_table_get_column_depth (first,name); p++)
1627 if ( strcmp (cpl_array_get_string (cpl_table_get_array (first, name, r), p),
1628 cpl_array_get_string (cpl_table_get_array (second, name, r), p)) )
1629 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1631 case CPL_TYPE_POINTER|CPL_TYPE_DOUBLE:
1632 case CPL_TYPE_POINTER|CPL_TYPE_FLOAT:
1633 case CPL_TYPE_POINTER|CPL_TYPE_INT:
1634 for (cpl_size r = 0; r<nrow; r++)
1635 for (cpl_size p = 0; p<cpl_table_get_column_depth (first,name); p++) {
1636 if (cpl_array_get (cpl_table_get_array (first, name, r), p, NULL) !=
1637 cpl_array_get (cpl_table_get_array (second, name, r), p, NULL) )
1638 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1642 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"Cannot compare these tables (TBD, FIXME)");
1649 FREE (cpl_array_delete, names);
1657 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1658 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1660 if ( cpl_table_has_column (table, name) &&
1661 cpl_table_get_column_type (table, name) == type) {
1662 cpl_msg_info (cpl_func,
"Column %s already exists", name);
1664 cpl_table_new_column (table, name, type);
1667 if (type == CPL_TYPE_DOUBLE_COMPLEX || type == CPL_TYPE_FLOAT_COMPLEX)
1668 cpl_table_fill_column_window_complex (table, name, 0, cpl_table_get_nrow (table), 0.0 + I*0.0);
1670 cpl_table_fill_column_window (table, name, 0, cpl_table_get_nrow (table), 0.0);
1672 if (unit) cpl_table_set_column_unit (table, name, unit);
1674 return CPL_ERROR_NONE;
1679 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1680 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1682 if ( cpl_table_has_column (table, name) )
1683 cpl_table_erase_column (table, name);
1685 cpl_table_new_column_array (table, name, type, size);
1686 if (unit) cpl_table_set_column_unit (table, name, unit);
1688 return CPL_ERROR_NONE;
1693 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1694 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1696 if ( cpl_table_has_column (table, name) )
1697 cpl_table_erase_column (table, name);
1699 cpl_table_new_column_array (table, name, type, size);
1700 if (unit) cpl_table_set_column_unit (table, name, unit);
1702 cpl_array * array = cpl_array_new (size, type);
1703 cpl_array_fill_window (array, 0, size, 0.0);
1705 cpl_size nrow = cpl_table_get_nrow (table);
1706 for (cpl_size row = 0; row < nrow; row++)
1707 cpl_table_set_array (table, name, row, array);
1709 FREE (cpl_array_delete, array);
1711 return CPL_ERROR_NONE;
1728 cpl_ensure_code (imglist, CPL_ERROR_NULL_INPUT);
1730 cpl_size nrow = cpl_imagelist_get_size (imglist);
1732 for (cpl_size i = nrow-1; i>=0 ; i--) {
1733 cpl_image_unwrap (cpl_imagelist_unset (imglist, i));
1737 cpl_imagelist_delete (imglist);
1740 return CPL_ERROR_NONE;
1759 cpl_ensure (table_data, CPL_ERROR_NULL_INPUT, NULL);
1760 cpl_ensure (data_x, CPL_ERROR_NULL_INPUT, NULL);
1764 int type_column = cpl_table_get_column_type (table_data, data_x);
1767 cpl_size nrow = cpl_table_get_nrow (table_data);
1768 cpl_array ** array = cpl_table_get_data_array (table_data, data_x);
1769 cpl_ensure (array, CPL_ERROR_ILLEGAL_INPUT, NULL);
1773 if (cpl_table_get_column_dimensions (table_data, data_x)<2) {
1774 nx = cpl_table_get_column_depth (table_data, data_x);
1777 nx = cpl_table_get_column_dimension (table_data, data_x, 0);
1778 ny = cpl_table_get_column_dimension (table_data, data_x, 1);
1784 cpl_imagelist * imglist = cpl_imagelist_new();
1787 switch (type_column)
1789 case CPL_TYPE_POINTER|CPL_TYPE_DOUBLE :
1791 for (cpl_size j = 0; j < nrow ; j++)
1793 img = cpl_image_wrap_double (nx, ny, cpl_array_get_data_double(array[j]));
1794 cpl_imagelist_set (imglist, img, j);
1799 case CPL_TYPE_POINTER|CPL_TYPE_INT :
1801 for (cpl_size j = 0; j < nrow ; j++)
1803 img = cpl_image_wrap_int (nx, ny, cpl_array_get_data_int(array[j]));
1804 cpl_imagelist_set (imglist, img,j);
1809 case CPL_TYPE_POINTER|CPL_TYPE_FLOAT :
1810 for (cpl_size j = 0; j < nrow ; j++)
1812 img = cpl_image_wrap_float (nx, ny, cpl_array_get_data_float(array[j]));
1813 cpl_imagelist_set (imglist, img, j);
1820 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
1821 "invalid type of image coming from %s", data_x);
1822 cpl_imagelist_delete (imglist);
1839 cpl_size llx, cpl_size lly,
1840 cpl_size urx, cpl_size ury)
1843 cpl_ensure (img, CPL_ERROR_NULL_INPUT, -1);
1847 cpl_vector * flux = cpl_vector_new ((urx-llx+1)*(ury-lly+1));
1849 for (cpl_size v = 0, x = llx; x <= urx; x++) {
1850 for (cpl_size y = lly; y <= ury; y++) {
1851 cpl_vector_set (flux, v, cpl_image_get (img, x, y, &nv));
1861 cpl_vector_multiply (flux, flux);
1863 double RMS = sqrt (cpl_vector_get_median (flux));
1864 FREE (cpl_vector_delete, flux);
1886 cpl_ensure (img, CPL_ERROR_NULL_INPUT, NULL);
1887 cpl_ensure (drop_from < drop_to, CPL_ERROR_ILLEGAL_INPUT, NULL);
1890 cpl_size nx = cpl_image_get_size_x (img);
1891 cpl_size ny = cpl_image_get_size_y (img);
1894 cpl_ensure (drop_from >0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1895 cpl_ensure (drop_to <=nx, CPL_ERROR_ILLEGAL_INPUT, NULL);
1898 cpl_mask * mask = cpl_mask_new (nx, ny);
1899 for (cpl_size y = 1; y <= ny; y++)
1900 for (cpl_size x = drop_from; x <= drop_to ; x++)
1901 cpl_mask_set (mask, x, y, CPL_BINARY_1);
1904 cpl_mask * bpm = cpl_image_set_bpm (img, mask);
1907 cpl_image * collapse = cpl_image_collapse_median_create (img, 1, 0, 0);
1910 mask = cpl_image_set_bpm (img, bpm);
1911 FREE (cpl_mask_delete, mask);
1921 const cpl_image * collapse,
1925 cpl_ensure_code (img, CPL_ERROR_NULL_INPUT);
1926 cpl_ensure_code (collapse, CPL_ERROR_NULL_INPUT);
1927 cpl_ensure_code (direction==0 || direction==1, CPL_ERROR_ILLEGAL_INPUT);
1932 cpl_size nx = cpl_image_get_size_x (img);
1933 cpl_size ny = cpl_image_get_size_y (img);
1935 if (direction == 0) {
1937 cpl_ensure_code (cpl_image_get_size_x (collapse) == nx &&
1938 cpl_image_get_size_y (collapse) == 1,
1939 CPL_ERROR_ILLEGAL_INPUT);
1941 for (cpl_size x = 0; x < nx ; x++) {
1942 double value = cpl_image_get (collapse, x+1, 1, &nv);
1943 for (cpl_size y = 0; y < ny ; y++) {
1944 cpl_image_set (img, x+1, y+1, cpl_image_get (img, x+1, y+1, &nv) - value);
1951 cpl_ensure_code (cpl_image_get_size_x (collapse) == 1 &&
1952 cpl_image_get_size_y (collapse) == ny,
1953 CPL_ERROR_ILLEGAL_INPUT);
1955 for (cpl_size y = 0; y < ny ; y++) {
1956 double value = cpl_image_get (collapse, 1, y+1, &nv);
1957 for (cpl_size x = 0; x < nx ; x++) {
1958 cpl_image_set (img, x+1, y+1, cpl_image_get (img, x+1, y+1, &nv) - value);
1965 return CPL_ERROR_NONE;
1971 cpl_size llx, cpl_size lly,
1972 cpl_size urx, cpl_size ury,
1973 cpl_size llx2, cpl_size lly2)
1976 cpl_ensure_code (img1, CPL_ERROR_NULL_INPUT);
1977 cpl_ensure_code (img2, CPL_ERROR_NULL_INPUT);
1980 cpl_size nx = cpl_image_get_size_x (img1);
1981 cpl_size ny = cpl_image_get_size_y (img1);
1983 urx = CPL_MIN (urx, nx);
1984 ury = CPL_MIN (ury, ny);
1989 for (cpl_size x=llx; x<=urx; x++) {
1990 for (cpl_size y=lly; y<=ury; y++) {
1991 cpl_image_set (img1, x, y,
1992 cpl_image_get (img1,x,y,&nv) -
1993 cpl_image_get (img2,x+llx2,y+lly2,&nv));
1998 return CPL_ERROR_NONE;
2004 cpl_size llx, cpl_size lly,
2005 cpl_size urx, cpl_size ury,
2006 cpl_size llx2, cpl_size lly2)
2009 cpl_ensure_code (img1, CPL_ERROR_NULL_INPUT);
2010 cpl_ensure_code (img2, CPL_ERROR_NULL_INPUT);
2013 cpl_size nx = cpl_image_get_size_x (img1);
2014 cpl_size ny = cpl_image_get_size_y (img1);
2015 cpl_size nx2 = cpl_image_get_size_x (img2);
2016 cpl_size ny2 = cpl_image_get_size_y (img2);
2017 cpl_msg_info(cpl_func,
"Size image 1 %lli/%lli, Size window %lli/%lli" , nx,ny,nx2,ny2);
2019 urx = CPL_MIN (urx, nx);
2020 ury = CPL_MIN (ury, ny);
2025 for (cpl_size x=llx; x<=urx; x++) {
2026 for (cpl_size y=lly; y<=ury; y++) {
2027 cpl_image_set (img1, x, y,
2028 cpl_image_get (img2,x+llx2,y+lly2,&nv));
2033 return CPL_ERROR_NONE;
2054 cpl_ensure (table_data, CPL_ERROR_NULL_INPUT, NULL);
2055 cpl_ensure (data_x, CPL_ERROR_NULL_INPUT, NULL);
2056 cpl_ensure (row < cpl_table_get_nrow (table_data), CPL_ERROR_ILLEGAL_INPUT, NULL);
2059 cpl_ensure (wrap_imglist, CPL_ERROR_ILLEGAL_INPUT, NULL);
2061 cpl_image * out_img = cpl_image_duplicate (cpl_imagelist_get (wrap_imglist, row));
2086 cpl_ensure (table_data, CPL_ERROR_NULL_INPUT, NULL);
2087 cpl_ensure (data_x, CPL_ERROR_NULL_INPUT, NULL);
2090 cpl_ensure (wrap_imglist, CPL_ERROR_ILLEGAL_INPUT, NULL);
2092 cpl_imagelist * out_imglist = cpl_imagelist_duplicate (wrap_imglist);
2115 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
2116 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
2118 cpl_size ndim = cpl_table_get_column_dimensions (table, name);
2119 cpl_array * dimension = cpl_array_new (ndim, CPL_TYPE_INT);
2120 for (cpl_size dim = 0; dim < ndim; dim++) {
2121 int value = cpl_table_get_column_dimension (table, name, dim);
2122 cpl_array_set (dimension, dim, value);
2142 cpl_ensure (img, CPL_ERROR_NULL_INPUT, NULL);
2144 cpl_type type_img = cpl_image_get_type (img);
2145 int x = cpl_image_get_size_x (img);
2146 int y = cpl_image_get_size_y (img);
2150 cpl_array * array = NULL;
2152 case CPL_TYPE_FLOAT :
2153 array = cpl_array_wrap_float (cpl_image_get_data_float(img), x*y);
2155 case CPL_TYPE_DOUBLE :
2156 array = cpl_array_wrap_double (cpl_image_get_data_double(img), x*y);
2159 array = cpl_array_wrap_int (cpl_image_get_data_int(img), x*y);
2162 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
2163 "invalid type of image");
2185 cpl_vector * vector2)
2187 cpl_ensure (vector1, CPL_ERROR_NULL_INPUT, NULL);
2189 cpl_matrix * matrix, * matrix_wrap;
2190 int size = cpl_vector_get_size(vector1);
2191 double * data1, * data2;
2193 if( vector2 != NULL ){
2194 int size2 = cpl_vector_get_size(vector2);
2195 cpl_ensure (size == size2, CPL_ERROR_ILLEGAL_INPUT, NULL);
2197 data1 = cpl_malloc(2 * size *
sizeof(
double));
2198 memcpy(data1, cpl_vector_get_data(vector1), size *
sizeof(
double));
2200 data2 = cpl_vector_get_data(vector2);
2201 memcpy(data1 + size, data2, size *
sizeof(
double));
2203 matrix_wrap = cpl_matrix_wrap(2, size, data1);
2204 matrix = cpl_matrix_transpose_create(matrix_wrap);
2206 cpl_matrix_unwrap(matrix_wrap);
2209 data1 = cpl_malloc(size *
sizeof(
double));
2210 memcpy(data1, cpl_vector_get_data(vector1), size *
sizeof(
double));
2212 matrix = cpl_matrix_wrap(size, 1, data1);
2236 const char * regname)
2239 cpl_ensure (spectrum_data, CPL_ERROR_NULL_INPUT, NULL);
2240 cpl_ensure (regname, CPL_ERROR_NULL_INPUT, NULL);
2241 cpl_ensure (index>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2244 cpl_size size = cpl_table_get_column_depth (spectrum_data, regname);
2245 cpl_ensure (index<size, CPL_ERROR_ILLEGAL_INPUT, NULL);
2248 cpl_size nrow = cpl_table_get_nrow (spectrum_data);
2249 cpl_vector * data_value = cpl_vector_new (nrow);
2254 cpl_array ** column_array = cpl_table_get_data_array (spectrum_data, regname);
2255 cpl_ensure (column_array, CPL_ERROR_ILLEGAL_INPUT, NULL);
2259 for (cpl_size row = 0; row < nrow; row ++){
2260 value = cpl_array_get (column_array[row], index, NULL);
2261 cpl_vector_set (data_value, row, value);
2263 }
else if (cpl_table_get_column_type (spectrum_data, regname)
2264 == CPL_TYPE_DOUBLE) {
2266 double * data = cpl_table_get_data_double (spectrum_data, regname);
2267 for (cpl_size row = 0; row < nrow; row++) {
2268 cpl_vector_set (data_value, row, data[row]);
2271 }
else if (cpl_table_get_column_type (spectrum_data, regname)
2274 int * data = cpl_table_get_data_int (spectrum_data, regname);
2275 for (cpl_size row = 0; row < nrow; row++) {
2276 cpl_vector_set (data_value, row, data[row]);
2280 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
2281 "This type is not supported"
2282 "(report to DRS team).");
2283 FREE (cpl_vector_delete, data_value);
2287 return (data_value);
2296 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
2297 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
2298 cpl_ensure (base>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2299 cpl_ensure (nbase>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2302 cpl_size size = cpl_table_get_column_depth (table, name);
2303 cpl_ensure (size==0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2306 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
2307 cpl_vector * vector = cpl_vector_new (nrow);
2310 cpl_type type = cpl_table_get_column_type (table, name);
2312 if (type == CPL_TYPE_DOUBLE) {
2313 double * data = cpl_table_get_data_double (table, name);
2314 for (cpl_size row = 0; row < nrow; row++)
2315 cpl_vector_set (vector, row, data[row*nbase+base]);
2317 else if (type == CPL_TYPE_FLOAT) {
2318 float * data = cpl_table_get_data_float (table, name);
2319 for (cpl_size row = 0; row < nrow; row++)
2320 cpl_vector_set (vector, row, data[row*nbase+base]);
2322 else if (type == CPL_TYPE_INT) {
2323 int * data = cpl_table_get_data_int (table, name);
2324 for (cpl_size row = 0; row < nrow; row++)
2325 cpl_vector_set (vector, row, data[row*nbase+base]);
2328 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
2329 "This type is not supported"
2330 "(report to DRS team).");
2331 FREE (cpl_vector_delete, vector);
2356 const char * regname1,
2357 const char * regname2)
2360 cpl_ensure (spectrum_data, CPL_ERROR_NULL_INPUT, NULL);
2361 cpl_ensure (regname1, CPL_ERROR_NULL_INPUT, NULL);
2362 cpl_ensure (regname2, CPL_ERROR_NULL_INPUT, NULL);
2363 cpl_ensure (index>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2366 cpl_size size1 = cpl_table_get_column_depth (spectrum_data, regname1);
2367 cpl_size size2 = cpl_table_get_column_depth (spectrum_data, regname2);
2368 cpl_ensure (index<size1, CPL_ERROR_ILLEGAL_INPUT, NULL);
2369 cpl_ensure (index<size2, CPL_ERROR_ILLEGAL_INPUT, NULL);
2372 cpl_array ** column_array1 = cpl_table_get_data_array (spectrum_data, regname1);
2373 cpl_array ** column_array2 = cpl_table_get_data_array (spectrum_data, regname2);
2374 cpl_ensure (column_array1, CPL_ERROR_ILLEGAL_INPUT, NULL);
2375 cpl_ensure (column_array2, CPL_ERROR_ILLEGAL_INPUT, NULL);
2378 cpl_size nrow = cpl_table_get_nrow (spectrum_data);
2379 cpl_vector * data_value = cpl_vector_new (nrow);
2383 for (cpl_size row = 0; row < nrow; row++){
2384 value = cpl_array_get (column_array1[row], index, NULL) - cpl_array_get (column_array2[row], index, NULL);
2385 cpl_vector_set (data_value, row, value);
2388 return (data_value);
2399 cpl_ensure_code (img, CPL_ERROR_NULL_INPUT);
2401 cpl_size nx = cpl_image_get_size_x (img);
2402 cpl_size ny = cpl_image_get_size_y (img);
2403 cpl_image_fill_window (img, 1,1,nx,ny, value);
2405 return CPL_ERROR_NONE;
2416 cpl_ensure (matrix, CPL_ERROR_NULL_INPUT, NULL);
2417 cpl_size nx = cpl_matrix_get_ncol (matrix);
2418 cpl_size ny = cpl_matrix_get_nrow (matrix);
2419 return cpl_image_wrap_double (nx, ny, cpl_matrix_get_data (matrix));
2424 cpl_ensure (matrix, CPL_ERROR_NULL_INPUT, NULL);
2425 cpl_size nx = cpl_matrix_get_ncol (matrix);
2426 cpl_size ny = cpl_matrix_get_nrow (matrix);
2428 cpl_image * image = cpl_image_new (nx,ny,CPL_TYPE_DOUBLE);
2429 for (cpl_size i = 0; i < nx; i++)
2430 for (cpl_size j = 0; j < ny; j++)
2431 cpl_image_set (image, i+1, j+1, cpl_matrix_get (matrix,j,i));
2444 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, NULL);
2445 cpl_size nx = cpl_vector_get_size (vector);
2447 return cpl_image_wrap_double (nx, ny, cpl_vector_get_data (vector));
2452 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, NULL);
2453 cpl_size nx = cpl_vector_get_size (vector);
2456 cpl_image * image = cpl_image_new (nx,ny,CPL_TYPE_DOUBLE);
2457 for (cpl_size i = 0; i < nx; i++)
2458 cpl_image_set (image, i+1, 1, cpl_vector_get (vector,i));
2478 cpl_ensure (img, CPL_ERROR_NULL_INPUT, -1);
2479 cpl_ensure (thr>0 && thr<1, CPL_ERROR_ILLEGAL_INPUT, -1);
2481 cpl_size nx = cpl_image_get_size_x (img);
2482 cpl_size ny = cpl_image_get_size_y (img);
2483 cpl_size nq = (cpl_size)(thr * nx * ny);
2485 cpl_ensure (nq>=0 && nq<=nx*ny, CPL_ERROR_ILLEGAL_INPUT, -1);
2489 cpl_vector * vect = cpl_vector_new (nx*ny);
2490 for (cpl_size ix = 0; ix < nx ; ix++)
2491 for (cpl_size iy = 0; iy < ny ; iy++)
2492 cpl_vector_set (vect, ix * ny + iy, cpl_image_get (img, ix+1, iy+1, &nv));
2495 cpl_vector_sort (vect, CPL_SORT_ASCENDING);
2496 double value = cpl_vector_get (vect, nq);
2497 cpl_vector_delete (vect);
2512 cpl_ensure (arr, CPL_ERROR_NULL_INPUT, -1);
2513 cpl_ensure (thr>0 && thr<1, CPL_ERROR_ILLEGAL_INPUT, -1);
2515 cpl_size nx = cpl_array_get_size (arr);
2516 cpl_size nq = (cpl_size)(thr * nx);
2518 cpl_ensure (nq>=0 && nq<=nx, CPL_ERROR_ILLEGAL_INPUT, -1);
2522 cpl_vector * vect = cpl_vector_new (nx);
2523 for (cpl_size ix = 0; ix < nx ; ix++)
2524 cpl_vector_set (vect, ix, cpl_array_get (arr, ix, &nv));
2527 cpl_vector_sort (vect, CPL_SORT_ASCENDING);
2528 double value = cpl_vector_get (vect, nq);
2529 cpl_vector_delete (vect);
2548 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, NULL);
2549 cpl_ensure (hw>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2551 cpl_size size = cpl_vector_get_size (vector);
2552 cpl_vector * median = NULL;
2557 median = cpl_vector_new (size);
2558 cpl_vector_fill (median, cpl_vector_get_median_const (vector));
2563 median = cpl_vector_filter_median_create (vector, hw);
2564 cpl_ensure (median, CPL_ERROR_DATA_NOT_FOUND, NULL);
2566 double * data = cpl_vector_get_data (median);
2567 cpl_ensure (data, CPL_ERROR_DATA_NOT_FOUND, NULL);
2569 for (
int i = 0; i < hw; i++) data[i] = data[hw];
2570 for (
int i = size-hw; i < size; i++) data[i] = data[size-hw-1];
2589 cpl_ensure_code (vector, CPL_ERROR_NULL_INPUT);
2592 cpl_size size = cpl_vector_get_size (vector);
2593 cpl_ensure_code (size > 0, CPL_ERROR_ILLEGAL_INPUT);
2595 double * data = cpl_vector_get_data (vector);
2596 cpl_ensure_code (data, CPL_ERROR_ILLEGAL_INPUT);
2599 for (
int i = 0; i < size; i++) data[i] = fabs (data[i]);
2601 return CPL_ERROR_NONE;
2615 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, -1);
2616 cpl_size size = cpl_vector_get_size (vector);
2619 double value = cpl_vector_get (vector, 0);
2620 for (
int s = 1; s < size; s++) {
2621 if (cpl_vector_get (vector, s) > value) {
2623 value = cpl_vector_get (vector, s);
2645 cpl_ensure (vector_in, CPL_ERROR_NULL_INPUT, 0.0);
2646 cpl_ensure (percent > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0);
2647 cpl_ensure (percent < 0.5, CPL_ERROR_ILLEGAL_INPUT, 0.0);
2648 cpl_ensure (nsigma > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0);
2651 cpl_vector * sort_vector = cpl_vector_duplicate (vector_in);
2652 cpl_vector_sort (sort_vector, CPL_SORT_ASCENDING);
2655 cpl_size size = cpl_vector_get_size (vector_in);
2656 cpl_size sizeout = size*(1-percent*2);
2657 cpl_size start = (size-sizeout)/2;
2659 cpl_vector * vector = cpl_vector_new (sizeout);
2660 for (cpl_size i = 0 ; i < sizeout ; i++)
2661 cpl_vector_set (vector, i, cpl_vector_get (sort_vector, i+start));
2664 cpl_vector * vector_med = cpl_vector_new (sizeout);
2665 double med = cpl_vector_get_median (vector);
2666 double rms = nsigma * cpl_vector_get_stdev (vector);
2668 cpl_size size_med = 0;
2669 for (cpl_size i = 0 ; i < cpl_vector_get_size (vector) ; i++)
2670 if ( (cpl_vector_get (vector, i) > med-rms) &&
2671 (cpl_vector_get (vector, i) < med+rms) ) {
2672 cpl_vector_set (vector_med, size_med, cpl_vector_get (vector, i));
2675 cpl_vector_set_size (vector_med, size_med);
2678 double output = cpl_vector_get_mean (vector_med);
2680 FREE (cpl_vector_delete, vector_med);
2681 FREE (cpl_vector_delete, sort_vector);
2697 cpl_size size = cpl_vector_get_size (vector);
2698 cpl_size newsize = size / step;
2699 cpl_vector * out = cpl_vector_new (newsize);
2701 for (
int s = 0; s < newsize; s++)
2702 cpl_vector_set (out, s, cpl_vector_get (vector, s*step+start));
2720 cpl_ensure_code (vector, CPL_ERROR_NULL_INPUT);
2721 cpl_ensure_code (ref, CPL_ERROR_NULL_INPUT);
2723 cpl_size nrow = cpl_vector_get_size (vector);
2725 double referenced, referenced_prev = 0.0;
2728 for (cpl_size row = 0 ; row < nrow; row ++) {
2729 double phase_ref = ref_to_phase * cpl_vector_get (ref, row);
2732 referenced = (cpl_vector_get (vector, row) - phase_ref);
2733 referenced = fmod (referenced, CPL_MATH_2PI);
2734 if (referenced < 0) referenced += CPL_MATH_2PI;
2737 if ( referenced - referenced_prev > CPL_MATH_PI ) wrap --;
2738 if ( referenced - referenced_prev < -CPL_MATH_PI ) wrap ++;
2739 referenced_prev = referenced;
2742 cpl_vector_set (vector, row, phase_ref + referenced + wrap * CPL_MATH_2PI);
2747 return CPL_ERROR_NONE;
2766 int base,
int nbase,
double value)
2768 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
2769 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
2770 cpl_ensure_code (nbase==1 || nbase==4 || nbase==6, CPL_ERROR_ILLEGAL_INPUT);
2771 cpl_ensure_code (base>=0 && base <nbase, CPL_ERROR_ILLEGAL_INPUT);
2773 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
2775 if (cpl_table_get_column_depth (table, name) > 0) {
2776 cpl_array ** array = cpl_table_get_data_array (table, name);
2777 for (cpl_size row = 0 ; row < nrow ; row ++) {
2778 cpl_array_multiply_scalar (array[row*nbase+base], value);
2779 CPLCHECK_MSG (
"Cannot multiply (array may not be numerical)");
2781 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_DOUBLE) {
2782 double * array = cpl_table_get_data_double (table, name);
2783 for (cpl_size row = 0 ; row < nrow ; row ++) {
2784 array[row*nbase+base] *= value;
2786 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_INT) {
2787 int * array = cpl_table_get_data_int (table, name);
2788 for (cpl_size row = 0 ; row < nrow ; row ++) {
2789 array[row*nbase+base] *= value;
2792 return cpl_error_set_message (cpl_func, CPL_ERROR_INVALID_TYPE,
2793 "Column type is not supported");
2797 return CPL_ERROR_NONE;
2816 int base,
int nbase,
double value)
2818 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
2819 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
2820 cpl_ensure_code (nbase==1 || nbase==4 || nbase==6, CPL_ERROR_ILLEGAL_INPUT);
2821 cpl_ensure_code (base>=0 && base <nbase, CPL_ERROR_ILLEGAL_INPUT);
2823 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
2825 if (cpl_table_get_column_depth (table, name) > 0) {
2826 cpl_array ** array = cpl_table_get_data_array (table, name);
2827 for (cpl_size row = 0 ; row < nrow ; row ++) {
2828 cpl_array_add_scalar (array[row*nbase+base], value);
2829 CPLCHECK_MSG (
"Cannot multiply (array may not be numerical)");
2831 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_DOUBLE) {
2832 double * array = cpl_table_get_data_double (table, name);
2833 for (cpl_size row = 0 ; row < nrow ; row ++) {
2834 array[row*nbase+base] += value;
2836 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_INT) {
2837 int * array = cpl_table_get_data_int (table, name);
2838 for (cpl_size row = 0 ; row < nrow ; row ++) {
2839 array[row*nbase+base] += value;
2842 return cpl_error_set_message (cpl_func, CPL_ERROR_INVALID_TYPE,
2843 "Column type is not supported");
2847 return CPL_ERROR_NONE;
2872 cpl_ensure (matrix, CPL_ERROR_NULL_INPUT, NULL);
2873 cpl_ensure (xref, CPL_ERROR_NULL_INPUT, NULL);
2874 cpl_ensure (xout, CPL_ERROR_NULL_INPUT, NULL);
2876 cpl_size nrow = cpl_matrix_get_nrow (matrix);
2877 cpl_size ncol = cpl_matrix_get_ncol (matrix);
2878 cpl_size nxref = cpl_vector_get_size (xref);
2879 cpl_size nxout = cpl_vector_get_size (xout);
2881 cpl_ensure (ncol == nxref, CPL_ERROR_ILLEGAL_INPUT, NULL);
2882 cpl_ensure (nxout > 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2885 cpl_matrix * outmatrix = cpl_matrix_new (nrow, nxout);
2886 cpl_vector * yref = cpl_vector_new (nxref);
2887 cpl_vector * yout = cpl_vector_new (nxout);
2888 cpl_bivector * fref = cpl_bivector_wrap_vectors (xref, yref);
2889 cpl_bivector * fout = cpl_bivector_wrap_vectors (xout, yout);
2892 for (cpl_size row = 0; row < nrow; row++) {
2893 for (cpl_size x = 0; x < nxref; x++)
2894 cpl_vector_set (yref, x, cpl_matrix_get (matrix, row, x));
2895 cpl_bivector_interpolate_linear (fout, fref);
2896 for (cpl_size x = 0; x < nxout; x++)
2897 cpl_matrix_set (outmatrix, row, x, cpl_vector_get (yout, x));
2901 FREE (cpl_bivector_unwrap_vectors, fref);
2902 FREE (cpl_bivector_unwrap_vectors, fout);
2903 FREE (cpl_vector_delete, yref);
2904 FREE (cpl_vector_delete, yout);
2924 cpl_ensure (a_in, CPL_ERROR_NULL_INPUT, NULL);
2926 cpl_size m = cpl_matrix_get_nrow (a_in);
2927 cpl_size n = cpl_matrix_get_ncol (a_in);
2929 cpl_vector * w = cpl_vector_new (n);
2930 cpl_matrix * v = cpl_matrix_new (n, n);
2936 cpl_matrix * a_out =
svdcmp (a_in, w, v);
2940 for (cpl_size ii = 0; ii < n; ii++) {
2941 if (cpl_vector_get (w, ii) < 0.1)
2942 cpl_msg_warning (cpl_func,
"Singular Value %lld = %e",
2943 ii, cpl_vector_get (w, ii));
2949 cpl_matrix * a_inv = cpl_matrix_new (n,m);
2950 double * a_inv_data = cpl_matrix_get_data (a_inv);
2952 for (cpl_size j = 0; j < m; j++) {
2953 for (cpl_size i = 0; i < n; i++){
2956 for (cpl_size ii = 0; ii < n; ii++)
2957 if (cpl_vector_get (w, ii) > 1e-15)
2958 wv_at += cpl_matrix_get (v, i, ii) /
2959 cpl_vector_get (w, ii) *
2960 cpl_matrix_get (a_out, j, ii);
2962 a_inv_data[j + i * m] = wv_at;
2967 cpl_vector_delete (w);
2968 cpl_matrix_delete (v);
2969 cpl_matrix_delete (a_out);
2981 double absa=fabs(a);
2982 double absb=fabs(b);
2984 return absa*sqrt(1.0+pow(absb/absa, 2));
2986 return (absb == 0.0 ? 0.0 : absb*sqrt(1.0+pow(absa/absb, 2)));
2994cpl_matrix *
svdcmp (cpl_matrix * a_in, cpl_vector * w, cpl_matrix * v)
2997 cpl_ensure (a_in, CPL_ERROR_NULL_INPUT, NULL);
2999 int flag, i, its, j, jj, k, l, nm, n, m;
3000 double anorm, c, f, g, h, s, scale, x, y, z;
3004 a = cpl_matrix_duplicate(a_in);
3005 m = cpl_matrix_get_nrow (a_in);
3006 n = cpl_matrix_get_ncol (a_in);
3007 rv1 = cpl_vector_new(n);
3009 g = scale = anorm = 0.0;
3010 for (i = 0; i < n; i++) {
3012 cpl_vector_set(rv1, i, scale*g);
3013 g = s = scale = 0.0;
3015 for (k = i; k < m; k++)
3016 scale += fabs(cpl_matrix_get(a, k, i));
3019 for (k = i; k < m; k++) {
3021 cpl_matrix_set (a, k, i, cpl_matrix_get(a, k, i)/scale);
3022 s += cpl_matrix_get(a, k, i) * cpl_matrix_get(a, k, i);
3024 f = cpl_matrix_get(a, i, i);
3025 g = -
SIGN(sqrt(s),f);
3027 cpl_matrix_set (a, i, i, f - g);
3028 for (j = l; j < n; j++) {
3029 for (s = 0.0, k = i; k < m; k++)
3030 s += cpl_matrix_get(a, k, i) * cpl_matrix_get(a, k, j);
3033 for (k = i; k < m; k++)
3034 cpl_matrix_set (a, k, j, cpl_matrix_get(a, k, j) +
3035 f * cpl_matrix_get(a, k, i));
3038 for (k = i; k < m; k++)
3039 cpl_matrix_set (a, k, i, cpl_matrix_get(a, k, i) * scale);
3044 cpl_vector_set(w, i, scale *g);
3046 g = s = scale = 0.0;
3047 if (i < m && i != (n - 1)) {
3048 for (k = l; k < n; k++)
3049 scale += fabs(cpl_matrix_get(a, i, k));;
3051 for (k = l; k < n; k++) {
3052 cpl_matrix_set (a, i, k, cpl_matrix_get(a, i, k) / scale);
3053 s += cpl_matrix_get(a, i, k) * cpl_matrix_get(a, i, k);
3055 f = cpl_matrix_get(a, i, l);
3056 g = -
SIGN(sqrt(s),f);
3058 cpl_matrix_set (a, i, l, f - g);
3059 for (k = l; k < n; k++)
3060 cpl_vector_set(rv1, k, cpl_matrix_get(a, i, k)/h);
3061 for (j = l; j < m; j++) {
3062 for (s = 0.0, k = l; k < n; k++)
3063 s += cpl_matrix_get(a, j, k) * cpl_matrix_get(a, i, k);
3064 for (k = l; k < n; k++)
3065 cpl_matrix_set (a, j, k, cpl_matrix_get(a, j, k) + s * cpl_vector_get(rv1, k));
3067 for (k = l; k < n; k++)
3068 cpl_matrix_set (a, i, k, cpl_matrix_get(a, i, k) * scale);
3072 anorm = fmax(anorm,(fabs(cpl_vector_get(w, i)) +
3073 fabs(cpl_vector_get(rv1, i))));
3077 for (i = (n - 1); i >= 0; i--) {
3080 for (j = l; j < n; j++)
3081 cpl_matrix_set(v, j, i, (cpl_matrix_get(a, i, j) /
3082 cpl_matrix_get(a, i, l)) / g);
3084 for (j = l;j < n; j++) {
3085 for (s = 0.0, k = l; k < n; k++)
3086 s += cpl_matrix_get(a, i, k) * cpl_matrix_get(v, k, j);
3088 for (k = l; k < n; k++)
3089 cpl_matrix_set(v, k, j, cpl_matrix_get(v, k, j) + s *
3090 cpl_matrix_get(v, k, i));
3094 for (j = l; j < n; j++) {
3095 cpl_matrix_set(v, i, j, 0.0);
3096 cpl_matrix_set(v, j, i, 0.0);
3099 cpl_matrix_set(v, i, i, 1.0);
3101 g = cpl_vector_get(rv1, i);
3105 for (i = (
IMIN(m,n) - 1); i >= 0; i--) {
3107 g = cpl_vector_get(w, i);
3108 for (j = l; j < n; j++)
3109 cpl_matrix_set(a, i, j, 0.0);
3113 for (j = l; j < n; j++) {
3114 for (s = 0.0, k = l; k < m; k++)
3115 s += cpl_matrix_get(a, k, i) * cpl_matrix_get(a, k, j);
3117 f = (s / cpl_matrix_get(a, i, i)) * g;
3119 for (k = i; k < m; k++)
3120 cpl_matrix_set(a, k, j, cpl_matrix_get(a, k, j) + f *
3121 cpl_matrix_get(a, k, i));
3124 for (j = i; j < m; j++)
3125 cpl_matrix_set(a, j, i, cpl_matrix_get(a, j, i) * g);
3129 for (j = i; j < m; j++)
3130 cpl_matrix_set(a, j, i, 0.0);
3132 cpl_matrix_set(a, i, i, cpl_matrix_get(a, i, i) + 1);
3136 for (k = (n - 1); k >= 0; k--) {
3137 for (its = 1; its <= 60; its ++) {
3140 for (l = k; l >= 0; l--) {
3142 if ((fabs(cpl_vector_get(rv1, l)) + anorm) == anorm) {
3146 if ((fabs(cpl_vector_get(w, nm)) + anorm) == anorm)
3153 for (i = l; i <= k; i++) {
3154 f = s * cpl_vector_get(rv1, i);
3155 cpl_vector_set(rv1, i, c * cpl_vector_get(rv1, i));
3156 if ((fabs(f) + anorm) == anorm)
3158 g = cpl_vector_get(w, i);
3160 cpl_vector_set(w, i, h);
3164 for (j = 0; j < m; j++) {
3165 y = cpl_matrix_get(a, j, nm);
3166 z = cpl_matrix_get(a, j, i);
3167 cpl_matrix_set(a, j, nm, y*c+z*s);
3168 cpl_matrix_set(a, j, i, z*c-y*s);
3172 z = cpl_vector_get(w, k);
3175 cpl_vector_set(w, k, -z);
3176 for (j = 0; j < n; j++)
3177 cpl_matrix_set(v, j, k, -cpl_matrix_get(v, j, k));
3184 cpl_error_set_message(cpl_func,
3185 CPL_ERROR_ILLEGAL_INPUT,
3186 "no convergence in 120 svdcmp iterations");
3187 cpl_vector_delete(rv1);
3188 cpl_matrix_delete(a);
3191 x = cpl_vector_get(w, l);
3193 y = cpl_vector_get(w, nm); ;
3194 g = cpl_vector_get(rv1, nm);
3195 h = cpl_vector_get(rv1, k);
3196 f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y);
3198 f = ((x - z) * (x + z) + h * ((y / (f +
SIGN(g, f))) - h)) / x;
3200 for (j = l; j < nm; j++) {
3202 g = cpl_vector_get(rv1, i);
3203 y = cpl_vector_get(w, i);
3207 cpl_vector_set(rv1, j, z);
3214 for (jj = 0; jj < n; jj++) {
3215 x = cpl_matrix_get(v, jj, j);
3216 z=cpl_matrix_get(v, jj, i);
3217 cpl_matrix_set(v, jj, j, x*c+z*s);
3218 cpl_matrix_set(v, jj, i, z*c-x*s);
3221 cpl_vector_set(w, j, z);
3230 for (jj = 0; jj < m; jj++) {
3231 y = cpl_matrix_get(a, jj, j);
3232 z = cpl_matrix_get(a, jj, i);
3233 cpl_matrix_set(a, jj, j, y*c+z*s);
3234 cpl_matrix_set(a, jj, i, z*c-y*s);
3237 cpl_vector_set(rv1, l, 0.0);
3238 cpl_vector_set(rv1, k, f);
3239 cpl_vector_set(w, k, x);
3243 cpl_vector_delete(rv1);
3263 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
3266 cpl_table_select_all (table);
3267 cpl_table_and_selected_double (table,
"TIME", CPL_NOT_LESS_THAN, start);
3268 cpl_table_and_selected_double (table,
"TIME", CPL_LESS_THAN, end);
3269 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