52 #include "gravi_dfs.h" 53 #include "gravi_data.h" 54 #include "gravi_pfits.h" 55 #include "gravi_utils.h" 56 #include "gravi_cpl.h" 62 #define GRAVI_DATA_SIZE 30 65 cpl_propertylist * primary_hdr;
67 cpl_propertylist ** exts_hdrs;
68 cpl_imagelist ** exts_imgl;
69 cpl_table ** exts_tbs;
104 gravi_msg_function_start(0);
105 cpl_ensure (nb_ext==0, CPL_ERROR_ILLEGAL_INPUT, NULL);
107 gravi_data *
self = cpl_malloc (
sizeof (gravi_data));
108 self->primary_hdr = cpl_propertylist_new ();
111 self->exts_hdrs = cpl_malloc (GRAVI_DATA_SIZE *
sizeof(cpl_propertylist*));
112 self->exts_tbs = cpl_malloc (GRAVI_DATA_SIZE *
sizeof(cpl_table*));
113 self->exts_imgl = cpl_malloc (GRAVI_DATA_SIZE *
sizeof(cpl_imagelist*));
115 for(
int i = 0; i < GRAVI_DATA_SIZE; i++){
116 self->exts_tbs[i] = NULL;
117 self->exts_hdrs[i] = NULL;
118 self->exts_imgl[i] = NULL;
121 gravi_msg_function_exit(0);
139 gravi_msg_function_start(0);
143 FREE (cpl_propertylist_delete, self->primary_hdr);
145 FREELOOP (cpl_propertylist_delete, self->exts_hdrs, GRAVI_DATA_SIZE);
146 FREELOOP (cpl_table_delete, self->exts_tbs, GRAVI_DATA_SIZE);
147 FREELOOP (cpl_imagelist_delete, self->exts_imgl, GRAVI_DATA_SIZE);
149 FREE (cpl_free,
self);
152 gravi_msg_function_exit(0);
164 if (hdr==NULL) {
return 0; }
165 if (!cpl_propertylist_has (hdr,
"EXTNAME")) {
return 0; }
166 if (strncmp (gravi_pfits_get_extname (hdr),
"OI_", 3)) {
return 0; }
188 cpl_ensure_code (hdr, CPL_ERROR_NULL_INPUT);
189 cpl_ensure_code (oi_table, CPL_ERROR_NULL_INPUT);
194 if ( cpl_table_has_column (oi_table,
"FLAG") ) {
195 cpl_table_set_column_savetype(oi_table,
"FLAG", CPL_TYPE_BOOL);
198 if ( cpl_table_has_column (oi_table,
"STA_INDEX") ) {
199 cpl_table_set_column_savetype(oi_table,
"STA_INDEX", CPL_TYPE_SHORT);
202 if ( cpl_table_has_column (oi_table,
"TARGET_ID") ) {
203 cpl_table_set_column_savetype(oi_table,
"TARGET_ID", CPL_TYPE_SHORT);
206 if ( cpl_table_has_column (oi_table,
"MNT_STA") ) {
207 cpl_table_set_column_savetype(oi_table,
"MNT_STA", CPL_TYPE_SHORT);
211 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
212 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
213 "Cannot reinstall the savetypes");
214 return cpl_error_get_code();
217 return CPL_ERROR_NONE;
238 gravi_msg_function_start(1);
239 cpl_ensure (
self, CPL_ERROR_NULL_INPUT, NULL);
242 copy->nb_ext =
self->nb_ext;
244 if (self->primary_hdr) {
245 cpl_propertylist_delete (copy->primary_hdr);
246 copy->primary_hdr = cpl_propertylist_duplicate(self->primary_hdr);
248 cpl_msg_warning (cpl_func,
"a data without header shall not exist");
251 CPLCHECK_NUL (
"Cannot duplicate header");
253 for (
int i = 0; i < copy->nb_ext ; i++){
254 if (self->exts_hdrs[i])
255 copy->exts_hdrs[i] = cpl_propertylist_duplicate(self->exts_hdrs[i]);
256 if (self->exts_tbs[i]) {
257 copy->exts_tbs[i] = cpl_table_duplicate(self->exts_tbs[i]);
260 if (self->exts_imgl[i])
261 copy->exts_imgl[i] = cpl_imagelist_duplicate(self->exts_imgl[i]);
263 CPLCHECK_NUL (
"Cannot duplicate extension");
266 gravi_msg_function_exit(1);
292 gravi_msg_function_start(1);
293 cpl_ensure_code (first, CPL_ERROR_NULL_INPUT);
294 cpl_ensure_code (second, CPL_ERROR_NULL_INPUT);
295 cpl_ensure_code (first->nb_ext == second->nb_ext, CPL_ERROR_INCOMPATIBLE_INPUT);
297 cpl_msg_warning (cpl_func,
"Append data: keep only the HEADER of the first data");
298 cpl_msg_warning (cpl_func,
"Append data: FIXME: only works for OIFITS data");
300 for (
int i = 0; i < first->nb_ext ; i++) {
303 const char * name1 = gravi_pfits_get_extname (first->exts_hdrs[i]);
304 const char * name2 = gravi_pfits_get_extname (second->exts_hdrs[i]);
305 cpl_ensure_code (!strcmp (name1, name2), CPL_ERROR_INCOMPATIBLE_INPUT);
308 if ( !strcmp (name1,
"OI_WAVELENGTH") ||
309 !strcmp (name1,
"OI_TARGET") ||
310 !strcmp (name1,
"OI_ARRAY") ||
311 !strcmp (name1,
"IMAGING_DETECTOR_SC") ||
312 !strcmp (name1,
"IMAGING_DETECTOR_FT") ||
313 !strcmp (name1,
"ARRAY_DESCRIPTION") ||
314 !strcmp (name1,
"ARRAY_GEOMETRY") ||
315 !strcmp (name1,
"OPTICAL_TRAIN") ) {
317 cpl_msg_info (cpl_func,
"Don't check table %s", name1);
321 cpl_msg_info (cpl_func,
"Check table %s", name1);
323 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"Tables %s are different", name1);
330 if ( first->exts_tbs[i] != NULL ) {
331 cpl_msg_info (cpl_func,
"Merge table %s", name1);
332 cpl_table_insert (first->exts_tbs[i], second->exts_tbs[i], CPL_SIZE_MAX);
334 CPLCHECK_MSG (
"Cannot append table");
339 if ( first->exts_imgl[i] != NULL ) {
340 cpl_msg_info (cpl_func,
"Merge imglist %s", name1);
341 cpl_size n_first = cpl_imagelist_get_size (first->exts_imgl[i]);
342 cpl_size n_second = cpl_imagelist_get_size (second->exts_imgl[i]);
343 CPLCHECK_MSG (
"Cannot get the size of imglist");
345 for (cpl_size iimg = 0; iimg < n_second; iimg++) {
346 cpl_image * img = cpl_image_duplicate (cpl_imagelist_get (second->exts_imgl[i], iimg));
347 cpl_imagelist_set (first->exts_imgl[i], img, n_first + iimg);
350 CPLCHECK_MSG (
"Cannot append imglist");
354 CPLCHECK_MSG (
"Cannot append data");
357 gravi_msg_function_exit(1);
358 return CPL_ERROR_NONE;
378 gravi_msg_function_start(0);
379 cpl_ensure (filename, CPL_ERROR_NULL_INPUT, NULL);
381 cpl_msg_debug (cpl_func,
"Load file : %s", filename);
384 int nb_ext = cpl_fits_count_extensions (filename);
386 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"no extension in this file");
394 cpl_propertylist * header = cpl_propertylist_load (filename, 0);
395 cpl_propertylist_append (self->primary_hdr, header);
396 FREE (cpl_propertylist_delete, header);
399 for (
int i = 0; i < nb_ext ; i++ ){
402 self->exts_hdrs[i] = cpl_propertylist_load (filename, i+1);
403 CPLCHECK_NUL (
"Cannot load header");
406 if (gravi_pfits_get_extension_type (self->exts_hdrs[i]) == 2) {
407 self->exts_tbs[i] = cpl_table_load (filename, i+1, 0);
409 CPLCHECK_NUL (
"Cannot load bintable");
412 else if (gravi_pfits_get_extension_type (self->exts_hdrs[i]) == 3) {
413 self->exts_imgl[i] = cpl_imagelist_load (filename,CPL_TYPE_DOUBLE,i+1);
414 CPLCHECK_NUL (
"Cannot load imagelist");
418 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"The dimension of the extension is wrong");
426 gravi_msg_function_exit(0);
449 const char * extensions_regexp)
451 gravi_msg_function_start(0);
452 cpl_ensure (filename, CPL_ERROR_NULL_INPUT, NULL);
454 cpl_msg_debug (cpl_func,
"Load file : %s", filename);
457 int nb_ext = cpl_fits_count_extensions (filename);
459 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"no extension in this file");
467 cpl_propertylist * header = cpl_propertylist_load (filename, 0);
468 cpl_propertylist_append (self->primary_hdr, header);
469 FREE (cpl_propertylist_delete, header);
473 int status = regcomp(&filter, extensions_regexp, REG_EXTENDED | REG_NOSUB);
475 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
476 "Cannot interpret extension regular expression");
482 for (
int i = 0; i < nb_ext ; i++ ){
485 cpl_propertylist *proplist = cpl_propertylist_load (filename, i+1);
486 const char *extname = cpl_propertylist_get_string (proplist,
"EXTNAME");
487 CPLCHECK_NUL (
"Cannot load header");
490 if (regexec(&filter, extname, 0, NULL, 0) == REG_NOMATCH)
492 cpl_propertylist_delete(proplist);
496 self->exts_hdrs[iext] = proplist;
499 if (gravi_pfits_get_extension_type (self->exts_hdrs[iext]) == 2) {
500 self->exts_tbs[iext] = cpl_table_load (filename, i+1, 0);
502 CPLCHECK_NUL (
"Cannot load bintable");
505 else if (gravi_pfits_get_extension_type (self->exts_hdrs[iext]) == 3) {
506 self->exts_imgl[iext] = cpl_imagelist_load (filename,CPL_TYPE_DOUBLE,i+1);
507 CPLCHECK_NUL (
"Cannot load imagelist");
511 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"The dimension of the extension is wrong");
522 gravi_msg_function_exit(0);
541 cpl_ensure_code (data, CPL_ERROR_NULL_INPUT);
542 cpl_errorstate prestate = cpl_errorstate_get();
545 cpl_propertylist * header = gravi_data_get_header (data);
546 const char * res = gravi_pfits_get_spec_res (header);
547 const char * scpol = gravi_pfits_get_pola_mode (header, GRAVI_SC);
548 const char * ftpol = gravi_pfits_get_pola_mode (header, GRAVI_FT);
550 if (cpl_errorstate_is_equal(prestate)) {
551 cpl_msg_info (cpl_func,
"(insmode: %s %s %s)", res, scpol, ftpol);
553 cpl_errorstate_set (prestate);
556 return CPL_ERROR_NONE;
574 cpl_frameset * used_frameset)
576 cpl_ensure (frame, CPL_ERROR_NULL_INPUT, NULL);
578 const char * filename = cpl_frame_get_filename (frame);
580 cpl_msg_info (cpl_func,
"Load file %s (%s)", FILESHORT(filename), cpl_frame_get_tag (frame));
582 if (used_frameset) cpl_frameset_insert (used_frameset, cpl_frame_duplicate (frame));
586 CPLCHECK_NUL (
"Cannot load data");
610 cpl_frameset * patch_frameset)
612 cpl_ensure (file_to_patch, CPL_ERROR_NULL_INPUT, 0);
614 cpl_frame * patch_frame = NULL;
616 if ( !cpl_frameset_is_empty (patch_frameset) )
617 patch_frame = cpl_frameset_get_position(patch_frameset, 0);
620 const char * filename = cpl_frame_get_filename (patch_frame);
621 CPLCHECK_INT(
"Cannot get finelame");
622 cpl_msg_info (cpl_func,
"Patch the input file with %s", FILESHORT(filename));
623 cpl_propertylist * plist_patch = cpl_propertylist_load (filename, 0);
624 CPLCHECK_INT(
"Cannot load patch");
626 CPLCHECK_INT(
"Cannot load data");
628 for (
int i=0; i<cpl_propertylist_get_size(plist_patch); i++){
629 cpl_property * keyword = cpl_propertylist_get(plist_patch, i);
630 cpl_type type = cpl_property_get_type(keyword);
631 const char * p_name = cpl_property_get_name (keyword);
632 if ( (strstr(p_name,
" QC ") != NULL) ||
633 (strstr(p_name,
" TPL ") != NULL) ||
634 (strstr(p_name,
" OCS ") != NULL) ||
635 (strstr(p_name,
" OBS ") != NULL) ||
636 (strstr(p_name,
" MET ") != NULL) ||
637 (strstr(p_name,
" ISS ") != NULL) ||
638 (strstr(p_name,
" INS ") != NULL) ||
639 (strstr(p_name,
" FT ") != NULL) ||
640 (strstr(p_name,
" FDDL ") != NULL) ||
641 (strstr(p_name,
" ACQ ") != NULL) ) {
642 cpl_msg_info (cpl_func,
"Patch the keyword %s", p_name);
644 case CPL_TYPE_FLOAT :
645 cpl_propertylist_update_float(plist_file_to_patch, p_name, cpl_property_get_float(keyword));
647 case CPL_TYPE_DOUBLE :
648 cpl_propertylist_update_double(plist_file_to_patch, p_name, cpl_property_get_double(keyword));
651 cpl_propertylist_update_int(plist_file_to_patch, p_name, cpl_property_get_int(keyword));
653 case CPL_TYPE_STRING :
654 cpl_propertylist_update_string(plist_file_to_patch, p_name, cpl_property_get_string(keyword));
657 cpl_propertylist_update_char(plist_file_to_patch, p_name, cpl_property_get_char(keyword));
660 cpl_propertylist_update_bool(plist_file_to_patch, p_name, cpl_property_get_bool(keyword));
663 cpl_msg_error (cpl_func,
"'%s' is an invalid type of property",p_name);
664 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
665 "invalid type of property");
670 FREE (cpl_propertylist_delete, plist_patch);
691 cpl_frameset * used_frameset)
693 cpl_ensure (frame, CPL_ERROR_NULL_INPUT, NULL);
695 const char * filename = cpl_frame_get_filename (frame);
696 cpl_msg_info (cpl_func,
"Load RAW file %s (%s)", FILESHORT(filename), cpl_frame_get_tag (frame));
698 if (used_frameset) cpl_frameset_insert (used_frameset, cpl_frame_duplicate (frame));
702 CPLCHECK_NUL (
"Cannot load data");
709 CPLCHECK_NUL (
"Cannot check data consistency");
735 cpl_frameset * used_frameset,
736 char * extensions_regexp)
738 cpl_ensure (frame, CPL_ERROR_NULL_INPUT, NULL);
740 const char * filename = cpl_frame_get_filename (frame);
741 cpl_msg_info (cpl_func,
"Load RAW file %s (%s)", FILESHORT(filename), cpl_frame_get_tag (frame));
743 if (used_frameset) cpl_frameset_insert (used_frameset, cpl_frame_duplicate (frame));
747 CPLCHECK_NUL (
"Cannot load data");
755 CPLCHECK_NUL (
"Cannot check data consistency");
772 cpl_ensure_code (
self, CPL_ERROR_NULL_INPUT);
774 cpl_msg_info (cpl_func,
"-------------------------");
775 cpl_msg_info (cpl_func,
"POINTER: %p",
self);
776 cpl_msg_info (cpl_func,
"HEADER: %p", self->primary_hdr);
777 cpl_msg_info (cpl_func,
"nb_ext = %i",self->nb_ext);
779 for (
int i=0; i<
self->nb_ext; i++){
780 cpl_msg_info (cpl_func,
"%i: %s - %p %p %p", i,
781 gravi_pfits_get_extname (self->exts_hdrs[i]),
786 cpl_msg_info (cpl_func,
"-------------------------");
788 return CPL_ERROR_NONE;
804 cpl_ensure (
self, CPL_ERROR_ILLEGAL_INPUT, 0L);
805 return (
int)
self->nb_ext;
831 const char * filename,
834 cpl_ensure_code (
self, CPL_ERROR_NULL_INPUT);
835 cpl_ensure_code (filename, CPL_ERROR_NULL_INPUT);
839 if (self->exts_tbs[0] != NULL)
840 cpl_table_save(self->exts_tbs[0], self->primary_hdr,
841 self->exts_hdrs[0], filename, mode);
842 else if (self->exts_imgl[0] != NULL){
843 cpl_propertylist_save (self->primary_hdr, filename, mode);
844 cpl_imagelist_save (self->exts_imgl[0], filename,
845 CPL_TYPE_DOUBLE, self->exts_hdrs[0], CPL_IO_EXTEND);
848 cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT,
849 "one of the inputs at least is NULL");
850 return CPL_ERROR_NULL_INPUT;
855 for (
int i = 1; i <
self->nb_ext; i++){
857 if (gravi_pfits_get_extension_type (self->exts_hdrs[i]) == 2)
858 cpl_table_save(self->exts_tbs[i], NULL,
859 self->exts_hdrs[i], filename, CPL_IO_EXTEND);
860 else if (gravi_pfits_get_extension_type (self->exts_hdrs[i]) == 3)
861 cpl_imagelist_save (self->exts_imgl[i], filename,
862 CPL_TYPE_DOUBLE, self->exts_hdrs[i], CPL_IO_EXTEND);
864 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
865 "The dimension of the extension is wrong");
867 return CPL_ERROR_ILLEGAL_INPUT;
871 return CPL_ERROR_NONE;
897 cpl_frameset * allframes,
898 const char * filename,
900 const cpl_parameterlist * parlist,
901 cpl_frameset * usedframes,
904 cpl_propertylist * applist,
905 const char * proCatg)
907 gravi_msg_function_start(0);
908 cpl_ensure_code (filename || frame, CPL_ERROR_NULL_INPUT);
909 cpl_ensure_code (
self, CPL_ERROR_NULL_INPUT);
910 cpl_ensure_code (proCatg, CPL_ERROR_NULL_INPUT);
912 cpl_frameset * frameset;
913 int ext, i = 0, j = 0;
917 if (applist == NULL) {
918 applist = gravi_data_get_qc (
self);
919 CPLCHECK_MSG (
"Cannot get QC parameters");
921 applist = cpl_propertylist_duplicate (applist);
925 cpl_propertylist_append_string (applist, CPL_DFS_PRO_CATG, proCatg);
926 CPLCHECK_MSG (
"Cannot add the CATG parameter");
929 cpl_propertylist * hdr = gravi_data_get_header (
self);
930 if ( cpl_propertylist_has (hdr, GRAVI_NIGHT_OBS) ) {
931 cpl_propertylist_copy_property (applist, hdr, GRAVI_NIGHT_OBS);
932 CPLCHECK_MSG (
"Cannot set NIGHT_OBS");
934 if ( cpl_propertylist_has (hdr,
"DATE-OBS") ) {
935 cpl_propertylist_copy_property (applist, hdr,
"DATE-OBS");
936 CPLCHECK_MSG (
"Cannot DATE-OBS");
940 if (strstr (proCatg,
"VIS") || strstr (proCatg,
"TF")) {
942 cpl_propertylist_append (applist, tmp);
943 FREE (cpl_propertylist_delete, tmp);
951 for(i = 0; proCatg[i]; i++)
if (proCatg[i]!=
'_') { catg_ext[j] = tolower(proCatg[i]); j++; }
956 if (filename == NULL && frame != NULL) {
957 filename = cpl_frame_get_filename (frame);
958 }
else if (filename == NULL && frame == NULL) {
959 cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT,
"Need a frame if filename is void");
960 return CPL_ERROR_NULL_INPUT;
964 char * product_name = NULL;
966 if ( cpl_parameterlist_find_const (parlist,
"gravity.dfs.static-name") &&
967 gravi_param_get_bool (parlist,
"gravity.dfs.static-name")) {
971 product_name = cpl_sprintf (
"%s_%s_%s.fits", recipe, catg_ext, suffix);
973 product_name = cpl_sprintf (
"%s_%s.fits", recipe, catg_ext);
978 char * filenoext = cpl_strdup (FILESHORT(filename));
979 char * lastdot = strrchr (filenoext,
'.');
980 if (lastdot != NULL) *lastdot =
'\0';
981 product_name = cpl_sprintf (
"%s_%s.fits", filenoext, catg_ext);
982 FREE (cpl_free, filenoext);
985 cpl_msg_info (cpl_func,
"Save file to %s", product_name);
987 if (usedframes && frame==NULL) {
989 frameset = cpl_frameset_duplicate (usedframes);
991 else if (usedframes && frame) {
994 frameset = cpl_frameset_new ();
995 cpl_frameset_insert (frameset, cpl_frame_duplicate (frame));
996 for (
int f = 0; f < cpl_frameset_get_size (usedframes); f++)
997 if (strcmp (cpl_frame_get_filename (cpl_frameset_get_position (usedframes, f)), cpl_frame_get_filename (frame)))
998 cpl_frameset_insert (frameset, cpl_frame_duplicate (cpl_frameset_get_position (usedframes, f)));
1000 else if (usedframes==NULL && frame) {
1002 frameset = cpl_frameset_new ();
1003 cpl_frameset_insert (frameset, cpl_frame_duplicate (frame));
1007 cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT,
"Bug: need a frame or a usedframes");
1008 return CPL_ERROR_NULL_INPUT;
1012 cpl_dfs_save_propertylist (allframes, NULL, parlist,
1013 frameset, frame, recipe, applist,
1014 NULL, PACKAGE_STRING, product_name);
1015 CPLCHECK_MSG(
"Cannot save the first extension primary header");
1018 for (ext = 0; ext <
self->nb_ext; ext ++)
1020 if (self->exts_tbs[ext] != NULL)
1021 cpl_table_save (self->exts_tbs[ext], NULL,
1022 self->exts_hdrs[ext], product_name, CPL_IO_EXTEND);
1023 else if (self->exts_imgl[ext] != NULL)
1024 cpl_imagelist_save (self->exts_imgl[ext], product_name,
1025 cpl_image_get_type (cpl_imagelist_get (self->exts_imgl[ext], 0)),
1026 self->exts_hdrs[ext], CPL_IO_EXTEND);
1027 CPLCHECK_MSG(
"Cannot save the extension");
1030 FREE (cpl_frameset_delete, frameset);
1031 FREE (cpl_free, product_name);
1032 FREE (cpl_propertylist_delete, applist);
1034 gravi_msg_function_exit(0);
1035 return CPL_ERROR_NONE;
1052 cpl_ensure_code (detector_table, CPL_ERROR_NULL_INPUT);
1057 int ref0_y = gravi_table_get_value (detector_table,
"CENTER", reg, 1);
1058 int ref1_y = gravi_table_get_value (detector_table,
"CENTER", reg+1, 1);
1060 return (ref0_y+ref1_y)/2;
1087 const cpl_parameterlist * parlist)
1089 gravi_msg_function_start(1);
1090 cpl_ensure_code (data, CPL_ERROR_NULL_INPUT);
1095 cpl_propertylist * header = gravi_data_get_header (data);
1097 cpl_size nreg = cpl_table_get_nrow (detector_table);
1098 const char * resolution = gravi_pfits_get_resolution (header);
1100 CPLCHECK_MSG (
"Cannot get data");
1104 cpl_size nframe = cpl_imagelist_get_size (imglist);
1105 cpl_size nx = cpl_image_get_size_x (cpl_imagelist_get (imglist, 0));
1106 cpl_size ny = cpl_image_get_size_y (cpl_imagelist_get (imglist, 0));
1108 CPLCHECK_MSG (
"Cannot get data");
1111 cpl_vector * bias_list = cpl_vector_new (nframe);
1114 cpl_size nx_bias_hr = 4;
1115 cpl_size ny_reg_mr = (ny - 1) / nreg;
1116 cpl_size n_bias_line = 5;
1120 if ( !strcmp(resolution,
"HIGH") && !strcmp (gravi_param_get_string_default (parlist,
1121 "gravity.preproc.bias-method",
"MEDIAN"),
1122 "MEDIAN_PER_COLUMN")) {
1127 gravi_msg_warning (
"FIXME",
"Remove bias per column is experimental (HIGH)");
1129 cpl_vector * bias = cpl_vector_new (nx);
1130 cpl_vector * bias_column = cpl_vector_new (n_bias_line*2);
1133 for (cpl_size f = 0; f < nframe; f++) {
1134 cpl_image * frame = cpl_imagelist_get (imglist, f);
1137 for (cpl_size x = 0; x < nx; x++) {
1138 cpl_size bias_index=0;
1141 for (cpl_size y = 0; y < n_bias_line; y++) {
1142 double value = cpl_image_get (frame, x+1, y+1, &nv);
1143 cpl_vector_set (bias_column, bias_index++, value);
1144 CPLCHECK_MSG (
"Cannot get the bias pixels");
1148 for (cpl_size y = 0; y < n_bias_line; y++) {
1149 double value = cpl_image_get (frame, x+1, ny-y, &nv);
1150 cpl_vector_set (bias_column, bias_index++, value);
1151 CPLCHECK_MSG (
"Cannot get the bias pixels");
1155 double bias_med = cpl_vector_get_median (bias_column);
1156 cpl_vector_set (bias, x, bias_med);
1159 for (cpl_size y = 0; y < ny; y++) {
1160 double value = cpl_image_get (frame, x+1, y+1, &nv);
1161 cpl_image_set (frame, x+1, y+1, value - bias_med);
1162 CPLCHECK_MSG (
"Cannot set the bias corrected pixels");
1167 double bias_mean = cpl_vector_get_mean (bias);
1168 cpl_vector_set (bias_list, f, bias_mean);
1170 FREE (cpl_vector_delete, bias);
1171 FREE (cpl_vector_delete, bias_column);
1173 else if ( !strcmp(resolution,
"HIGH") ) {
1178 cpl_vector * bias = cpl_vector_new (nx_bias_hr * ny);
1181 for (cpl_size f = 0; f < nframe; f++) {
1182 cpl_image * frame = cpl_imagelist_get (imglist, f);
1185 for (cpl_size x = 0; x < nx_bias_hr; x++)
1186 for (cpl_size y = 0; y < ny; y++) {
1187 cpl_vector_set (bias, x * ny + y, cpl_image_get (frame, x+1, y+1, &nv));
1188 CPLCHECK_MSG (
"Cannot get the bias pixels");
1192 double bias_med = cpl_vector_get_median (bias);
1193 cpl_vector_set (bias_list, f, bias_med);
1194 cpl_image_subtract_scalar (frame, bias_med);
1195 CPLCHECK_MSG (
"Cannot subtract bias");
1197 FREE (cpl_vector_delete, bias);
1199 else if ( !strcmp (gravi_param_get_string_default (parlist,
1200 "gravity.preproc.bias-method",
"MEDIAN"),
1201 "MEDIAN_PER_COLUMN")) {
1206 gravi_msg_warning (
"FIXME",
"Remove bias per column is experimental (LOW, MEDIUM)");
1208 cpl_vector * bias = cpl_vector_new (nx);
1210 cpl_vector * bias_column = cpl_vector_new ((nreg-1)*n_bias_line);
1211 cpl_vector * bias_coord = cpl_vector_new ((nreg-1)*n_bias_line);
1214 for (cpl_size f = 0; f < nframe; f++) {
1215 cpl_image * frame = cpl_imagelist_get (imglist, f);
1218 for (cpl_size x = 0; x < nx; x++) {
1219 cpl_size bias_index=0;
1229 for (cpl_size reg = 0; reg < nreg-1; reg++) {
1231 for (cpl_size y = 0; y < n_bias_line; y++){
1232 double value = cpl_image_get (frame, x+1, starty+y+1, &nv);
1233 cpl_vector_set (bias_column, bias_index, value);
1234 cpl_vector_set (bias_coord, bias_index++, starty+y);
1236 CPLCHECK_MSG (
"Cannot get the bias pixels");
1241 cpl_vector_set (bias, x, bias_med);
1244 for (cpl_size y = 0; y < ny; y++) {
1245 double value = cpl_image_get (frame, x+1, y+1, &nv);
1246 cpl_image_set (frame, x+1, y+1, value - bias_med);
1247 CPLCHECK_MSG (
"Cannot set the bias corrected pixels");
1252 double bias_mean = cpl_vector_get_mean (bias);
1253 cpl_vector_set (bias_list, f, bias_mean);
1255 FREE (cpl_vector_delete, bias);
1256 FREE (cpl_vector_delete, bias_column);
1262 cpl_vector * bias = cpl_vector_new (nx * nreg);
1265 for (cpl_size f = 0; f < nframe; f++) {
1266 cpl_image * frame = cpl_imagelist_get (imglist, f);
1269 for (cpl_size x = 0; x < nx; x++)
1270 for (cpl_size y = 0; y < nreg; y++) {
1271 cpl_vector_set (bias, x * nreg + y, cpl_image_get (frame, x+1, (y+1)*ny_reg_mr+1, &nv));
1272 CPLCHECK_MSG (
"Cannot get the bias pixels");
1276 double bias_med = cpl_vector_get_median (bias);
1277 cpl_vector_set (bias_list, f, bias_med);
1278 cpl_image_subtract_scalar (frame, bias_med);
1279 CPLCHECK_MSG (
"Cannot subtract bias");
1281 FREE (cpl_vector_delete, bias);
1285 cpl_propertylist_update_double (header,
"ESO QC PIXBIAS AVG", cpl_vector_get_mean (bias_list));
1286 cpl_propertylist_set_comment (header,
"ESO QC PIXBIAS AVG",
"[adu] avg over the bias pixel");
1288 cpl_propertylist_update_double (header,
"ESO QC PIXBIAS RMS", cpl_vector_get_stdev (bias_list));
1289 cpl_propertylist_set_comment (header,
"ESO QC PIXBIAS RMS",
"[adu] rms over frames");
1290 cpl_vector_delete (bias_list);
1292 gravi_msg_function_exit(1);
1293 return CPL_ERROR_NONE;
1299 inline static int _gravi_data_find (
const gravi_data *
self,
const char *name)
1302 while (ext < self->nb_ext){
1303 cpl_propertylist *p =
self->exts_hdrs[ext];
1304 const char *key = cpl_propertylist_get_string (p,
"EXTNAME");
1305 if (strcmp(key, name) == 0)
break;
1329 cpl_ensure_code (output, CPL_ERROR_NULL_INPUT);
1330 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1331 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1334 for (
int j = 0; j < n; j++){
1337 const char * plist_name = gravi_pfits_get_extname (plist);
1339 CPLCHECK_MSG (
"Cannot get input data");
1341 if (plist_name == NULL)
continue;
1343 if (!(strcmp (plist_name, name))) {
1344 int type_data = gravi_pfits_get_extension_type (plist);
1346 if (type_data == 2) {
1350 else if (type_data == 3) {
1355 CPLCHECK_MSG (
"Cannot copy extension");
1359 return CPL_ERROR_NONE;
1380 gravi_msg_function_start(0);
1381 cpl_ensure_code (output, CPL_ERROR_NULL_INPUT);
1382 cpl_ensure_code (input, CPL_ERROR_NULL_INPUT);
1383 cpl_ensure_code (name, CPL_ERROR_NULL_INPUT);
1388 for (
int j = 0; j < n; j++){
1391 const char * plist_name = gravi_pfits_get_extname (plist);
1392 CPLCHECK_MSG (
"Cannot get input");
1395 if ( (plist_name!=NULL) &&
1396 !(strcmp (plist_name, name))) {
1398 cpl_msg_info (cpl_func,
"Move extension %s", plist_name);
1399 int type_data = gravi_pfits_get_extension_type (plist);
1400 if (type_data == 2) {
1404 else if (type_data == 3) {
1408 CPLCHECK_MSG (
"Cannot move extension");
1413 input->exts_hdrs[jnew] = input->exts_hdrs[j];
1414 input->exts_imgl[jnew] = input->exts_imgl[j];
1415 input->exts_tbs[jnew] = input->exts_tbs[j];
1422 input->nb_ext = jnew;
1423 for (
int j = input->nb_ext; j < GRAVI_DATA_SIZE; j++) {
1424 input->exts_hdrs[j] = NULL;
1425 input->exts_imgl[j] = NULL;
1426 input->exts_tbs[j] = NULL;
1429 gravi_msg_function_exit(0);
1430 return CPL_ERROR_NONE;
1445 cpl_ensure (raw_calib, CPL_ERROR_NULL_INPUT, 0);
1446 cpl_ensure (ext_name, CPL_ERROR_NULL_INPUT, 0);
1449 int ext = _gravi_data_find (raw_calib, ext_name);
1451 if (ext == raw_calib->nb_ext) {
1470 cpl_ensure (
self, CPL_ERROR_NULL_INPUT, -1);
1471 cpl_ensure (type, CPL_ERROR_NULL_INPUT, -1);
1472 cpl_ensure (strlen (type)>1, CPL_ERROR_ILLEGAL_INPUT, -1);
1483 if ( (cpl_propertylist_has (plist,
"INSNAME") &&
1484 strstr (gravi_pfits_get_insname (plist), type) ) ||
1485 (cpl_propertylist_has (plist,
"EXTNAME") &&
1486 strstr (gravi_pfits_get_extname (plist), type) ) )
1488 cpl_msg_debug (cpl_func,
"Find '%s' ", gravi_pfits_get_extname (plist));
1513 cpl_ensure (
self, CPL_ERROR_NULL_INPUT, NULL);
1514 cpl_ensure (i>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1515 cpl_ensure (i<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
1517 return self->exts_hdrs[i];
1538 cpl_ensure (
self, CPL_ERROR_NULL_INPUT, NULL);
1539 cpl_ensure (i>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1540 cpl_ensure (i<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
1542 return self->exts_tbs[i];
1563 cpl_ensure (
self, CPL_ERROR_NULL_INPUT, NULL);
1564 cpl_ensure (i>=0, CPL_ERROR_ILLEGAL_INPUT, NULL);
1565 cpl_ensure (i<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
1567 return self->exts_imgl[i];
1588 const char * extname,
1589 const char * insname)
1591 cpl_ensure (
self, CPL_ERROR_NULL_INPUT, NULL);
1592 cpl_ensure (extname, CPL_ERROR_NULL_INPUT, NULL);
1593 cpl_ensure (insname, CPL_ERROR_NULL_INPUT, NULL);
1595 int nb_ext =
self->nb_ext;
1597 for (
int i = 0; i < nb_ext; i++){
1599 if (cpl_propertylist_has (self->exts_hdrs[i],
"INSNAME")){
1600 if ((!strcmp (gravi_pfits_get_insname (self->exts_hdrs[i]), insname)) &&
1601 (!strcmp (gravi_pfits_get_extname (self->exts_hdrs[i]), extname))){
1609 cpl_msg_warning(cpl_func,
"The extention %s doesn't exist " 1610 "with the insname %s",
1615 return self->exts_tbs[pos];
1637 const char * extname,
1638 const char * insname)
1640 cpl_ensure (
self, CPL_ERROR_NULL_INPUT, NULL);
1641 cpl_ensure (extname, CPL_ERROR_NULL_INPUT, NULL);
1642 cpl_ensure (insname, CPL_ERROR_NULL_INPUT, NULL);
1644 int nb_ext =
self->nb_ext;
1646 for (
int i = 0; i < nb_ext; i++){
1647 if (cpl_propertylist_has (self->exts_hdrs[i],
"INSNAME")){
1648 if ((!strcmp (gravi_pfits_get_insname (self->exts_hdrs[i]), insname)) &&
1649 (!strcmp (gravi_pfits_get_extname (self->exts_hdrs[i]), extname))){
1657 cpl_msg_warning(cpl_func,
"The extention %s doesn't exist " 1658 "with the insname %s",
1663 return self->exts_hdrs[pos];
1685 const char * extname)
1687 cpl_ensure (
self, CPL_ERROR_NULL_INPUT, NULL);
1688 cpl_ensure (extname, CPL_ERROR_NULL_INPUT, NULL);
1690 if (!strcmp(extname, GRAVI_PRIMARY_HDR_EXT))
1691 return self->primary_hdr;
1693 int pos = _gravi_data_find(
self, extname);
1695 cpl_ensure (pos<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
1697 return self->exts_hdrs[pos];
1718 cpl_ensure (
self, CPL_ERROR_NULL_INPUT, NULL);
1719 cpl_ensure (extname, CPL_ERROR_NULL_INPUT, NULL);
1721 int pos = _gravi_data_find(
self, extname);
1723 cpl_ensure (pos<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
1725 if ((self->exts_tbs[pos] == NULL) ||
1726 (gravi_pfits_get_extension_type (self->exts_hdrs[pos]) != 2)){
1727 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1728 "No BINTABLE at the extension %s", extname);
1732 return self->exts_tbs[pos];
1753 cpl_ensure (
self, CPL_ERROR_NULL_INPUT, NULL);
1754 cpl_ensure (extname, CPL_ERROR_NULL_INPUT, NULL);
1756 int pos = _gravi_data_find(
self, extname);
1758 cpl_ensure (pos<self->nb_ext, CPL_ERROR_ILLEGAL_INPUT, NULL);
1760 if ((self->exts_imgl[pos] == NULL) ||
1761 (gravi_pfits_get_extension_type (self->exts_hdrs[pos]) != 3)){
1762 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1763 "No IMAGE at the extension %s", extname);
1767 return self->exts_imgl[pos];
1783 cpl_ensure_code (
self, CPL_ERROR_NULL_INPUT);
1784 cpl_ensure_code (pos>-1, CPL_ERROR_ILLEGAL_INPUT);
1788 for (
int i = 0; i <
self->nb_ext; i++) {
1790 self->exts_hdrs[comp] =
self->exts_hdrs[i];
1791 self->exts_tbs[comp] =
self->exts_tbs[i];
1792 self->exts_imgl[comp] =
self->exts_imgl[i];
1796 if ((gravi_pfits_get_extension_type (self->exts_hdrs[pos]) == 2))
1797 FREE (cpl_table_delete, self->exts_tbs[i]);
1798 else if (gravi_pfits_get_extension_type (self->exts_hdrs[pos]) == 3)
1799 FREE (cpl_imagelist_delete, self->exts_imgl[i]);
1800 CPLCHECK_MSG(
"Cannot delete data");
1802 FREE (cpl_propertylist_delete, self->exts_hdrs[i]);
1803 CPLCHECK_MSG(
"Cannot delete header");
1808 for (
int i = comp ; i<GRAVI_DATA_SIZE; i++) {
1809 self->exts_hdrs[i] = NULL;
1810 self->exts_tbs[i] = NULL;
1811 self->exts_imgl[i] = NULL;
1815 self->nb_ext = comp;
1817 return CPL_ERROR_NONE;
1834 cpl_ensure_code (
self, CPL_ERROR_NULL_INPUT);
1835 cpl_ensure_code (extname, CPL_ERROR_NULL_INPUT);
1838 int pos = _gravi_data_find(
self, extname);
1841 if (pos == self->nb_ext) {
1842 cpl_msg_info (cpl_func,
"Cannot delete '%s' (not found)",extname);
1843 return CPL_ERROR_NONE;
1845 cpl_msg_info (cpl_func,
"Delete '%s' found in ext[%i] (over %i) ",extname, pos, self->nb_ext);
1851 CPLCHECK_MSG (
"Cannot erase this extension name");
1852 return CPL_ERROR_NONE;
1869 cpl_ensure_code (
self, CPL_ERROR_NULL_INPUT);
1870 cpl_ensure_code (type, CPL_ERROR_NULL_INPUT);
1871 cpl_ensure_code (strlen (type)>1, CPL_ERROR_ILLEGAL_INPUT);
1880 if ( (cpl_propertylist_has (plist,
"INSNAME") &&
1881 strstr (gravi_pfits_get_insname (plist), type) ) ||
1882 (cpl_propertylist_has (plist,
"EXTNAME") &&
1883 strstr (gravi_pfits_get_extname (plist), type) ) )
1885 cpl_msg_info (cpl_func,
"Delete '%s' ", gravi_pfits_get_extname (plist));
1889 CPLCHECK_MSG (
"Cannot erase this type");
1892 return CPL_ERROR_NONE;
1910 cpl_propertylist * plist,
1911 const char * extname,
1914 cpl_ensure_code (
self, CPL_ERROR_NULL_INPUT);
1915 cpl_ensure_code (table, CPL_ERROR_NULL_INPUT);
1918 if (plist == NULL) plist = cpl_propertylist_new ();
1919 if (extname != NULL) cpl_propertylist_update_string (plist,
"EXTNAME", extname);
1922 cpl_propertylist_update_string (plist,
"XTENSION",
"BINTABLE");
1923 self->exts_hdrs[
self->nb_ext] = plist;
1926 if (!cpl_propertylist_has(plist,
"EXTNAME") ) {
1927 cpl_msg_error (cpl_func,
"FIXME: set a table without EXTNAME !!");
1928 cpl_propertylist_update_string (plist,
"EXTNAME",
"UNKNOWN");
1932 const char * plist_name = 0;
1933 if (cpl_propertylist_has (plist,
"EXTNAME"))
1934 plist_name = gravi_pfits_get_extname (plist);
1936 if (plist_name && !(strcmp(plist_name, GRAVI_OI_ARRAY_EXT) &&
1937 strcmp (plist_name, GRAVI_OI_TARGET_EXT) &&
1938 strcmp (plist_name, GRAVI_OI_WAVELENGTH_EXT) &&
1939 strcmp (plist_name, GRAVI_OI_FLUX_EXT) &&
1940 strcmp (plist_name, GRAVI_OI_T3_EXT) &&
1941 strcmp (plist_name, GRAVI_OI_VIS2_EXT) &&
1942 strcmp (plist_name, GRAVI_OI_VIS_EXT))) {
1943 cpl_propertylist_update_int (plist,
"OI_REVN", 1);
1949 self->exts_tbs[
self->nb_ext] = table;
1950 self->exts_imgl[
self->nb_ext] = NULL;
1954 CPLCHECK_MSG (
"Cannot add the table");
1955 return CPL_ERROR_NONE;
1973 cpl_propertylist * plist,
1974 const char * extname,
1975 cpl_imagelist * imglist)
1978 cpl_ensure_code (
self, CPL_ERROR_NULL_INPUT);
1979 cpl_ensure_code (imglist, CPL_ERROR_NULL_INPUT);
1981 if (plist == NULL) plist = cpl_propertylist_new ();
1982 if (extname != NULL) cpl_propertylist_update_string (plist,
"EXTNAME", extname);
1985 self->exts_hdrs[
self->nb_ext] = plist;
1986 cpl_propertylist_update_string (self->exts_hdrs[self->nb_ext],
"XTENSION",
"IMAGE");
1989 self->exts_imgl[
self->nb_ext] = (imglist);
1990 self->exts_tbs[
self->nb_ext] = NULL;
1994 CPLCHECK_MSG (
"Cannot add the cube");
1995 return CPL_ERROR_NONE;
2014 cpl_propertylist * plist,
2015 const char * extname,
2016 cpl_image * image) {
2018 cpl_ensure_code (
self, CPL_ERROR_NULL_INPUT);
2019 cpl_ensure_code (image, CPL_ERROR_NULL_INPUT);
2021 if (plist == NULL) plist = cpl_propertylist_new ();
2022 if (extname != NULL) cpl_propertylist_update_string (plist,
"EXTNAME", extname);
2025 self->exts_hdrs[
self->nb_ext] = plist;
2026 cpl_propertylist_update_string (self->exts_hdrs[self->nb_ext],
"XTENSION",
"IMAGE");
2029 cpl_imagelist * imglist = cpl_imagelist_new ();
2030 cpl_imagelist_set (imglist, image, 0);
2033 self->exts_imgl[
self->nb_ext] = (imglist);
2034 self->exts_tbs[
self->nb_ext] = NULL;
2038 CPLCHECK_MSG (
"Cannot add the image");
2039 return CPL_ERROR_NONE;
2056 gravi_msg_function_start(1);
2057 cpl_ensure_code (data, CPL_ERROR_NULL_INPUT);
2064 const char * plist_name = gravi_pfits_get_extname (plist);
2065 if (!(strcmp (plist_name, GRAVI_OI_ARRAY_EXT)) ||
2066 !(strcmp (plist_name, GRAVI_OI_TARGET_EXT)) ) {
2067 cpl_msg_debug (cpl_func,
"NAME: %s kept", plist_name);
2072 if (cpl_propertylist_has (plist,
"INSNAME") &&
2073 ( (!strcmp (gravi_pfits_get_insname (plist), INSNAME_SC_P1)) ||
2074 (!strcmp (gravi_pfits_get_insname (plist), INSNAME_SC_P2)) ||
2075 (!strcmp (gravi_pfits_get_insname (plist), INSNAME_SC)) ) ) {
2076 cpl_msg_debug (cpl_func,
"NAME: %s kept", plist_name);
2081 cpl_msg_debug (cpl_func,
"NAME: %s deleted", plist_name);
2082 FREE (cpl_propertylist_delete, data->exts_hdrs[i]);
2083 FREE (cpl_table_delete, data->exts_tbs[i]);
2084 FREE (cpl_imagelist_delete, data->exts_imgl[i]);
2092 if (data->exts_hdrs[i] || data->exts_tbs[i] || data->exts_imgl[i]) {
2094 data->exts_hdrs[j] = data->exts_hdrs[i]; data->exts_hdrs[i] = NULL;
2095 data->exts_tbs[j] = data->exts_tbs[i]; data->exts_tbs[i] = NULL;
2096 data->exts_imgl[j] = data->exts_imgl[i]; data->exts_imgl[i] = NULL;
2104 gravi_msg_function_exit(1);
2105 return CPL_ERROR_NONE;
2123 gravi_msg_function_start(0);
2124 cpl_ensure_code (data, CPL_ERROR_NULL_INPUT);
2129 cpl_propertylist * header = gravi_data_get_header (data);
2130 cpl_propertylist_append_int (header,
"ESO QC CHECK FLAGS", 0);
2134 const char *extname[] = {
"ARRAY_DESCRIPTION",
"ARRAY_GEOMETRY",
"OPTICAL_TRAIN",
2135 "IMAGING_DATA_ACQ",
"ACQ_ABS_REF_POSITION",
2136 "OPDC",
"FDDL",
"METROLOGY",
2137 "IMAGING_DATA_SC",
"IMAGING_DETECTOR_SC",
2138 "IMAGING_DATA_FT",
"IMAGING_DETECTOR_FT"};
2140 for (
int ext = 0; ext< nb_ext; ext++) {
2144 sprintf (qc_msg,
"%s is missing", extname[ext]);
2149 cpl_propertylist * plist;
2153 if (cpl_propertylist_has (plist,
"ESO DET FRAM NO")) {
2154 int frame_no = cpl_propertylist_get_int (plist,
"ESO DET FRAM NO");
2155 int naxis_3 = cpl_propertylist_get_int (plist,
"NAXIS3");
2156 if ( frame_no != naxis_3) {
2157 sprintf (qc_msg,
"%s is missing DITs", extname[ext]);
2163 CPLCHECK_MSG (
"Cannot check consistency of tables...");
2170 int ndit = cpl_propertylist_get_int (header,
"ESO DET2 NDIT");
2171 double scdit = gravi_pfits_get_dit_sc (header);
2175 cpl_msg_debug (cpl_func,
"start = %8.0f and end = %10.0f (%s [us] from PCR.ACQ.START)",
2176 start_sc, end_sc,
"SC");
2180 const char *ext_rmn[] = {
"OPDC",
"FDDL",
"METROLOGY",
"IMAGING_DATA_FT"};
2182 for (
int ext = 0; ext< nb_ext_rmn; ext++) {
2189 double min_table = cpl_table_get_column_min (table,
"TIME");
2190 double max_table = cpl_table_get_column_max (table,
"TIME");
2192 cpl_msg_debug (cpl_func,
"start = %8.0f and end = %10.0f (%s [us] from PCR.ACQ.START)",
2193 min_table, max_table, ext_rmn[ext]);
2196 if ( min_table > start_sc) {
2197 sprintf (qc_msg,
"%s starts *after* the science exposure", ext_rmn[ext]);
2200 if ( max_table < end_sc) {
2201 sprintf (qc_msg,
"%s finish *before* the science exposure", ext_rmn[ext]);
2206 cpl_size nrow = cpl_table_get_nrow (table);
2207 int * time = cpl_table_get_data_int (table,
"TIME");
2208 CPLCHECK_MSG (
"Cannot get data");
2211 cpl_size nsamp = CPL_MIN (10000, nrow-1);
2212 cpl_array * delta = cpl_array_new (nsamp, CPL_TYPE_INT);
2213 for (cpl_size row = 0; row < nsamp ; row++) {
2214 cpl_array_set_int (delta, row, time[row+1] - time[row]);
2216 double median_delta = cpl_array_get_median (delta);
2217 FREE (cpl_array_delete, delta);
2221 for (cpl_size row = 0; row < nrow-1 ; row++) {
2222 double current_delta = time[row+1] - time[row];
2223 if (current_delta > 1.5 * median_delta) nwrong ++;
2227 sprintf (qc_msg,
"%s has %i wrong steps", ext_rmn[ext], nwrong);
2233 CPLCHECK_MSG (
"Cannot check consistency of RMN tables...");
2235 gravi_msg_function_exit(0);
2236 return CPL_ERROR_NONE;
2255 cpl_ensure (data, CPL_ERROR_NULL_INPUT, NULL);
2256 cpl_ensure (npol == 1 || npol == 2, CPL_ERROR_ILLEGAL_INPUT, NULL);
2257 cpl_ensure (type_data == GRAVI_SC || type_data == GRAVI_FT, CPL_ERROR_ILLEGAL_INPUT, NULL);
2259 cpl_table ** oiwave_tables = cpl_calloc (npol,
sizeof(cpl_table *));
2260 for (
int pol = 0; pol < npol; pol++)
2261 oiwave_tables[pol] = gravi_data_get_oi_wave (data, type_data, pol, npol);
2263 return oiwave_tables;
gravi_data * gravi_data_new(int nb_ext)
Create an empty gravi_data.
double gravi_pfits_get_time_sc(const cpl_propertylist *header, cpl_size row)
Time of the middle of the SC exposure row in [us], counted from PRC.ACQ.START.
cpl_propertylist * gravi_data_get_oi_plist(gravi_data *self, const char *extname, const char *insname)
Get the propertylist from EXTNAME and INSNAME.
gravi_data * gravi_data_load_frame(cpl_frame *frame, cpl_frameset *used_frameset)
Load a FITS file and create a gravi_data.
gravi_data * gravi_data_load(const char *filename)
Low-level function to load FITS file.
cpl_error_code gravi_data_copy_ext(gravi_data *output, gravi_data *input, const char *name)
Copy extensions from one data to another.
cpl_propertylist * gravi_data_get_plist_x(gravi_data *self, int i)
Get the propertylist of an extension by position.
cpl_error_code gravi_data_erase_type(gravi_data *self, const char *type)
Erase all extension related to an instrument (SC, FT, MET...)
int gravi_data_has_extension(gravi_data *raw_calib, const char *ext_name)
Check if data has extension with given EXTNAME.
gravi_data * gravi_data_load_rawframe(cpl_frame *frame, cpl_frameset *used_frameset)
Load a RAW FITS file and create a gravi_data.
gravi_data * gravi_data_load_ext(const char *filename, const char *extensions_regexp)
Low-level function to load FITS file.
cpl_error_code gravi_pfits_add_check(cpl_propertylist *header, char *msg)
Add a QC.CHECK keyword to the header.
cpl_error_code gravi_data_move_ext(gravi_data *output, gravi_data *input, const char *name)
Move extensions from one data to another.
cpl_error_code gravi_data_save_data(gravi_data *self, const char *filename, unsigned mode)
Save a gravi data in a FITS file.
cpl_propertylist * gravi_plist_get_oifits_keywords(cpl_propertylist *header)
Create OIFITS keywords to satisfy standar.
cpl_table ** gravi_data_get_oiwave_tables(gravi_data *data, int type_data, int npol)
Get pointer to the OI_WAVELENGTH tables of both polarisations.
int gravi_data_is_oi_ext(cpl_propertylist *hdr)
Check if EXTNAME starts with 'OI_' (OIFITS extension)
cpl_error_code gravi_data_erase_x(gravi_data *self, int pos)
Erase an extension by its position.
int gravi_table_are_equal(cpl_table *first, cpl_table *second)
Check if two tables have the same content.
cpl_table * gravi_data_get_table(gravi_data *self, const char *extname)
Return a pointer on a table extension by its EXTNAME.
cpl_error_code gravi_data_check_consistency(gravi_data *data)
Verify the integrity of RAW data.
cpl_imagelist * gravi_data_get_cube_x(gravi_data *self, int i)
Get the cube of an extension by position.
cpl_error_code gravi_pfits_add_pipe_build(cpl_propertylist *header)
Add the ESO PRO REC# PIPE LAST_BUILD in header.
cpl_error_code gravi_data_dump(gravi_data *self)
Dump the overall structure of a gravi_data in stdout.
cpl_error_code gravi_data_check_savetypes(cpl_propertylist *hdr, cpl_table *oi_table)
Set the savetypes of the OIFITS table.
cpl_error_code gravi_data_detector_cleanup(gravi_data *data, const cpl_parameterlist *parlist)
Perform self-bias correction to the SC raw data.
cpl_error_code gravi_data_save_new(gravi_data *self, cpl_frameset *allframes, const char *filename, const char *suffix, const cpl_parameterlist *parlist, cpl_frameset *usedframes, cpl_frame *frame, const char *recipe, cpl_propertylist *applist, const char *proCatg)
Save a gravi data in a CPL-complian FITS file.
cpl_error_code gravi_data_dump_mode(gravi_data *data)
Dump some information about data in messagin.
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.
int gravi_data_has_type(gravi_data *self, const char *type)
Return the number of ext whose EXTNAME and INSNAME match 'type'.
cpl_error_code gravi_data_clean_for_astro(gravi_data *data)
Clean the data to keep only OIFITS extensions related to SC.
cpl_propertylist * gravi_data_get_plist(gravi_data *self, const char *extname)
Get the propertylist from EXTNAME.
cpl_table * gravi_data_get_table_x(gravi_data *self, int i)
Get the table of an extension by position.
cpl_imagelist * gravi_data_get_cube(gravi_data *self, const char *extname)
Return a pointer on an IMAGE extension by its EXTNAME.
cpl_error_code gravi_data_add_cube(gravi_data *self, cpl_propertylist *plist, const char *extname, cpl_imagelist *imglist)
Add an IMAGE (imagelist) extension in gravi_data.
gravi_data * gravi_data_load_rawframe_ext(cpl_frame *frame, cpl_frameset *used_frameset, char *extensions_regexp)
Load a RAW FITS file and create a gravi_data from specified extensions.
cpl_error_code gravi_data_add_table(gravi_data *self, cpl_propertylist *plist, const char *extname, cpl_table *table)
Add a BINTABLE extension in gravi_data.
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
gravi_data * gravi_data_duplicate(const gravi_data *self)
Create a copy of the gravi data.
int gravi_data_patch(gravi_data *file_to_patch, cpl_frameset *patch_frameset)
Load a RAW FITS file and create a gravi_data.
cpl_error_code gravi_data_erase(gravi_data *self, const char *extname)
Erase an extension by its EXTNAME.
cpl_error_code gravi_data_append(gravi_data *first, const gravi_data *second, int force)
Append a gravi_data into another existing one.
cpl_error_code gravi_data_add_img(gravi_data *self, cpl_propertylist *plist, const char *extname, cpl_image *image)
Add an IMAGE (single image) extension in gravi_data.
int gravi_data_get_dark_pos(cpl_table *detector_table, int reg)
retrun the position of the dark line on top of the region at x position
int gravi_data_get_size(const gravi_data *self)
Get the number of extension in a gravi_data.
cpl_table * gravi_data_get_oi_table(gravi_data *self, const char *extname, const char *insname)
Get an OI_FITS table from EXTNAME and INSNAME.