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");
277 cpl_ensure (table, CPL_ERROR_NULL_INPUT, 0.0);
278 cpl_ensure (name, CPL_ERROR_NULL_INPUT, 0.0);
281 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
282 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, 0.0);
284 cpl_type type = cpl_table_get_column_type (table, name);
285 cpl_size depth = cpl_table_get_column_depth (table, name);
287 if (depth == 0 && type == CPL_TYPE_DOUBLE) {
288 double * data = cpl_table_get_data_double (table, name);
289 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
290 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
292 else if (depth == 0 && type == CPL_TYPE_FLOAT) {
293 float * data = cpl_table_get_data_float (table, name);
294 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
295 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
297 else if (depth == 0 && type == CPL_TYPE_INT) {
298 int * data = cpl_table_get_data_int (table, name);
299 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
300 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
302 else if (depth > 0) {
303 cpl_array ** arrays = cpl_table_get_data_array (table, name);
304 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, 0.0);
305 cpl_array * output = cpl_array_duplicate (arrays[base]);
306 cpl_ensure (output, CPL_ERROR_ILLEGAL_INPUT, 0.0);
307 for (cpl_size r=1; r<nrow;r++)
308 cpl_array_add (output, arrays[r*nbase+base]);
309 mean = cpl_array_get_mean (output);
310 FREE (cpl_array_delete, output);
313 cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
"unknow type");
322 cpl_ensure (table, CPL_ERROR_NULL_INPUT, 0.0);
323 cpl_ensure (name, CPL_ERROR_NULL_INPUT, 0.0);
327 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
328 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, 0.0);
330 cpl_type type = cpl_table_get_column_type (table, name);
331 cpl_size depth = cpl_table_get_column_depth (table, name);
333 if (depth == 0 && type == CPL_TYPE_DOUBLE) {
334 double * data = cpl_table_get_data_double (table, name);
335 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
336 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
337 for (cpl_size r=0; r<nrow;r++) mean2 += data[r*nbase+base] * data[r*nbase+base];
339 else if (depth == 0 && type == CPL_TYPE_FLOAT) {
340 float * data = cpl_table_get_data_float (table, name);
341 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
342 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
343 for (cpl_size r=0; r<nrow;r++) mean2 += data[r*nbase+base] * data[r*nbase+base];
345 else if (depth == 0 && type == CPL_TYPE_INT) {
346 int * data = cpl_table_get_data_int (table, name);
347 cpl_ensure (data, CPL_ERROR_ILLEGAL_INPUT, 0.0);
348 for (cpl_size r=0; r<nrow;r++) mean += data[r*nbase+base];
349 for (cpl_size r=0; r<nrow;r++) mean2 += data[r*nbase+base] * data[r*nbase+base];
352 cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
"unknow type");
356 return sqrt (mean2 / nrow - mean*mean / nrow / nrow);
361 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
362 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
364 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
365 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
368 cpl_array ** arrays = cpl_table_get_data_array (table, name);
369 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, NULL);
372 cpl_array * output = cpl_array_duplicate (arrays[base]);
375 for (cpl_size r=1; r<nrow;r++)
376 cpl_array_add (output, arrays[r*nbase+base]);
383 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
384 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
386 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
387 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
390 cpl_array ** arrays = cpl_table_get_data_array (table, name);
391 cpl_ensure (arrays, CPL_ERROR_ILLEGAL_INPUT, NULL);
394 cpl_array * output = cpl_array_duplicate (arrays[base]);
397 for (cpl_size r=1; r<nrow;r++)
398 cpl_array_add (output, arrays[r*nbase+base]);
400 cpl_array_divide_scalar (output, nrow);
407 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
408 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
410 cpl_size nrow = cpl_table_get_nrow (table);
411 cpl_array ** pdata = cpl_table_get_data_array (table, name);
413 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
414 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
417 double ** data = cpl_malloc (
sizeof(
double*) * nrow);
420 for (cpl_size row=0; row<nrow; row++) {
421 data[row] = cpl_array_get_data_double (pdata[row]);
431 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
432 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
434 cpl_size nrow = cpl_table_get_nrow (table);
435 cpl_array ** pdata = cpl_table_get_data_array (table, name);
437 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
438 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
441 float ** data = cpl_malloc (
sizeof(
float*) * nrow);
444 for (cpl_size row=0; row<nrow; row++) {
445 data[row] = cpl_array_get_data_float (pdata[row]);
455 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
456 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
458 cpl_size nrow = cpl_table_get_nrow (table);
459 cpl_array ** pdata = cpl_table_get_data_array (table, name);
461 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
462 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
465 float complex ** data = cpl_malloc (
sizeof(
float complex*) * nrow);
468 for (cpl_size row=0; row<nrow; row++) {
469 data[row] = cpl_array_get_data_float_complex (pdata[row]);
480 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
481 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
483 cpl_size nrow = cpl_table_get_nrow (table);
484 cpl_array ** pdata = cpl_table_get_data_array (table, name);
486 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
487 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
490 double complex ** data = cpl_malloc (
sizeof(
double complex*) * nrow);
493 for (cpl_size row=0; row<nrow; row++) {
494 data[row] = cpl_array_get_data_double_complex (pdata[row]);
504 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
505 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
507 cpl_size nrow = cpl_table_get_nrow (table);
508 cpl_array ** pdata = cpl_table_get_data_array (table, name);
510 cpl_ensure (nrow, CPL_ERROR_ILLEGAL_INPUT, NULL);
511 cpl_ensure (pdata, CPL_ERROR_ILLEGAL_INPUT, NULL);
514 int ** data = cpl_malloc (
sizeof(
int*) * nrow);
517 for (cpl_size row=0; row<nrow; row++) {
518 data[row] = cpl_array_get_data_int (pdata[row]);
531 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
532 cpl_array * output = cpl_array_new (n, CPL_TYPE_DOUBLE);
533 cpl_array_fill_window_double (output, 0, n, value);
542 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
543 cpl_array * output = cpl_array_new (n, CPL_TYPE_INT);
544 cpl_array_fill_window_int (output, 0, n, value);
553 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
554 cpl_array * output = cpl_array_new (n, CPL_TYPE_DOUBLE_COMPLEX);
555 cpl_array_fill_window_double_complex (output, 0, n, value);
564 cpl_ensure (n>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
565 cpl_array * output = cpl_array_new (n, CPL_TYPE_FLOAT_COMPLEX);
566 cpl_array_fill_window_float_complex (output, 0, n, value);
575 cpl_ensure (input_re, CPL_ERROR_NULL_INPUT, NULL);
576 cpl_ensure (input_im, CPL_ERROR_NULL_INPUT, NULL);
578 cpl_size size_re = cpl_array_get_size (input_re);
579 cpl_size size_im = cpl_array_get_size (input_im);
581 cpl_ensure (size_re == size_im, CPL_ERROR_ILLEGAL_INPUT, NULL);
583 cpl_array * output = cpl_array_new (size_re, CPL_TYPE_DOUBLE_COMPLEX);
585 for (cpl_size n = 0; n < size_re; n ++) {
586 cpl_array_set_complex (output, n, 1.* I * cpl_array_get (input_im, n, NULL) +
587 cpl_array_get (input_re, n, NULL));
598 cpl_ensure (input_re, CPL_ERROR_NULL_INPUT, NULL);
599 cpl_ensure (input_im, CPL_ERROR_NULL_INPUT, NULL);
601 cpl_size size_re = cpl_array_get_size (input_re);
602 cpl_size size_im = cpl_array_get_size (input_im);
604 cpl_ensure (size_re == size_im, CPL_ERROR_ILLEGAL_INPUT, NULL);
606 cpl_array * output = cpl_array_new (size_re, CPL_TYPE_FLOAT_COMPLEX);
609 for (cpl_size n = 0; n < size_re; n ++) {
610 cpl_array_set_float_complex (output, n, 1.* I * cpl_array_get (input_im, n, &nv) +
611 cpl_array_get (input_re, n, &nv));
622 cpl_ensure (input_re, CPL_ERROR_NULL_INPUT, NULL);
623 cpl_ensure (input_im, CPL_ERROR_NULL_INPUT, NULL);
625 cpl_size size_re = cpl_array_get_size (input_re);
626 cpl_size size_im = cpl_array_get_size (input_im);
628 cpl_ensure (size_re == size_im, CPL_ERROR_ILLEGAL_INPUT, NULL);
630 cpl_array * output = cpl_array_new (size_re, CPL_TYPE_DOUBLE);
631 cpl_array_fill_window_double (output, 0, size_re, 0.0);
634 for (cpl_size n = 0; n < size_re; n ++) {
635 cpl_array_set_double (output, n, pow(cpl_array_get (input_im, n, &nv),2) +
636 pow(cpl_array_get (input_re, n, &nv),2) );
652 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
653 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
654 cpl_ensure_code (visR, CPL_ERROR_NULL_INPUT);
655 cpl_ensure_code (visI, CPL_ERROR_NULL_INPUT);
658 cpl_table_set_array (table, name, row, tmp_cast);
659 cpl_array_delete (tmp_cast);
663 return CPL_ERROR_NONE;
672 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
673 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
674 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
676 cpl_array * tmp_cast;
677 if (cpl_array_get_type (phase) == CPL_TYPE_FLOAT_COMPLEX ||
678 cpl_array_get_type (phase) == CPL_TYPE_DOUBLE_COMPLEX ) {
679 tmp_cast = cpl_array_cast (phase, CPL_TYPE_DOUBLE_COMPLEX);
680 cpl_array_arg (tmp_cast);
682 tmp_cast = cpl_array_cast (phase, CPL_TYPE_DOUBLE);
684 cpl_array_multiply_scalar (tmp_cast, 180.0/ CPL_MATH_PI);
685 cpl_table_set_array (table, name, row, tmp_cast);
686 cpl_array_delete (tmp_cast);
690 return CPL_ERROR_NONE;
704 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
705 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
706 cpl_ensure_code (row>-1, CPL_ERROR_ILLEGAL_INPUT);
707 cpl_ensure_code (len>0, CPL_ERROR_ILLEGAL_INPUT);
709 char * str = cpl_sprintf (
"%-*.*s", len, len, value);
710 cpl_table_set_string (table, name, row, str);
712 FREE (cpl_free, str);
716 return CPL_ERROR_NONE;
725 cpl_table * oi_wave_sc, cpl_table * oi_wave_ft)
728 cpl_ensure (input, CPL_ERROR_NULL_INPUT, NULL);
729 cpl_ensure (errs, CPL_ERROR_NULL_INPUT, NULL);
730 cpl_ensure (oi_wave_sc, CPL_ERROR_NULL_INPUT, NULL);
731 cpl_ensure (oi_wave_ft, CPL_ERROR_NULL_INPUT, NULL);
734 float *effWave_sc = cpl_table_get_data_float (oi_wave_sc,
"EFF_WAVE");
735 float *effWave_ft = cpl_table_get_data_float (oi_wave_ft,
"EFF_WAVE");
736 float *effBand_ft = cpl_table_get_data_float (oi_wave_ft,
"EFF_BAND");
737 cpl_size nwave_ft = cpl_table_get_nrow (oi_wave_ft);
738 cpl_size nwave_sc = cpl_table_get_nrow (oi_wave_sc);
742 cpl_array * output = cpl_array_new (nwave_ft, CPL_TYPE_DOUBLE);
743 cpl_array * weight = cpl_array_new (nwave_ft, CPL_TYPE_DOUBLE);
746 for (cpl_size wft = 0; wft < nwave_ft; wft++) {
747 for (cpl_size wsc = 0; wsc < nwave_sc; wsc++)
748 if ( fabs (effWave_sc[wsc] - effWave_ft[wft]) < 0.5 * effBand_ft[wft] ) {
750 double v = cpl_array_get (input, wsc, NULL);
751 double w = cpl_array_get (errs, wsc, NULL);
754 cpl_array_set (output, wft, cpl_array_get (output, wft, NULL) + v * w);
755 cpl_array_set (weight, wft, cpl_array_get (weight, wft, NULL) + w);
761 cpl_array_divide (output, weight);
762 cpl_array_delete (weight);
773 cpl_table * oi_vis2,
const char *name2)
776 cpl_ensure_code (oi_vis1, CPL_ERROR_NULL_INPUT);
777 cpl_ensure_code (oi_vis2, CPL_ERROR_NULL_INPUT);
778 cpl_ensure_code (name1, CPL_ERROR_NULL_INPUT);
779 cpl_ensure_code (name2, CPL_ERROR_NULL_INPUT);
784 cpl_type type1 = cpl_table_get_column_type (oi_vis1, name1);
785 cpl_type type2 = cpl_table_get_column_type (oi_vis2, name2);
786 cpl_size nrow1 = cpl_table_get_nrow (oi_vis1);
787 cpl_size nrow2 = cpl_table_get_nrow (oi_vis2);
790 if ( type1 != type2 || nrow1 != nrow2) {
791 return cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
792 "input columns not conformables");
795 if ( type1 == CPL_TYPE_DOUBLE ) {
796 double * data1 = cpl_table_get_data_double (oi_vis1, name1);
797 double * data2 = cpl_table_get_data_double (oi_vis2, name2);
800 for (row=0 ; row<nrow1 ; row++) data1[row] += data2[row];
802 else if ( type1 == CPL_TYPE_FLOAT_COMPLEX ) {
803 float complex * data1 = cpl_table_get_data_float_complex (oi_vis1, name1);
804 float complex * data2 = cpl_table_get_data_float_complex (oi_vis2, name2);
807 for (row=0 ; row<nrow1; row++) data1[row] += data2[row];
809 else if ( type1 == CPL_TYPE_DOUBLE_COMPLEX ) {
810 double complex * data1 = cpl_table_get_data_double_complex (oi_vis1, name1);
811 double complex * data2 = cpl_table_get_data_double_complex (oi_vis2, name2);
814 for (row=0 ; row<nrow1; row++) data1[row] += data2[row];
816 else if ( type1 & CPL_TYPE_POINTER ) {
817 cpl_array ** data1 = cpl_table_get_data_array (oi_vis1, name1);
818 cpl_array ** data2 = cpl_table_get_data_array (oi_vis2, name2);
821 for (row=0 ; row<nrow1; row++) {
822 cpl_array_add (data1[row], data2[row]);
826 return cpl_error_set_message (cpl_func,CPL_ERROR_ILLEGAL_INPUT,
827 "unknow type -- report to DRS team");
832 return CPL_ERROR_NONE;
844 const char *input_name,
845 const char *output_name,
846 int nsmooth,
int nbase)
849 cpl_ensure_code (oi_vis, CPL_ERROR_NULL_INPUT);
850 cpl_ensure_code (input_name, CPL_ERROR_NULL_INPUT);
851 cpl_ensure_code (output_name, CPL_ERROR_NULL_INPUT);
852 cpl_ensure_code (nsmooth>=0, CPL_ERROR_ILLEGAL_INPUT);
853 cpl_ensure_code (nbase>0, CPL_ERROR_ILLEGAL_INPUT);
856 int row_add, row_sub;
858 cpl_type type = cpl_table_get_column_type (oi_vis, input_name);
859 cpl_size nrow = cpl_table_get_nrow (oi_vis) / nbase;
861 if ( type == CPL_TYPE_DOUBLE ) {
862 double * data = cpl_table_get_data_double (oi_vis, input_name);
863 double * output = cpl_malloc (
sizeof(
double) * nrow * nbase);
869 for ( base=0 ; base<nbase ; base++) {
872 for ( row=-nsmooth ; row<nrow ; row++) {
873 row_add = row+nsmooth;
874 row_sub = row-nsmooth-1;
875 if ( row_add < nrow ) buffer += data[row_add * nbase + base];
876 if ( row_sub >= 0 ) buffer -= data[row_sub * nbase + base];
877 if( row>=0 && row<nrow ) output[row * nbase + base] = (double)(buffer);
884 if ( !strcmp (input_name, output_name)) {
885 for (row = 0; row < nrow * nbase; row++) data[row] = output[row];
888 if (cpl_table_has_column (oi_vis, output_name))
889 cpl_table_erase_column (oi_vis, output_name);
890 cpl_table_wrap_double (oi_vis, output, output_name);
894 else if ( type == CPL_TYPE_DOUBLE_COMPLEX ) {
895 double complex * data = cpl_table_get_data_double_complex (oi_vis, input_name);
896 double complex * output = cpl_malloc (
sizeof(
double complex) * nrow * nbase);
897 double complex buffer = 0.0;
902 for ( base=0 ; base<nbase ; base++) {
905 for ( row=-nsmooth ; row<nrow ; row++) {
906 row_add = row+nsmooth;
907 row_sub = row-nsmooth-1;
908 if ( row_add < nrow ) buffer += data[row_add * nbase + base];
909 if ( row_sub >= 0 ) buffer -= data[row_sub * nbase + base];
910 if( row>=0 && row<nrow ) output[row * nbase + base] = (
double complex)(buffer);
916 if ( !strcmp (input_name, output_name)) {
917 for (row = 0; row < nrow * nbase; row++) data[row] = output[row];
920 if (cpl_table_has_column (oi_vis, output_name))
921 cpl_table_erase_column (oi_vis, output_name);
922 cpl_table_wrap_double_complex (oi_vis, output, output_name);
927 return cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
928 "This type is not supported..."
929 "report this error to DRS team !!");
933 return CPL_ERROR_NONE;
937 const char *input_name,
938 const char *output_name,
939 int nsmooth,
int nbase)
942 cpl_ensure_code (oi_vis, CPL_ERROR_NULL_INPUT);
943 cpl_ensure_code (input_name, CPL_ERROR_NULL_INPUT);
944 cpl_ensure_code (output_name, CPL_ERROR_NULL_INPUT);
945 cpl_ensure_code (nsmooth>0, CPL_ERROR_ILLEGAL_INPUT);
946 cpl_ensure_code (nbase>0, CPL_ERROR_ILLEGAL_INPUT);
950 cpl_table_divide_scalar (oi_vis, output_name, 2.0*(
double)nsmooth+1.0);
953 return CPL_ERROR_NONE;
959 cpl_size size = cpl_table_get_nrow (oi_wave);
960 cpl_array * sigma = cpl_array_new (size, CPL_TYPE_DOUBLE);
962 for (cpl_size w = 0; w<size; w++ )
963 cpl_array_set (sigma, w, 1./cpl_table_get (oi_wave,
"EFF_WAVE", w, &nv));
965 CPLCHECK_NUL(
"Cannot compute the sigma array from EFF_WAVE");
971 cpl_ensure (oi_wave, CPL_ERROR_NULL_INPUT, NULL);
974 cpl_size size = cpl_table_get_nrow (oi_wave);
975 cpl_array * wave = cpl_array_new (size, CPL_TYPE_FLOAT);
977 for (cpl_size w = 0; w<size; w++ )
978 cpl_array_set (wave, w, cpl_table_get (oi_wave,
"EFF_WAVE", w, &nv));
980 CPLCHECK_NUL(
"Cannot compute the wave array from EFF_WAVE");
987 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
990 cpl_size size = cpl_array_get_size (input);
992 double complex cpx = 0.0 * I + 0.0;
993 for (cpl_size wave = 0; wave<size; wave++ ) {
994 cpx = cpl_array_get_complex (input,wave,&nv);
995 cpl_array_set_complex (input, wave, cpx / cabs (cpx));
996 if (nv) {cpl_array_set_invalid (input, wave); nv=0;}
1000 return CPL_ERROR_NONE;
1005 cpl_ensure (input, CPL_ERROR_NULL_INPUT, NULL);
1007 cpl_size size = cpl_array_get_size (input);
1009 cpl_array * inv = cpl_array_new (size, CPL_TYPE_DOUBLE);
1010 cpl_array_fill_window (inv, 0, size, 1.0);
1011 cpl_array_divide (inv, input);
1013 CPLCHECK_NUL(
"Cannot compute the sigma array from wave");
1022 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1024 cpl_size size_x = cpl_array_get_size (input);
1025 double phi_i, phi_ii, d_phi;
1028 for (cpl_size i_data = 1; i_data < size_x; i_data++){
1033 phi_i = cpl_array_get(input, i_data, NULL);
1034 phi_ii = cpl_array_get(input, i_data-1, NULL);
1036 d_phi = phi_i + k_wrap * 2 * M_PI - phi_ii;
1038 if (d_phi > M_PI) k_wrap --;
1039 if (d_phi < - M_PI) k_wrap ++;
1041 cpl_array_set(input, i_data, cpl_array_get(input, i_data, NULL) + k_wrap * 2 * M_PI);
1045 return CPL_ERROR_NONE;
1053 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1055 cpl_size size = cpl_array_get_size (input);
1057 for (cpl_size wave = 0; wave<size; wave++ ) {
1058 cpl_array_set (input, wave, carg (cexp ( 1.0 * I * cpl_array_get (input, wave, NULL))));
1062 return CPL_ERROR_NONE;
1071 cpl_ensure (input, CPL_ERROR_NULL_INPUT, NULL);
1073 cpl_size size = cpl_array_get_size (input);
1075 cpl_array * output = cpl_array_new (size, CPL_TYPE_DOUBLE_COMPLEX);
1076 cpl_array_fill_window_complex (output, 0, size, (
double complex)(0.0 + 0.0 * I));
1080 for (n = 0; n < size; n ++) {
1081 cpl_array_set_complex (output, n, cexp (factor * cpl_array_get (input, n, &nv) ) );
1093 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1094 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
1096 cpl_size size_in = cpl_array_get_size (input);
1097 cpl_size size_ph = cpl_array_get_size (phase);
1099 cpl_ensure_code (size_in == size_ph, CPL_ERROR_ILLEGAL_INPUT);
1103 for (n = 0; n < size_in; n ++) {
1104 cpl_array_set_complex( input, n,
1105 cpl_array_get_complex( input, n, &nv) *
1106 cexp ( factor * cpl_array_get( phase, n, &nv) ) );
1110 return CPL_ERROR_NONE;
1119 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1120 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
1122 cpl_size size_in = cpl_array_get_size (input);
1123 cpl_size size_ph = cpl_array_get_size (phase);
1125 cpl_ensure_code (size_in == size_ph, CPL_ERROR_ILLEGAL_INPUT);
1129 for (n = 0; n < size_in; n ++) {
1130 cpl_array_set_complex( input, n,
1131 cpl_array_get_complex( input, n, &nv) +
1132 cexp ( factor * cpl_array_get( phase, n, &nv) ) );
1136 return CPL_ERROR_NONE;
1145 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1146 cpl_ensure_code (add, CPL_ERROR_NULL_INPUT);
1147 cpl_ensure_code (sub, CPL_ERROR_NULL_INPUT);
1149 cpl_size size_in = cpl_array_get_size (input);
1150 cpl_size size_add = cpl_array_get_size (add);
1151 cpl_size size_sub = cpl_array_get_size (sub);
1153 cpl_ensure_code (size_in == size_add, CPL_ERROR_ILLEGAL_INPUT);
1154 cpl_ensure_code (size_in == size_sub, CPL_ERROR_ILLEGAL_INPUT);
1158 for (n = 0; n < size_in; n ++) {
1159 cpl_array_set_complex (input, n,
1160 cpl_array_get_complex (input, n, &nv) +
1161 cpl_array_get_complex (add, n, &nv) *
1162 conj (cpl_array_get_complex (sub, n, &nv)));
1166 return CPL_ERROR_NONE;
1175 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1176 cpl_ensure_code (phase, CPL_ERROR_NULL_INPUT);
1178 cpl_size size_in = cpl_array_get_size (input);
1179 cpl_size size_ph = cpl_array_get_size (phase);
1181 cpl_ensure_code (size_in == size_ph, CPL_ERROR_ILLEGAL_INPUT);
1183 cpl_array * tmp = cpl_array_duplicate (phase);
1185 cpl_array_multiply_scalar (tmp, factor);
1186 cpl_array_add (input, tmp);
1188 cpl_array_delete (tmp);
1191 return CPL_ERROR_NONE;
1196 cpl_ensure_code (input1, CPL_ERROR_NULL_INPUT);
1197 cpl_ensure_code (input2, CPL_ERROR_NULL_INPUT);
1199 cpl_size size_in1 = cpl_array_get_size (input1);
1200 cpl_size size_in2 = cpl_array_get_size (input2);
1202 cpl_ensure_code (size_in1 == size_in2, CPL_ERROR_ILLEGAL_INPUT);
1204 for (cpl_size w = 0 ; w < size_in1 ; w++)
1205 cpl_array_set_complex (input1, w, cpl_array_get_complex (input1, w, NULL) *
1206 conj(cpl_array_get_complex (input2, w, NULL)));
1209 return CPL_ERROR_NONE;
1219 cpl_ensure (DIT_smooth>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1220 cpl_ensure (input_array, CPL_ERROR_NULL_INPUT, NULL);
1222 cpl_type type = cpl_array_get_type (input_array);
1223 cpl_size nrow = cpl_array_get_size ( input_array );
1226 if (nrow-DIT_smooth*2-1<0) DIT_smooth=nrow/2;
1229 cpl_array * output_smooth_array;
1232 if ( type == CPL_TYPE_DOUBLE ) {
1233 double* input = cpl_array_get_data_double (input_array);
1234 double* output_smooth = cpl_malloc (nrow *
sizeof(
double));
1235 double data_carrier = 0.0;
1238 int int_carrier = 0;
1239 for (cpl_size row = - DIT_smooth; row < 0; row ++)
1241 data_carrier+=input[row+DIT_smooth];
1244 for (cpl_size row = 0; row < DIT_smooth+1; row ++)
1246 data_carrier+=input[row+DIT_smooth];
1248 output_smooth[row]=data_carrier/int_carrier;
1250 double inv_int_carrier= 1.0/int_carrier;
1251 for (cpl_size row = DIT_smooth+1; row < nrow-DIT_smooth; row ++)
1253 data_carrier-=input[row-DIT_smooth-1];
1254 data_carrier+=input[row+DIT_smooth];
1255 output_smooth[row]=data_carrier*inv_int_carrier;
1257 for (cpl_size row = nrow-DIT_smooth; row < nrow; row ++)
1259 data_carrier-=input[row-DIT_smooth-1];
1261 output_smooth[row]=data_carrier/int_carrier;
1265 output_smooth_array=cpl_array_wrap_double (output_smooth, nrow);
1267 }
else if ( type == CPL_TYPE_DOUBLE_COMPLEX ){
1268 double complex * input = cpl_array_get_data_double_complex (input_array);
1269 double complex * output_smooth = cpl_malloc (nrow *
sizeof(
double complex));
1270 double complex data_carrier = 0.0;
1273 int int_carrier = 0;
1274 for (cpl_size row = - DIT_smooth; row < 0; row ++)
1276 data_carrier+=input[row+DIT_smooth];
1279 for (cpl_size row = 0; row < DIT_smooth+1; row ++)
1281 data_carrier+=input[row+DIT_smooth];
1283 output_smooth[row]=data_carrier/int_carrier;
1285 double inv_int_carrier= 1.0/int_carrier;
1286 for (cpl_size row = DIT_smooth+1; row < nrow-DIT_smooth; row ++)
1288 data_carrier-=input[row-DIT_smooth-1];
1289 data_carrier+=input[row+DIT_smooth];
1290 output_smooth[row]=data_carrier*inv_int_carrier;
1292 for (cpl_size row = nrow-DIT_smooth; row < nrow; row ++)
1294 data_carrier-=input[row-DIT_smooth-1];
1296 output_smooth[row]=data_carrier/int_carrier;
1300 output_smooth_array=cpl_array_wrap_double_complex (output_smooth, nrow);
1304 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1305 "This type is not supported... report this error to DRS team !!");
1308 return output_smooth_array;
1338 double * gd, cpl_size nrow,
1343 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1344 cpl_ensure_code (sigma, CPL_ERROR_NULL_INPUT);
1345 cpl_ensure_code (gd, CPL_ERROR_ILLEGAL_OUTPUT);
1348 cpl_size nsigma = cpl_array_get_size (sigma);
1349 double width1, step1, width2, step2, width3, step3;
1350 cpl_size w, s, nstep1, nstep2, nstep3;
1351 double x, gd0, gd1, gd2, gd3, current_max = -1.0;
1352 double lbd = 1.0 / cpl_array_get (sigma,nsigma/2,&nv);
1355 double coherence = 0.5 * nsigma / fabs (cpl_array_get (sigma,0,&nv) - cpl_array_get (sigma,nsigma-1,&nv));
1358 width1 = CPL_MIN (coherence, max_width);
1360 nstep1 = (cpl_size)(width1/step1);
1363 width2 = 3.0 * step1;
1365 nstep2 = (cpl_size)(width2/step2);
1368 width3 = 3.0 * step2;
1370 nstep3 = (cpl_size)(width3/step3);
1374 double * sigdata = cpl_malloc (
sizeof(
double complex) * nsigma);
1375 double complex * visdata = cpl_malloc (
sizeof(
double complex) * nsigma);
1376 double complex * waveform1 = cpl_malloc (
sizeof(
double complex) * (nstep1+2) * nsigma);
1377 double complex * waveform2 = cpl_malloc (
sizeof(
double complex) * (nstep2+2) * nsigma);
1378 double complex * waveform3 = cpl_malloc (
sizeof(
double complex) * (nstep3+2) * nsigma);
1381 for (w=0; w<nsigma; w++) sigdata[w] = cpl_array_get (sigma, w, &nv);
1385 for (w=1; w<nsigma; w++) ds += sigdata[w] - sigdata[w-1];
1389 cpl_msg_debug (cpl_func,
"Build waveform for 3 pass -- %lli %lli %lli steps", nstep1, nstep2, nstep3);
1391 for (s=0, x = -width1/2.0; x < +width1/2.0; x+=step1)
1392 for (w=0; w<nsigma; w++) { waveform1[s] = cexp (-2.*I*CPL_MATH_PI * x * sigdata[w]); s++;}
1393 for (s=0, x = -width2/2.0; x < +width2/2.0; x+=step2)
1394 for (w=0; w<nsigma; w++) { waveform2[s] = cexp (-2.*I*CPL_MATH_PI * x * sigdata[w]); s++;}
1395 for (s=0, x = -width3/2.0; x < +width3/2.0; x+=step3)
1396 for (w=0; w<nsigma; w++) { waveform3[s] = cexp (-2.*I*CPL_MATH_PI * x * sigdata[w]); s++;}
1398 cpl_msg_debug (cpl_func,
"Loop on %lli rows to compute gdelay", nrow);
1401 for (cpl_size row = 0; row<nrow; row++) {
1405 for (w=0; w<nsigma; w++) {
1406 if (flag && cpl_array_get (flag[row], w, &nv)) visdata[w] = 0. + I*0.;
1407 else visdata[w] = cpl_array_get_complex (input[row], w, &nv);
1412 double complex is = 0.0 + I * 0.0;
1413 for (w=1; w<nsigma; w++) {
1414 is += visdata[w] * conj(visdata[w-1]) / CPL_MAX(cabs(visdata[w]) * cabs(visdata[w-1]), 1e-15);
1416 gd0 = carg (is) / ds / CPL_MATH_2PI;
1419 for (w=0; w<nsigma; w++) visdata[w] *= cexp (-2.*I*CPL_MATH_PI*gd0*sigdata[w]);
1422 for (current_max = -1.0, s = 0, x = -width1/2; x < +width1/2; x+=step1) {
1423 double complex tmp = 0.0 * I + 0.0;
1424 for (w=0; w<nsigma; w++) {tmp += visdata[w] * waveform1[s]; s++;}
1426 if ( P > current_max) { current_max = P; gd1 = x; }
1430 for (w=0; w<nsigma; w++) visdata[w] *= cexp (-2.*I*CPL_MATH_PI*gd1*sigdata[w]);
1433 for (current_max = -1.0, s = 0, x = -width2/2; x < +width2/2; x+=step2) {
1434 double complex tmp = 0.0 * I + 0.0;
1435 for (w=0; w<nsigma; w++) {tmp += visdata[w] * waveform2[s]; s++;}
1437 if ( P > current_max) { current_max = P; gd2 = x; }
1441 for (w=0; w<nsigma; w++) visdata[w] *= cexp (-2.*I*CPL_MATH_PI*gd2*sigdata[w]);
1444 for (current_max = -1.0, s = 0, x = -width3/2; x < +width3/2; x+=step3) {
1445 double complex tmp = 0.0 * I + 0.0;
1446 for (w=0; w<nsigma; w++) {tmp += visdata[w] * waveform3[s]; s++;}
1448 if ( P > current_max) { current_max = P; gd3 = x; }
1451 gd[row] = gd0 + gd1 + gd2 + gd3;
1457 FREE (cpl_free, visdata);
1458 FREE (cpl_free, sigdata);
1459 FREE (cpl_free, waveform1);
1460 FREE (cpl_free, waveform2);
1461 FREE (cpl_free, waveform3);
1464 return CPL_ERROR_NONE;
1470 const char *output, cpl_table * oi_wave)
1473 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1474 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1475 cpl_ensure_code (flag, CPL_ERROR_NULL_INPUT);
1476 cpl_ensure_code (output, CPL_ERROR_NULL_INPUT);
1477 cpl_ensure_code (oi_wave, CPL_ERROR_NULL_INPUT);
1480 cpl_size nwave = cpl_table_get_nrow (oi_wave);
1481 cpl_array * sigma = cpl_array_new (nwave, CPL_TYPE_DOUBLE);
1482 for (cpl_size wave = 0; wave < nwave ; wave ++)
1483 cpl_array_set (sigma, wave, 1./cpl_table_get (oi_wave,
"EFF_WAVE", wave, NULL));
1487 double * gdelay = cpl_table_get_data_double (table, output);
1490 cpl_array ** input_arrays = cpl_table_get_data_array (table, input);
1491 cpl_array ** flag_arrays = cpl_table_get_data_array (table, flag);
1492 cpl_size nrow = cpl_table_get_nrow (table);
1500 nrow, 1.e-3, CPL_TRUE);
1501 FREE (cpl_array_delete, sigma);
1504 return CPL_ERROR_NONE;
1520 cpl_ensure_code (first, CPL_ERROR_NULL_INPUT);
1521 cpl_ensure_code (second, CPL_ERROR_NULL_INPUT);
1523 cpl_size nrow = cpl_table_get_nrow (first);
1524 cpl_size ncol = cpl_table_get_ncol (first);
1527 if (nrow != cpl_table_get_nrow (second)) {
cpl_msg_info(cpl_func,
"Different rows");
return 0;}
1528 if (ncol != cpl_table_get_ncol (second)) {
cpl_msg_info(cpl_func,
"Different cols");
return 0;}
1529 if (cpl_table_compare_structure (first, second)) {
cpl_msg_info(cpl_func,
"Different structure");
return 0;}
1532 cpl_array *names = cpl_table_get_column_names (first);
1535 for (cpl_size c = 0; c<ncol; c++) {
1536 const char * name = cpl_array_get_string (names, c);
1540 int type = cpl_table_get_column_type (first, name);
1543 case CPL_TYPE_STRING:
1544 for (cpl_size r = 0; r<nrow; r++)
1545 if (strcmp (cpl_table_get_string (first, name, r),
1546 cpl_table_get_string (second, name, r) ) )
1547 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1549 case CPL_TYPE_DOUBLE:
1550 case CPL_TYPE_FLOAT:
1552 for (cpl_size r = 0; r<nrow; r++)
1553 if (cpl_table_get (first, name, r, &nv) !=
1554 cpl_table_get (second, name, r, &nv) )
1555 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1557 case CPL_TYPE_POINTER|CPL_TYPE_STRING:
1558 for (cpl_size r = 0; r<nrow; r++)
1559 for (cpl_size p = 0; p<cpl_table_get_column_depth (first,name); p++)
1560 if ( strcmp (cpl_array_get_string (cpl_table_get_array (first, name, r), p),
1561 cpl_array_get_string (cpl_table_get_array (second, name, r), p)) )
1562 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1564 case CPL_TYPE_POINTER|CPL_TYPE_DOUBLE:
1565 case CPL_TYPE_POINTER|CPL_TYPE_FLOAT:
1566 case CPL_TYPE_POINTER|CPL_TYPE_INT:
1567 for (cpl_size r = 0; r<nrow; r++)
1568 for (cpl_size p = 0; p<cpl_table_get_column_depth (first,name); p++) {
1569 if (cpl_array_get (cpl_table_get_array (first, name, r), p, NULL) !=
1570 cpl_array_get (cpl_table_get_array (second, name, r), p, NULL) )
1571 {
cpl_msg_info (cpl_func,
"Different values in column %s, row %lli", name,r);
return 0;}
1575 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"Cannot compare these tables (TBD, FIXME)");
1582 FREE (cpl_array_delete, names);
1590 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1591 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1593 if ( cpl_table_has_column (table, name) &&
1594 cpl_table_get_column_type (table, name) == type) {
1595 cpl_msg_info (cpl_func,
"Column %s already exists", name);
1597 cpl_table_new_column (table, name, type);
1600 if (type == CPL_TYPE_DOUBLE_COMPLEX || type == CPL_TYPE_FLOAT_COMPLEX)
1601 cpl_table_fill_column_window_complex (table, name, 0, cpl_table_get_nrow (table), 0.0 + I*0.0);
1603 cpl_table_fill_column_window (table, name, 0, cpl_table_get_nrow (table), 0.0);
1605 if (unit) cpl_table_set_column_unit (table, name, unit);
1607 return CPL_ERROR_NONE;
1612 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1613 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1615 if ( cpl_table_has_column (table, name) )
1616 cpl_table_erase_column (table, name);
1618 cpl_table_new_column_array (table, name, type, size);
1619 if (unit) cpl_table_set_column_unit (table, name, unit);
1621 return CPL_ERROR_NONE;
1626 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1627 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1629 if ( cpl_table_has_column (table, name) )
1630 cpl_table_erase_column (table, name);
1632 cpl_table_new_column_array (table, name, type, size);
1633 if (unit) cpl_table_set_column_unit (table, name, unit);
1635 cpl_array * array = cpl_array_new (size, type);
1636 cpl_array_fill_window (array, 0, size, 0.0);
1638 cpl_size nrow = cpl_table_get_nrow (table);
1639 for (cpl_size row = 0; row < nrow; row++)
1640 cpl_table_set_array (table, name, row, array);
1642 FREE (cpl_array_delete, array);
1644 return CPL_ERROR_NONE;
1661 cpl_ensure_code (imglist, CPL_ERROR_NULL_INPUT);
1663 cpl_size nrow = cpl_imagelist_get_size (imglist);
1665 for (cpl_size i = nrow-1; i>=0 ; i--) {
1666 cpl_image_unwrap (cpl_imagelist_unset (imglist, i));
1670 cpl_imagelist_delete (imglist);
1673 return CPL_ERROR_NONE;
1692 cpl_ensure (table_data, CPL_ERROR_NULL_INPUT, NULL);
1693 cpl_ensure (data_x, CPL_ERROR_NULL_INPUT, NULL);
1697 int type_column = cpl_table_get_column_type (table_data, data_x);
1700 cpl_size nrow = cpl_table_get_nrow (table_data);
1701 cpl_array ** array = cpl_table_get_data_array (table_data, data_x);
1702 cpl_ensure (array, CPL_ERROR_ILLEGAL_INPUT, NULL);
1706 if (cpl_table_get_column_dimensions (table_data, data_x)<2) {
1707 nx = cpl_table_get_column_depth (table_data, data_x);
1710 nx = cpl_table_get_column_dimension (table_data, data_x, 0);
1711 ny = cpl_table_get_column_dimension (table_data, data_x, 1);
1717 cpl_imagelist * imglist = cpl_imagelist_new();
1720 switch (type_column)
1722 case CPL_TYPE_POINTER|CPL_TYPE_DOUBLE :
1724 for (cpl_size j = 0; j < nrow ; j++)
1726 img = cpl_image_wrap_double (nx, ny, cpl_array_get_data_double(array[j]));
1727 cpl_imagelist_set (imglist, img, j);
1732 case CPL_TYPE_POINTER|CPL_TYPE_INT :
1734 for (cpl_size j = 0; j < nrow ; j++)
1736 img = cpl_image_wrap_int (nx, ny, cpl_array_get_data_int(array[j]));
1737 cpl_imagelist_set (imglist, img,j);
1742 case CPL_TYPE_POINTER|CPL_TYPE_FLOAT :
1743 for (cpl_size j = 0; j < nrow ; j++)
1745 img = cpl_image_wrap_float (nx, ny, cpl_array_get_data_float(array[j]));
1746 cpl_imagelist_set (imglist, img, j);
1753 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
1754 "invalid type of image coming from %s", data_x);
1755 cpl_imagelist_delete (imglist);
1772 cpl_size llx, cpl_size lly,
1773 cpl_size urx, cpl_size ury)
1776 cpl_ensure (img, CPL_ERROR_NULL_INPUT, -1);
1780 cpl_vector * flux = cpl_vector_new ((urx-llx+1)*(ury-lly+1));
1782 for (cpl_size v = 0, x = llx; x <= urx; x++) {
1783 for (cpl_size y = lly; y <= ury; y++) {
1784 cpl_vector_set (flux, v, cpl_image_get (img, x, y, &nv));
1794 cpl_vector_multiply (flux, flux);
1796 double RMS = sqrt (cpl_vector_get_median (flux));
1797 FREE (cpl_vector_delete, flux);
1819 cpl_ensure (img, CPL_ERROR_NULL_INPUT, NULL);
1820 cpl_ensure (drop_from < drop_to, CPL_ERROR_ILLEGAL_INPUT, NULL);
1823 cpl_size nx = cpl_image_get_size_x (img);
1824 cpl_size ny = cpl_image_get_size_y (img);
1827 cpl_ensure (drop_from >0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1828 cpl_ensure (drop_to <=nx, CPL_ERROR_ILLEGAL_INPUT, NULL);
1831 cpl_mask * mask = cpl_mask_new (nx, ny);
1832 for (cpl_size y = 1; y <= ny; y++)
1833 for (cpl_size x = drop_from; x <= drop_to ; x++)
1834 cpl_mask_set (mask, x, y, CPL_BINARY_1);
1837 cpl_mask * bpm = cpl_image_set_bpm (img, mask);
1840 cpl_image * collapse = cpl_image_collapse_median_create (img, 1, 0, 0);
1843 mask = cpl_image_set_bpm (img, bpm);
1844 FREE (cpl_mask_delete, mask);
1854 const cpl_image * collapse,
1858 cpl_ensure_code (img, CPL_ERROR_NULL_INPUT);
1859 cpl_ensure_code (collapse, CPL_ERROR_NULL_INPUT);
1860 cpl_ensure_code (direction==0 || direction==1, CPL_ERROR_ILLEGAL_INPUT);
1865 cpl_size nx = cpl_image_get_size_x (img);
1866 cpl_size ny = cpl_image_get_size_y (img);
1868 if (direction == 0) {
1870 cpl_ensure_code (cpl_image_get_size_x (collapse) == nx &&
1871 cpl_image_get_size_y (collapse) == 1,
1872 CPL_ERROR_ILLEGAL_INPUT);
1874 for (cpl_size x = 0; x < nx ; x++) {
1875 double value = cpl_image_get (collapse, x+1, 1, &nv);
1876 for (cpl_size y = 0; y < ny ; y++) {
1877 cpl_image_set (img, x+1, y+1, cpl_image_get (img, x+1, y+1, &nv) - value);
1884 cpl_ensure_code (cpl_image_get_size_x (collapse) == 1 &&
1885 cpl_image_get_size_y (collapse) == ny,
1886 CPL_ERROR_ILLEGAL_INPUT);
1888 for (cpl_size y = 0; y < ny ; y++) {
1889 double value = cpl_image_get (collapse, 1, y+1, &nv);
1890 for (cpl_size x = 0; x < nx ; x++) {
1891 cpl_image_set (img, x+1, y+1, cpl_image_get (img, x+1, y+1, &nv) - value);
1898 return CPL_ERROR_NONE;
1904 cpl_size llx, cpl_size lly,
1905 cpl_size urx, cpl_size ury,
1906 cpl_size llx2, cpl_size lly2)
1909 cpl_ensure_code (img1, CPL_ERROR_NULL_INPUT);
1910 cpl_ensure_code (img2, CPL_ERROR_NULL_INPUT);
1913 cpl_size nx = cpl_image_get_size_x (img1);
1914 cpl_size ny = cpl_image_get_size_y (img1);
1916 urx = CPL_MIN (urx, nx);
1917 ury = CPL_MIN (ury, ny);
1922 for (cpl_size x=llx; x<=urx; x++) {
1923 for (cpl_size y=lly; y<=ury; y++) {
1924 cpl_image_set (img1, x, y,
1925 cpl_image_get (img1,x,y,&nv) -
1926 cpl_image_get (img2,x+llx2,y+lly2,&nv));
1931 return CPL_ERROR_NONE;
1937 cpl_size llx, cpl_size lly,
1938 cpl_size urx, cpl_size ury,
1939 cpl_size llx2, cpl_size lly2)
1942 cpl_ensure_code (img1, CPL_ERROR_NULL_INPUT);
1943 cpl_ensure_code (img2, CPL_ERROR_NULL_INPUT);
1946 cpl_size nx = cpl_image_get_size_x (img1);
1947 cpl_size ny = cpl_image_get_size_y (img1);
1948 cpl_size nx2 = cpl_image_get_size_x (img2);
1949 cpl_size ny2 = cpl_image_get_size_y (img2);
1950 cpl_msg_info(cpl_func,
"Size image 1 %lli/%lli, Size window %lli/%lli" , nx,ny,nx2,ny2);
1952 urx = CPL_MIN (urx, nx);
1953 ury = CPL_MIN (ury, ny);
1958 for (cpl_size x=llx; x<=urx; x++) {
1959 for (cpl_size y=lly; y<=ury; y++) {
1960 cpl_image_set (img1, x, y,
1961 cpl_image_get (img2,x+llx2,y+lly2,&nv));
1966 return CPL_ERROR_NONE;
1987 cpl_ensure (table_data, CPL_ERROR_NULL_INPUT, NULL);
1988 cpl_ensure (data_x, CPL_ERROR_NULL_INPUT, NULL);
1989 cpl_ensure (row < cpl_table_get_nrow (table_data), CPL_ERROR_ILLEGAL_INPUT, NULL);
1992 cpl_ensure (wrap_imglist, CPL_ERROR_ILLEGAL_INPUT, NULL);
1994 cpl_image * out_img = cpl_image_duplicate (cpl_imagelist_get (wrap_imglist, row));
2019 cpl_ensure (table_data, CPL_ERROR_NULL_INPUT, NULL);
2020 cpl_ensure (data_x, CPL_ERROR_NULL_INPUT, NULL);
2023 cpl_ensure (wrap_imglist, CPL_ERROR_ILLEGAL_INPUT, NULL);
2025 cpl_imagelist * out_imglist = cpl_imagelist_duplicate (wrap_imglist);
2048 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
2049 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
2051 cpl_size ndim = cpl_table_get_column_dimensions (table, name);
2052 cpl_array * dimension = cpl_array_new (ndim, CPL_TYPE_INT);
2053 for (cpl_size dim = 0; dim < ndim; dim++) {
2054 int value = cpl_table_get_column_dimension (table, name, dim);
2055 cpl_array_set (dimension, dim, value);
2075 cpl_ensure (img, CPL_ERROR_NULL_INPUT, NULL);
2077 cpl_type type_img = cpl_image_get_type (img);
2078 int x = cpl_image_get_size_x (img);
2079 int y = cpl_image_get_size_y (img);
2083 cpl_array * array = NULL;
2085 case CPL_TYPE_FLOAT :
2086 array = cpl_array_wrap_float (cpl_image_get_data_float(img), x*y);
2088 case CPL_TYPE_DOUBLE :
2089 array = cpl_array_wrap_double (cpl_image_get_data_double(img), x*y);
2092 array = cpl_array_wrap_int (cpl_image_get_data_int(img), x*y);
2095 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
2096 "invalid type of image");
2118 cpl_vector * vector2)
2120 cpl_ensure (vector1, CPL_ERROR_NULL_INPUT, NULL);
2122 cpl_matrix * matrix, * matrix_wrap;
2123 int size = cpl_vector_get_size(vector1);
2124 double * data1, * data2;
2126 if( vector2 != NULL ){
2127 int size2 = cpl_vector_get_size(vector2);
2128 cpl_ensure (size == size2, CPL_ERROR_ILLEGAL_INPUT, NULL);
2130 data1 = cpl_malloc(2 * size *
sizeof(
double));
2131 memcpy(data1, cpl_vector_get_data(vector1), size *
sizeof(
double));
2133 data2 = cpl_vector_get_data(vector2);
2134 memcpy(data1 + size, data2, size *
sizeof(
double));
2136 matrix_wrap = cpl_matrix_wrap(2, size, data1);
2137 matrix = cpl_matrix_transpose_create(matrix_wrap);
2139 cpl_matrix_unwrap(matrix_wrap);
2142 data1 = cpl_malloc(size *
sizeof(
double));
2143 memcpy(data1, cpl_vector_get_data(vector1), size *
sizeof(
double));
2145 matrix = cpl_matrix_wrap(size, 1, data1);
2169 const char * regname)
2172 cpl_ensure (spectrum_data, CPL_ERROR_NULL_INPUT, NULL);
2173 cpl_ensure (regname, CPL_ERROR_NULL_INPUT, NULL);
2174 cpl_ensure (index>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2177 cpl_size size = cpl_table_get_column_depth (spectrum_data, regname);
2178 cpl_ensure (index<size, CPL_ERROR_ILLEGAL_INPUT, NULL);
2181 cpl_size nrow = cpl_table_get_nrow (spectrum_data);
2182 cpl_vector * data_value = cpl_vector_new (nrow);
2187 cpl_array ** column_array = cpl_table_get_data_array (spectrum_data, regname);
2188 cpl_ensure (column_array, CPL_ERROR_ILLEGAL_INPUT, NULL);
2192 for (cpl_size row = 0; row < nrow; row ++){
2193 value = cpl_array_get (column_array[row], index, NULL);
2194 cpl_vector_set (data_value, row, value);
2196 }
else if (cpl_table_get_column_type (spectrum_data, regname)
2197 == CPL_TYPE_DOUBLE) {
2199 double * data = cpl_table_get_data_double (spectrum_data, regname);
2200 for (cpl_size row = 0; row < nrow; row++) {
2201 cpl_vector_set (data_value, row, data[row]);
2204 }
else if (cpl_table_get_column_type (spectrum_data, regname)
2207 int * data = cpl_table_get_data_int (spectrum_data, regname);
2208 for (cpl_size row = 0; row < nrow; row++) {
2209 cpl_vector_set (data_value, row, data[row]);
2213 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
2214 "This type is not supported"
2215 "(report to DRS team).");
2216 FREE (cpl_vector_delete, data_value);
2220 return (data_value);
2229 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
2230 cpl_ensure (name, CPL_ERROR_NULL_INPUT, NULL);
2231 cpl_ensure (base>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2232 cpl_ensure (nbase>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2235 cpl_size size = cpl_table_get_column_depth (table, name);
2236 cpl_ensure (size==0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2239 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
2240 cpl_vector * vector = cpl_vector_new (nrow);
2243 cpl_type type = cpl_table_get_column_type (table, name);
2245 if (type == CPL_TYPE_DOUBLE) {
2246 double * data = cpl_table_get_data_double (table, name);
2247 for (cpl_size row = 0; row < nrow; row++)
2248 cpl_vector_set (vector, row, data[row*nbase+base]);
2250 else if (type == CPL_TYPE_FLOAT) {
2251 float * data = cpl_table_get_data_float (table, name);
2252 for (cpl_size row = 0; row < nrow; row++)
2253 cpl_vector_set (vector, row, data[row*nbase+base]);
2255 else if (type == CPL_TYPE_INT) {
2256 int * data = cpl_table_get_data_int (table, name);
2257 for (cpl_size row = 0; row < nrow; row++)
2258 cpl_vector_set (vector, row, data[row*nbase+base]);
2261 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
2262 "This type is not supported"
2263 "(report to DRS team).");
2264 FREE (cpl_vector_delete, vector);
2289 const char * regname1,
2290 const char * regname2)
2293 cpl_ensure (spectrum_data, CPL_ERROR_NULL_INPUT, NULL);
2294 cpl_ensure (regname1, CPL_ERROR_NULL_INPUT, NULL);
2295 cpl_ensure (regname2, CPL_ERROR_NULL_INPUT, NULL);
2296 cpl_ensure (index>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2299 cpl_size size1 = cpl_table_get_column_depth (spectrum_data, regname1);
2300 cpl_size size2 = cpl_table_get_column_depth (spectrum_data, regname2);
2301 cpl_ensure (index<size1, CPL_ERROR_ILLEGAL_INPUT, NULL);
2302 cpl_ensure (index<size2, CPL_ERROR_ILLEGAL_INPUT, NULL);
2305 cpl_array ** column_array1 = cpl_table_get_data_array (spectrum_data, regname1);
2306 cpl_array ** column_array2 = cpl_table_get_data_array (spectrum_data, regname2);
2307 cpl_ensure (column_array1, CPL_ERROR_ILLEGAL_INPUT, NULL);
2308 cpl_ensure (column_array2, CPL_ERROR_ILLEGAL_INPUT, NULL);
2311 cpl_size nrow = cpl_table_get_nrow (spectrum_data);
2312 cpl_vector * data_value = cpl_vector_new (nrow);
2316 for (cpl_size row = 0; row < nrow; row++){
2317 value = cpl_array_get (column_array1[row], index, NULL) - cpl_array_get (column_array2[row], index, NULL);
2318 cpl_vector_set (data_value, row, value);
2321 return (data_value);
2332 cpl_ensure_code (img, CPL_ERROR_NULL_INPUT);
2334 cpl_size nx = cpl_image_get_size_x (img);
2335 cpl_size ny = cpl_image_get_size_y (img);
2336 cpl_image_fill_window (img, 1,1,nx,ny, value);
2338 return CPL_ERROR_NONE;
2349 cpl_ensure (matrix, CPL_ERROR_NULL_INPUT, NULL);
2350 cpl_size nx = cpl_matrix_get_ncol (matrix);
2351 cpl_size ny = cpl_matrix_get_nrow (matrix);
2352 return cpl_image_wrap_double (nx, ny, cpl_matrix_get_data (matrix));
2357 cpl_ensure (matrix, CPL_ERROR_NULL_INPUT, NULL);
2358 cpl_size nx = cpl_matrix_get_ncol (matrix);
2359 cpl_size ny = cpl_matrix_get_nrow (matrix);
2361 cpl_image * image = cpl_image_new (nx,ny,CPL_TYPE_DOUBLE);
2362 for (cpl_size i = 0; i < nx; i++)
2363 for (cpl_size j = 0; j < ny; j++)
2364 cpl_image_set (image, i+1, j+1, cpl_matrix_get (matrix,j,i));
2377 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, NULL);
2378 cpl_size nx = cpl_vector_get_size (vector);
2380 return cpl_image_wrap_double (nx, ny, cpl_vector_get_data (vector));
2385 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, NULL);
2386 cpl_size nx = cpl_vector_get_size (vector);
2389 cpl_image * image = cpl_image_new (nx,ny,CPL_TYPE_DOUBLE);
2390 for (cpl_size i = 0; i < nx; i++)
2391 cpl_image_set (image, i+1, 1, cpl_vector_get (vector,i));
2411 cpl_ensure (img, CPL_ERROR_NULL_INPUT, -1);
2412 cpl_ensure (thr>0 && thr<1, CPL_ERROR_ILLEGAL_INPUT, -1);
2414 cpl_size nx = cpl_image_get_size_x (img);
2415 cpl_size ny = cpl_image_get_size_y (img);
2416 cpl_size nq = (cpl_size)(thr * nx * ny);
2418 cpl_ensure (nq>=0 && nq<=nx*ny, CPL_ERROR_ILLEGAL_INPUT, -1);
2422 cpl_vector * vect = cpl_vector_new (nx*ny);
2423 for (cpl_size ix = 0; ix < nx ; ix++)
2424 for (cpl_size iy = 0; iy < ny ; iy++)
2425 cpl_vector_set (vect, ix * ny + iy, cpl_image_get (img, ix+1, iy+1, &nv));
2428 cpl_vector_sort (vect, CPL_SORT_ASCENDING);
2429 double value = cpl_vector_get (vect, nq);
2430 cpl_vector_delete (vect);
2445 cpl_ensure (arr, CPL_ERROR_NULL_INPUT, -1);
2446 cpl_ensure (thr>0 && thr<1, CPL_ERROR_ILLEGAL_INPUT, -1);
2448 cpl_size nx = cpl_array_get_size (arr);
2449 cpl_size nq = (cpl_size)(thr * nx);
2451 cpl_ensure (nq>=0 && nq<=nx, CPL_ERROR_ILLEGAL_INPUT, -1);
2455 cpl_vector * vect = cpl_vector_new (nx);
2456 for (cpl_size ix = 0; ix < nx ; ix++)
2457 cpl_vector_set (vect, ix, cpl_array_get (arr, ix, &nv));
2460 cpl_vector_sort (vect, CPL_SORT_ASCENDING);
2461 double value = cpl_vector_get (vect, nq);
2462 cpl_vector_delete (vect);
2481 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, NULL);
2482 cpl_ensure (hw>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2484 cpl_size size = cpl_vector_get_size (vector);
2485 cpl_vector * median = NULL;
2490 median = cpl_vector_new (size);
2491 cpl_vector_fill (median, cpl_vector_get_median_const (vector));
2496 median = cpl_vector_filter_median_create (vector, hw);
2497 cpl_ensure (median, CPL_ERROR_DATA_NOT_FOUND, NULL);
2499 double * data = cpl_vector_get_data (median);
2500 cpl_ensure (data, CPL_ERROR_DATA_NOT_FOUND, NULL);
2502 for (
int i = 0; i < hw; i++) data[i] = data[hw];
2503 for (
int i = size-hw; i < size; i++) data[i] = data[size-hw-1];
2522 cpl_ensure_code (vector, CPL_ERROR_NULL_INPUT);
2525 cpl_size size = cpl_vector_get_size (vector);
2526 cpl_ensure_code (size > 0, CPL_ERROR_ILLEGAL_INPUT);
2528 double * data = cpl_vector_get_data (vector);
2529 cpl_ensure_code (data, CPL_ERROR_ILLEGAL_INPUT);
2532 for (
int i = 0; i < size; i++) data[i] = fabs (data[i]);
2534 return CPL_ERROR_NONE;
2548 cpl_ensure (vector, CPL_ERROR_NULL_INPUT, -1);
2549 cpl_size size = cpl_vector_get_size (vector);
2552 double value = cpl_vector_get (vector, 0);
2553 for (
int s = 1; s < size; s++) {
2554 if (cpl_vector_get (vector, s) > value) {
2556 value = cpl_vector_get (vector, s);
2578 cpl_ensure (vector_in, CPL_ERROR_NULL_INPUT, 0.0);
2579 cpl_ensure (percent > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0);
2580 cpl_ensure (percent < 0.5, CPL_ERROR_ILLEGAL_INPUT, 0.0);
2581 cpl_ensure (nsigma > 0, CPL_ERROR_ILLEGAL_INPUT, 0.0);
2584 cpl_vector * sort_vector = cpl_vector_duplicate (vector_in);
2585 cpl_vector_sort (sort_vector, CPL_SORT_ASCENDING);
2588 cpl_size size = cpl_vector_get_size (vector_in);
2589 cpl_size sizeout = size*(1-percent*2);
2590 cpl_size start = (size-sizeout)/2;
2592 cpl_vector * vector = cpl_vector_new (sizeout);
2593 for (cpl_size i = 0 ; i < sizeout ; i++)
2594 cpl_vector_set (vector, i, cpl_vector_get (sort_vector, i+start));
2597 cpl_vector * vector_med = cpl_vector_new (sizeout);
2598 double med = cpl_vector_get_median (vector);
2599 double rms = nsigma * cpl_vector_get_stdev (vector);
2601 cpl_size size_med = 0;
2602 for (cpl_size i = 0 ; i < cpl_vector_get_size (vector) ; i++)
2603 if ( (cpl_vector_get (vector, i) > med-rms) &&
2604 (cpl_vector_get (vector, i) < med+rms) ) {
2605 cpl_vector_set (vector_med, size_med, cpl_vector_get (vector, i));
2608 cpl_vector_set_size (vector_med, size_med);
2611 double output = cpl_vector_get_mean (vector_med);
2613 FREE (cpl_vector_delete, vector_med);
2614 FREE (cpl_vector_delete, sort_vector);
2630 cpl_size size = cpl_vector_get_size (vector);
2631 cpl_size newsize = size / step;
2632 cpl_vector * out = cpl_vector_new (newsize);
2634 for (
int s = 0; s < newsize; s++)
2635 cpl_vector_set (out, s, cpl_vector_get (vector, s*step+start));
2653 cpl_ensure_code (vector, CPL_ERROR_NULL_INPUT);
2654 cpl_ensure_code (ref, CPL_ERROR_NULL_INPUT);
2656 cpl_size nrow = cpl_vector_get_size (vector);
2658 double referenced, referenced_prev = 0.0;
2661 for (cpl_size row = 0 ; row < nrow; row ++) {
2662 double phase_ref = ref_to_phase * cpl_vector_get (ref, row);
2665 referenced = (cpl_vector_get (vector, row) - phase_ref);
2666 referenced = fmod (referenced, CPL_MATH_2PI);
2667 if (referenced < 0) referenced += CPL_MATH_2PI;
2670 if ( referenced - referenced_prev > CPL_MATH_PI ) wrap --;
2671 if ( referenced - referenced_prev < -CPL_MATH_PI ) wrap ++;
2672 referenced_prev = referenced;
2675 cpl_vector_set (vector, row, phase_ref + referenced + wrap * CPL_MATH_2PI);
2680 return CPL_ERROR_NONE;
2699 int base,
int nbase,
double value)
2701 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
2702 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
2703 cpl_ensure_code (nbase==1 || nbase==4 || nbase==6, CPL_ERROR_ILLEGAL_INPUT);
2704 cpl_ensure_code (base>=0 && base <nbase, CPL_ERROR_ILLEGAL_INPUT);
2706 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
2708 if (cpl_table_get_column_depth (table, name) > 0) {
2709 cpl_array ** array = cpl_table_get_data_array (table, name);
2710 for (cpl_size row = 0 ; row < nrow ; row ++) {
2711 cpl_array_multiply_scalar (array[row*nbase+base], value);
2712 CPLCHECK_MSG (
"Cannot multiply (array may not be numerical)");
2714 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_DOUBLE) {
2715 double * array = cpl_table_get_data_double (table, name);
2716 for (cpl_size row = 0 ; row < nrow ; row ++) {
2717 array[row*nbase+base] *= value;
2719 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_INT) {
2720 int * array = cpl_table_get_data_int (table, name);
2721 for (cpl_size row = 0 ; row < nrow ; row ++) {
2722 array[row*nbase+base] *= value;
2725 return cpl_error_set_message (cpl_func, CPL_ERROR_INVALID_TYPE,
2726 "Column type is not supported");
2730 return CPL_ERROR_NONE;
2749 int base,
int nbase,
double value)
2751 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
2752 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
2753 cpl_ensure_code (nbase==1 || nbase==4 || nbase==6, CPL_ERROR_ILLEGAL_INPUT);
2754 cpl_ensure_code (base>=0 && base <nbase, CPL_ERROR_ILLEGAL_INPUT);
2756 cpl_size nrow = cpl_table_get_nrow (table) / nbase;
2758 if (cpl_table_get_column_depth (table, name) > 0) {
2759 cpl_array ** array = cpl_table_get_data_array (table, name);
2760 for (cpl_size row = 0 ; row < nrow ; row ++) {
2761 cpl_array_add_scalar (array[row*nbase+base], value);
2762 CPLCHECK_MSG (
"Cannot multiply (array may not be numerical)");
2764 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_DOUBLE) {
2765 double * array = cpl_table_get_data_double (table, name);
2766 for (cpl_size row = 0 ; row < nrow ; row ++) {
2767 array[row*nbase+base] += value;
2769 }
else if(cpl_table_get_column_type (table, name) == CPL_TYPE_INT) {
2770 int * array = cpl_table_get_data_int (table, name);
2771 for (cpl_size row = 0 ; row < nrow ; row ++) {
2772 array[row*nbase+base] += value;
2775 return cpl_error_set_message (cpl_func, CPL_ERROR_INVALID_TYPE,
2776 "Column type is not supported");
2780 return CPL_ERROR_NONE;
2805 cpl_ensure (matrix, CPL_ERROR_NULL_INPUT, NULL);
2806 cpl_ensure (xref, CPL_ERROR_NULL_INPUT, NULL);
2807 cpl_ensure (xout, CPL_ERROR_NULL_INPUT, NULL);
2809 cpl_size nrow = cpl_matrix_get_nrow (matrix);
2810 cpl_size ncol = cpl_matrix_get_ncol (matrix);
2811 cpl_size nxref = cpl_vector_get_size (xref);
2812 cpl_size nxout = cpl_vector_get_size (xout);
2814 cpl_ensure (ncol == nxref, CPL_ERROR_ILLEGAL_INPUT, NULL);
2815 cpl_ensure (nxout > 0, CPL_ERROR_ILLEGAL_INPUT, NULL);
2818 cpl_matrix * outmatrix = cpl_matrix_new (nrow, nxout);
2819 cpl_vector * yref = cpl_vector_new (nxref);
2820 cpl_vector * yout = cpl_vector_new (nxout);
2821 cpl_bivector * fref = cpl_bivector_wrap_vectors (xref, yref);
2822 cpl_bivector * fout = cpl_bivector_wrap_vectors (xout, yout);
2825 for (cpl_size row = 0; row < nrow; row++) {
2826 for (cpl_size x = 0; x < nxref; x++)
2827 cpl_vector_set (yref, x, cpl_matrix_get (matrix, row, x));
2828 cpl_bivector_interpolate_linear (fout, fref);
2829 for (cpl_size x = 0; x < nxout; x++)
2830 cpl_matrix_set (outmatrix, row, x, cpl_vector_get (yout, x));
2834 FREE (cpl_bivector_unwrap_vectors, fref);
2835 FREE (cpl_bivector_unwrap_vectors, fout);
2836 FREE (cpl_vector_delete, yref);
2837 FREE (cpl_vector_delete, yout);
2857 cpl_ensure (a_in, CPL_ERROR_NULL_INPUT, NULL);
2859 cpl_size m = cpl_matrix_get_nrow (a_in);
2860 cpl_size n = cpl_matrix_get_ncol (a_in);
2862 cpl_vector * w = cpl_vector_new (n);
2863 cpl_matrix * v = cpl_matrix_new (n, n);
2869 cpl_matrix * a_out =
svdcmp (a_in, w, v);
2873 for (cpl_size ii = 0; ii < n; ii++) {
2874 if (cpl_vector_get (w, ii) < 0.1)
2875 cpl_msg_warning (cpl_func,
"Singular Value %lld = %e",
2876 ii, cpl_vector_get (w, ii));
2882 cpl_matrix * a_inv = cpl_matrix_new (n,m);
2883 double * a_inv_data = cpl_matrix_get_data (a_inv);
2885 for (cpl_size j = 0; j < m; j++) {
2886 for (cpl_size i = 0; i < n; i++){
2889 for (cpl_size ii = 0; ii < n; ii++)
2890 if (cpl_vector_get (w, ii) > 1e-15)
2891 wv_at += cpl_matrix_get (v, i, ii) /
2892 cpl_vector_get (w, ii) *
2893 cpl_matrix_get (a_out, j, ii);
2895 a_inv_data[j + i * m] = wv_at;
2900 cpl_vector_delete (w);
2901 cpl_matrix_delete (v);
2902 cpl_matrix_delete (a_out);
2914 double absa=fabs(a);
2915 double absb=fabs(b);
2917 return absa*sqrt(1.0+pow(absb/absa, 2));
2919 return (absb == 0.0 ? 0.0 : absb*sqrt(1.0+pow(absa/absb, 2)));
2927cpl_matrix *
svdcmp (cpl_matrix * a_in, cpl_vector * w, cpl_matrix * v)
2930 cpl_ensure (a_in, CPL_ERROR_NULL_INPUT, NULL);
2932 int flag, i, its, j, jj, k, l, nm, n, m;
2933 double anorm, c, f, g, h, s, scale, x, y, z;
2937 a = cpl_matrix_duplicate(a_in);
2938 m = cpl_matrix_get_nrow (a_in);
2939 n = cpl_matrix_get_ncol (a_in);
2940 rv1 = cpl_vector_new(n);
2942 g = scale = anorm = 0.0;
2943 for (i = 0; i < n; i++) {
2945 cpl_vector_set(rv1, i, scale*g);
2946 g = s = scale = 0.0;
2948 for (k = i; k < m; k++)
2949 scale += fabs(cpl_matrix_get(a, k, i));
2952 for (k = i; k < m; k++) {
2954 cpl_matrix_set (a, k, i, cpl_matrix_get(a, k, i)/scale);
2955 s += cpl_matrix_get(a, k, i) * cpl_matrix_get(a, k, i);
2957 f = cpl_matrix_get(a, i, i);
2958 g = -
SIGN(sqrt(s),f);
2960 cpl_matrix_set (a, i, i, f - g);
2961 for (j = l; j < n; j++) {
2962 for (s = 0.0, k = i; k < m; k++)
2963 s += cpl_matrix_get(a, k, i) * cpl_matrix_get(a, k, j);
2966 for (k = i; k < m; k++)
2967 cpl_matrix_set (a, k, j, cpl_matrix_get(a, k, j) +
2968 f * cpl_matrix_get(a, k, i));
2971 for (k = i; k < m; k++)
2972 cpl_matrix_set (a, k, i, cpl_matrix_get(a, k, i) * scale);
2977 cpl_vector_set(w, i, scale *g);
2979 g = s = scale = 0.0;
2980 if (i < m && i != (n - 1)) {
2981 for (k = l; k < n; k++)
2982 scale += fabs(cpl_matrix_get(a, i, k));;
2984 for (k = l; k < n; k++) {
2985 cpl_matrix_set (a, i, k, cpl_matrix_get(a, i, k) / scale);
2986 s += cpl_matrix_get(a, i, k) * cpl_matrix_get(a, i, k);
2988 f = cpl_matrix_get(a, i, l);
2989 g = -
SIGN(sqrt(s),f);
2991 cpl_matrix_set (a, i, l, f - g);
2992 for (k = l; k < n; k++)
2993 cpl_vector_set(rv1, k, cpl_matrix_get(a, i, k)/h);
2994 for (j = l; j < m; j++) {
2995 for (s = 0.0, k = l; k < n; k++)
2996 s += cpl_matrix_get(a, j, k) * cpl_matrix_get(a, i, k);
2997 for (k = l; k < n; k++)
2998 cpl_matrix_set (a, j, k, cpl_matrix_get(a, j, k) + s * cpl_vector_get(rv1, k));
3000 for (k = l; k < n; k++)
3001 cpl_matrix_set (a, i, k, cpl_matrix_get(a, i, k) * scale);
3005 anorm = fmax(anorm,(fabs(cpl_vector_get(w, i)) +
3006 fabs(cpl_vector_get(rv1, i))));
3010 for (i = (n - 1); i >= 0; i--) {
3013 for (j = l; j < n; j++)
3014 cpl_matrix_set(v, j, i, (cpl_matrix_get(a, i, j) /
3015 cpl_matrix_get(a, i, l)) / g);
3017 for (j = l;j < n; j++) {
3018 for (s = 0.0, k = l; k < n; k++)
3019 s += cpl_matrix_get(a, i, k) * cpl_matrix_get(v, k, j);
3021 for (k = l; k < n; k++)
3022 cpl_matrix_set(v, k, j, cpl_matrix_get(v, k, j) + s *
3023 cpl_matrix_get(v, k, i));
3027 for (j = l; j < n; j++) {
3028 cpl_matrix_set(v, i, j, 0.0);
3029 cpl_matrix_set(v, j, i, 0.0);
3032 cpl_matrix_set(v, i, i, 1.0);
3034 g = cpl_vector_get(rv1, i);
3038 for (i = (
IMIN(m,n) - 1); i >= 0; i--) {
3040 g = cpl_vector_get(w, i);
3041 for (j = l; j < n; j++)
3042 cpl_matrix_set(a, i, j, 0.0);
3046 for (j = l; j < n; j++) {
3047 for (s = 0.0, k = l; k < m; k++)
3048 s += cpl_matrix_get(a, k, i) * cpl_matrix_get(a, k, j);
3050 f = (s / cpl_matrix_get(a, i, i)) * g;
3052 for (k = i; k < m; k++)
3053 cpl_matrix_set(a, k, j, cpl_matrix_get(a, k, j) + f *
3054 cpl_matrix_get(a, k, i));
3057 for (j = i; j < m; j++)
3058 cpl_matrix_set(a, j, i, cpl_matrix_get(a, j, i) * g);
3062 for (j = i; j < m; j++)
3063 cpl_matrix_set(a, j, i, 0.0);
3065 cpl_matrix_set(a, i, i, cpl_matrix_get(a, i, i) + 1);
3069 for (k = (n - 1); k >= 0; k--) {
3070 for (its = 1; its <= 60; its ++) {
3073 for (l = k; l >= 0; l--) {
3075 if ((fabs(cpl_vector_get(rv1, l)) + anorm) == anorm) {
3079 if ((fabs(cpl_vector_get(w, nm)) + anorm) == anorm)
3086 for (i = l; i <= k; i++) {
3087 f = s * cpl_vector_get(rv1, i);
3088 cpl_vector_set(rv1, i, c * cpl_vector_get(rv1, i));
3089 if ((fabs(f) + anorm) == anorm)
3091 g = cpl_vector_get(w, i);
3093 cpl_vector_set(w, i, h);
3097 for (j = 0; j < m; j++) {
3098 y = cpl_matrix_get(a, j, nm);
3099 z = cpl_matrix_get(a, j, i);
3100 cpl_matrix_set(a, j, nm, y*c+z*s);
3101 cpl_matrix_set(a, j, i, z*c-y*s);
3105 z = cpl_vector_get(w, k);
3108 cpl_vector_set(w, k, -z);
3109 for (j = 0; j < n; j++)
3110 cpl_matrix_set(v, j, k, -cpl_matrix_get(v, j, k));
3117 cpl_error_set_message(cpl_func,
3118 CPL_ERROR_ILLEGAL_INPUT,
3119 "no convergence in 120 svdcmp iterations");
3120 cpl_vector_delete(rv1);
3121 cpl_matrix_delete(a);
3124 x = cpl_vector_get(w, l);
3126 y = cpl_vector_get(w, nm); ;
3127 g = cpl_vector_get(rv1, nm);
3128 h = cpl_vector_get(rv1, k);
3129 f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y);
3131 f = ((x - z) * (x + z) + h * ((y / (f +
SIGN(g, f))) - h)) / x;
3133 for (j = l; j < nm; j++) {
3135 g = cpl_vector_get(rv1, i);
3136 y = cpl_vector_get(w, i);
3140 cpl_vector_set(rv1, j, z);
3147 for (jj = 0; jj < n; jj++) {
3148 x = cpl_matrix_get(v, jj, j);
3149 z=cpl_matrix_get(v, jj, i);
3150 cpl_matrix_set(v, jj, j, x*c+z*s);
3151 cpl_matrix_set(v, jj, i, z*c-x*s);
3154 cpl_vector_set(w, j, z);
3163 for (jj = 0; jj < m; jj++) {
3164 y = cpl_matrix_get(a, jj, j);
3165 z = cpl_matrix_get(a, jj, i);
3166 cpl_matrix_set(a, jj, j, y*c+z*s);
3167 cpl_matrix_set(a, jj, i, z*c-y*s);
3170 cpl_vector_set(rv1, l, 0.0);
3171 cpl_vector_set(rv1, k, f);
3172 cpl_vector_set(w, k, x);
3176 cpl_vector_delete(rv1);
3196 cpl_ensure (table, CPL_ERROR_NULL_INPUT, NULL);
3199 cpl_table_select_all (table);
3200 cpl_table_and_selected_double (table,
"TIME", CPL_NOT_LESS_THAN, start);
3201 cpl_table_and_selected_double (table,
"TIME", CPL_LESS_THAN, end);
3202 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.
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