67#include <irplib_sdp_spectrum.h>
77 for (
int i = 0; str[i] !=
'\0'; i++) {
98 cpl_frameset* raws=NULL;
99 raws=cpl_frameset_new();
105 return cpl_error_get_code();
121 flag_norm = (cpl_parameter_get_default_flag(p) == 0) ? 1 : 0;
122 type=cpl_parameter_get_type(p);
126 flag_gasgano = (cpl_parameter_get_default_bool(p) ==
127 cpl_parameter_get_bool(p)) ? 1:0;
130 flag_gasgano = (cpl_parameter_get_default_int(p) ==
131 cpl_parameter_get_int(p)) ? 1:0;
133 case CPL_TYPE_DOUBLE:
134 flag_gasgano = (cpl_parameter_get_default_double(p) ==
135 cpl_parameter_get_double(p)) ? 1:0;
137 case CPL_TYPE_STRING:
138 flag_gasgano = (cpl_parameter_get_default_string(p) ==
139 cpl_parameter_get_string(p)) ? 1:0;
146 flag = (flag_gasgano && flag_norm) ? 0 : 1;
155 cpl_propertylist_erase_regexp(header,
156 "^[:blank:]*(COMMENT|CHECKSUM|DATASUM|RADECSYS)[:blank:]*$",
159 return cpl_error_get_code();
171 const char* mod_name=NULL;
172 const char* raw_name=NULL;
173 cpl_frame* raw_frame=0;
174 cpl_propertylist* mod_header=NULL;
179 raw_frame=cpl_frameset_get_frame(set,0);
181 mod_name=cpl_frame_get_filename(mod);
182 mod_header=cpl_propertylist_load(mod_name,0);
185 raw_name=cpl_frame_get_filename(raw_frame);
189 if(raw_mjd < mod_mjd) {
191 xsh_msg_warning(
"Raw frame %s has MJD-OBS prior than model cfg frame %s",
193 xsh_msg_warning(
"The user should use a model cfg frame corresponding to a more recent period");
197 return cpl_error_get_code();
208 cpl_frameset* result=NULL;
212 cpl_propertylist* plist=NULL;
213 const char* name=NULL;
216 check(nset=cpl_frameset_get_size(set));
217 result=cpl_frameset_new();
218 for(i=0;i<nset;i++) {
219 check(frm=cpl_frameset_get_frame(set,i));
220 check(name=cpl_frame_get_filename(frm));
221 check(plist=cpl_propertylist_load(name,0));
224 check(cpl_frameset_insert(result,cpl_frame_duplicate(frm)));
247 const char *func =
"dfs_files_dont_exist";
251 if (frameset == NULL) {
252 cpl_error_set(func, CPL_ERROR_NULL_INPUT);
256 if (cpl_frameset_is_empty(frameset)) {
260 cpl_frameset_iterator* it = cpl_frameset_iterator_new(frameset);
261 frame = cpl_frameset_iterator_get(it);
263 if (access(cpl_frame_get_filename(frame), F_OK)) {
264 cpl_msg_error(func,
"File %s (%s) was not found",
265 cpl_frame_get_filename(frame),
266 cpl_frame_get_tag(frame));
267 cpl_error_set(func, CPL_ERROR_FILE_NOT_FOUND);
269 cpl_frameset_iterator_advance(it, 1);
270 frame = cpl_frameset_iterator_get(it);
272 cpl_frameset_iterator_delete(it);
274 if (cpl_error_get_code())
287 cpl_frameset* result=NULL;
291 cpl_propertylist* plist=NULL;
292 const char* name=NULL;
295 check(nset=cpl_frameset_get_size(set));
296 result=cpl_frameset_new();
297 for(i=0;i<nset;i++) {
298 check(frm=cpl_frameset_get_frame(set,i));
299 check(name=cpl_frame_get_filename(frm));
300 check(plist=cpl_propertylist_load(name,0));
303 check(cpl_frameset_insert(result,cpl_frame_duplicate(frm)));
320 cpl_frameset* result=NULL;
324 cpl_propertylist* plist=NULL;
325 const char* name=NULL;
328 check(nset=cpl_frameset_get_size(set));
329 result=cpl_frameset_new();
330 for(i=0;i<nset;i++) {
331 check(frm=cpl_frameset_get_frame(set,i));
332 check(name=cpl_frame_get_filename(frm));
333 check(plist=cpl_propertylist_load(name,0));
336 check(cpl_frameset_insert(result,cpl_frame_duplicate(frm)));
356 cpl_frameset* obj=NULL;
357 cpl_frameset* sky=NULL;
358 const char * obj_tag=NULL;
359 const char * sky_tag=NULL;
366 check(nraws=cpl_frameset_get_size(*raws));
368 assure(nraws>=2, CPL_ERROR_ILLEGAL_INPUT,
"Too few input frames. At least one OBJ and a SKY frame are required" );
377 nobj=cpl_frameset_get_size(obj);
386 nobj=cpl_frameset_get_size(obj);
399 nsky=cpl_frameset_get_size(sky);
401 assure(nobj>0, CPL_ERROR_ILLEGAL_INPUT,
402 "Too few input obj frames. At least a OBJ frame is required" );
404 assure(nsky>0, CPL_ERROR_ILLEGAL_INPUT,
405 "Too few input sky frames. At least a SKY frame is required" );
410 for(i=0;i<ndif;i++) {
411 check(frm=cpl_frameset_get_frame(obj,nobj-i-1));
412 check(cpl_frameset_erase_frame(obj,frm));
414 }
else if(nsky>nobj) {
417 for(i=0;i<ndif;i++) {
418 check(frm=cpl_frameset_get_frame(sky,nsky-i-1));
419 check(cpl_frameset_erase_frame(sky,frm));
425 return CPL_ERROR_NONE;
429 check(*raws=cpl_frameset_duplicate(obj));
436 return cpl_error_get_code();
462 posang = posang/180.0*
M_PI;
467 offsety=(cos(-posang)*dec_off+
468 sin(-posang)*ra_off);
469 xsh_msg(
"ra_off=%f,dec_off=%f,offsety=%f,posang=%f",
470 ra_off,dec_off,offsety,posang);
488 cpl_frameset* result=NULL;
489 cpl_propertylist* plist=NULL;
491 const char* name=NULL;
496 nraw=cpl_frameset_get_size(raws);
497 result=cpl_frameset_new();
498 for(i=0;i<nraw;i++) {
499 frm=cpl_frameset_get_frame(raws,i);
500 name=cpl_frame_get_filename(frm);
501 plist=cpl_propertylist_load(name,0);
504 if(fabs(offsety-offset)<1.E-8) {
505 cpl_frameset_insert(result,cpl_frame_duplicate(frm));
530 cpl_frameset* result=NULL;
531 cpl_propertylist* plist=NULL;
533 const char* name=NULL;
542 nraw=cpl_frameset_get_size(raws);
543 result=cpl_frameset_new();
544 for(i=0;i<nraw;i++) {
545 frm=cpl_frameset_get_frame(raws,i);
546 name=cpl_frame_get_filename(frm);
547 plist=cpl_propertylist_load(name,0);
554 posang = posang/180.0*
M_PI;
559 offsety=(cos(-posang)*dec_off+
560 sin(-posang)*ra_off);
561 xsh_msg(
"ra_off=%f,dec_off=%f,offsety=%f,posang=%f",
562 ra_off,dec_off,offsety,posang);
564 if(offsety!=offset) {
565 cpl_frameset_insert(result,cpl_frame_duplicate(frm));
588 cpl_frameset* set_a=NULL;
589 cpl_frameset* set_b=NULL;
590 cpl_frameset* result=NULL;
591 cpl_propertylist* plist=NULL;
600 cpl_frame* frm_a=NULL;
601 cpl_frame* frm_b=NULL;
602 cpl_frame* frm_tmp=NULL;
605 double mjd_obs_tmp=0;
606 const char* name=NULL;
608 double mjd_obs_ref=-999999.;
611 check(nraws=cpl_frameset_get_size(raws));
613 assure(nraws>=2, CPL_ERROR_ILLEGAL_INPUT,
614 "Too few input frames. At least two NOD positions are required" );
616 noff=cpl_vector_get_size(offset);
617 result=cpl_frameset_new();
618 for(i=0;i<noff;i++) {
619 offsety_a=cpl_vector_get(offset,i);
620 xsh_msg(
"offsety_a=%f",offsety_a);
626 na=cpl_frameset_get_size(set_a);
627 nb=cpl_frameset_get_size(set_b);
631 check(frm_a=cpl_frameset_get_frame(set_a,k));
632 check(name=cpl_frame_get_filename(frm_a));
633 check(plist=cpl_propertylist_load(name,0));
639 mjd_obs_b=mjd_obs_ref;
642 check(frm_tmp=cpl_frameset_get_frame(set_b,j));
643 check(name=cpl_frame_get_filename(frm_tmp));
644 check(plist=cpl_propertylist_load(name,0));
647 if(fabs(mjd_obs_tmp-mjd_obs_a) < fabs(mjd_obs_b-mjd_obs_a)) {
648 mjd_obs_b=mjd_obs_tmp;
654 cpl_frameset_erase_frame(raws,frm_a);
662 cpl_frameset_erase_frame(raws,frm_b);
663 cpl_frameset_insert(result,cpl_frame_duplicate(frm_a));
664 cpl_frameset_insert(result,cpl_frame_duplicate(frm_b));
669 na=cpl_frameset_get_size(set_a);
670 nb=cpl_frameset_get_size(set_b);
672 xsh_msg(
"check again na=%d nb=%d",na,nb);
702 cpl_frameset* obj=NULL;
703 cpl_frameset* sky=NULL;
704 cpl_frameset* result=NULL;
705 cpl_propertylist* plist=NULL;
707 const char * obj_tag=NULL;
708 const char * sky_tag=NULL;
713 cpl_frame* frm_obj=NULL;
714 cpl_frame* frm_sky=NULL;
715 cpl_frame* frm_tmp=NULL;
719 const char* name=NULL;
721 check(nraws=cpl_frameset_get_size(raws));
723 assure(nraws>=2, CPL_ERROR_ILLEGAL_INPUT,
724 "Too few input frames. At least one OBJ and a SKY frame are required");
736 nobj=cpl_frameset_get_size(obj);
737 nsky=cpl_frameset_get_size(sky);
739 assure(nobj>0, CPL_ERROR_ILLEGAL_INPUT,
740 "Too few input obj frames. At least a OBJ frame is required" );
742 assure(nsky>0, CPL_ERROR_ILLEGAL_INPUT,
743 "Too few input sky frames. At least a SKY frame is required" );
745 result=cpl_frameset_new();
746 for(i=0;i<nobj;i++) {
747 check(frm_obj=cpl_frameset_get_frame(obj,i));
748 check(name=cpl_frame_get_filename(frm_obj));
749 check(plist=cpl_propertylist_load(name,0));
754 check(frm_sky=cpl_frameset_get_frame(sky,0));
755 check(name=cpl_frame_get_filename(frm_sky));
756 check(plist=cpl_propertylist_load(name,0));
759 cpl_frameset_insert(result,cpl_frame_duplicate(frm_obj));
761 for(j=1;j<nsky;j++) {
762 check(frm_tmp=cpl_frameset_get_frame(sky,j));
763 check(name=cpl_frame_get_filename(frm_tmp));
764 check(plist=cpl_propertylist_load(name,0));
767 if(fabs(mjdobs_tmp-mjdobs_obj) < fabs(mjdobs_sky-mjdobs_obj)) {
768 mjdobs_sky=mjdobs_tmp;
772 cpl_frameset_insert(result,cpl_frame_duplicate(frm_sky));
795 cpl_frame* rejected=NULL;
796 cpl_frame* frame1=NULL;
797 cpl_frame* frame2=NULL;
798 cpl_frame* frameN=NULL;
799 cpl_propertylist* plist1=NULL;
800 cpl_propertylist* plist2=NULL;
801 cpl_propertylist* plistN=NULL;
802 const char* name1=NULL;
803 const char* name2=NULL;
804 const char* nameN=NULL;
810 check(nraws=cpl_frameset_get_size(raws));
811 if ( (nraws % 2) != 0 ) {
813 check(frame1=cpl_frameset_get_frame(raws,0));
814 check(frame2=cpl_frameset_get_frame(raws,1));
815 check(frameN=cpl_frameset_get_frame(raws,nraws-1));
816 check(name1=cpl_frame_get_filename(frame1));
817 check(name2=cpl_frame_get_filename(frame2));
818 check(nameN=cpl_frame_get_filename(frameN));
819 check(plist1=cpl_propertylist_load(name1,0));
820 check(plist2=cpl_propertylist_load(name2,0));
821 check(plistN=cpl_propertylist_load(nameN,0));
830 if(yshift1 == yshiftN) {
832 if ( fabs(yshift1-yshift2) <= DBL_MIN ) {
835 cpl_frame_get_filename(frameN));
836 cpl_frameset_erase_frame(raws,frameN);
841 cpl_frame_get_filename(frame1));
842 cpl_frameset_erase_frame(raws,frame1);
847 if (fabs(yshift1 - yshift2) <= DBL_MIN) {
850 cpl_frame_get_filename(frame1));
851 cpl_frameset_erase_frame(raws,frame1);
856 cpl_frame_get_filename(frameN));
857 cpl_frameset_erase_frame(raws,frameN);
878 if(cpl_error_get_code() != CPL_ERROR_NONE) {
903 cpl_frame_group group,
904 cpl_frame_level level,
908 check(cpl_frame_set_filename(*frame,fname));
909 check(cpl_frame_set_tag(*frame,tag));
910 check(cpl_frame_set_type(*frame,type));
911 check(cpl_frame_set_group(*frame,group));
912 check(cpl_frame_set_level(*frame,level));
931 cpl_frame_group group,cpl_frame_level level)
933 cpl_frame* frame=NULL;
934 check(frame=cpl_frame_new());
963 if ((fo=fopen(filename,
"r"))==NULL) {
986 cpl_frameset *subset = NULL;
991 assure( frames != NULL, CPL_ERROR_ILLEGAL_INPUT,
"Null frameset" );
992 assure( tag != NULL, CPL_ERROR_ILLEGAL_INPUT,
"Null tag" );
994 subset = cpl_frameset_new();
996 for (f = cpl_frameset_find_const(frames, tag);
998 f = cpl_frameset_find_const(frames, NULL)) {
1000 cpl_frameset_insert(subset, cpl_frame_duplicate(f));
1017 cpl_frame* frm_tmp=NULL;
1018 cpl_frame* frm_dup=NULL;
1020 passure(set1 != NULL,
"Wrong input set");
1022 cpl_frameset_iterator* it = cpl_frameset_iterator_new(set2);
1023 frm_tmp = cpl_frameset_iterator_get(it);
1025 while (frm_tmp != NULL)
1027 frm_dup=cpl_frame_duplicate(frm_tmp);
1028 cpl_frameset_insert(set1,frm_dup);
1029 cpl_frameset_iterator_advance(it, 1);
1030 frm_tmp = cpl_frameset_iterator_get(it);
1033 cpl_frameset_iterator_delete(it);
1035 return cpl_error_get_code();
1048 cpl_frame * cur_frame = NULL;
1053 assure (set != NULL, CPL_ERROR_NULL_INPUT,
"Null frame set");
1054 assure (!cpl_frameset_is_empty(set),CPL_ERROR_ILLEGAL_INPUT,
1059 nfrm=cpl_frameset_get_size(set);
1061 for (i = 0; i<nfrm; i++) {
1062 const char *tag = NULL;
1063 cur_frame=cpl_frameset_get_frame(set,i);
1064 check(tag = cpl_frame_get_tag (cur_frame));
1068 check(cpl_frame_set_group (cur_frame, CPL_FRAME_GROUP_NONE));
1072 check(cpl_frame_set_group (cur_frame, CPL_FRAME_GROUP_RAW));
1076 check(cpl_frame_set_group (cur_frame, CPL_FRAME_GROUP_CALIB));
1081 check(cpl_error_set(cpl_func,CPL_ERROR_ILLEGAL_INPUT ));
1089 "invalid tag %s in file %s",
1090 tag, cpl_frame_get_filename (cur_frame));
1094 CPL_ERROR_TYPE_MISMATCH,
"Arm is undefined");
1096 xsh_msg(
"Arm %s, Mode %s Nb Orders %d, min: %d, max: %d",
1102 if (cpl_error_get_code () != CPL_ERROR_NONE){
1119 cpl_frame *cur_frame = NULL;
1123 nfrm=cpl_frameset_get_size(input);
1124 for (i=0; i < nfrm; i++) {
1125 cur_frame=cpl_frameset_get_frame(input,i);
1127 if (cpl_frame_get_group (cur_frame) == CPL_FRAME_GROUP_RAW) {
1128 cpl_frameset_insert (raws, cpl_frame_duplicate(cur_frame));
1132return cpl_error_get_code();
1146 cpl_frame *cur_frame = NULL;
1150 nfrm=cpl_frameset_get_size(input);
1152 for (i = 0; i< nfrm; i++) {
1153 cur_frame=cpl_frameset_get_frame(input,i);
1155 if (cpl_frame_get_group (cur_frame) == CPL_FRAME_GROUP_CALIB) {
1156 cpl_frameset_insert (calib, cpl_frame_duplicate(cur_frame));
1160return cpl_error_get_code();
1175 cpl_frame *cur_frame = NULL;
1180 nfrm=cpl_frameset_get_size(input);
1181 for (i=0;i<nfrm; i++) {
1182 cur_frame=cpl_frameset_get_frame(input,i);
1184 if (cpl_frame_get_group (cur_frame) == CPL_FRAME_GROUP_PRODUCT) {
1185 cpl_frameset_insert (pros, cpl_frame_duplicate(cur_frame));
1189 return cpl_error_get_code();
1203 cpl_frameset * calib)
1205 cpl_frame *cur_frame = NULL;
1209 nfrm=cpl_frameset_get_size(input);
1211 for (i = 0; i < nfrm; i++) {
1212 cur_frame=cpl_frameset_get_frame(input,i);
1214 if (cpl_frame_get_group (cur_frame) == CPL_FRAME_GROUP_RAW) {
1216 cpl_frameset_insert (raws, cpl_frame_duplicate(cur_frame));
1219 else if (cpl_frame_get_group (cur_frame) == CPL_FRAME_GROUP_CALIB) {
1220 cpl_frameset_insert (calib, cpl_frame_duplicate(cur_frame));
1225 cpl_frame_get_filename (cur_frame));
1245 cpl_frame* cur_frame = NULL;
1246 cpl_frame* temp =NULL;
1258 nfrm=cpl_frameset_get_size(input);
1260 for (i = 0; i < nfrm; i++) {
1261 const char* tag = NULL;
1262 cur_frame=cpl_frameset_get_frame(input,i);
1263 check(tag = cpl_frame_get_tag(cur_frame));
1265 if ( strstr(tag,
"D2") != NULL) {
1266 check(temp = cpl_frame_duplicate(cur_frame));
1267 check(cpl_frameset_insert(*d2, temp));
1270 else if ( strstr(tag,
"QTH") != NULL) {
1271 check(temp = cpl_frame_duplicate(cur_frame));
1272 check(cpl_frameset_insert(*qth, temp));
1277 cpl_frame_get_filename (cur_frame));
1282 if (cpl_error_get_code() != CPL_ERROR_NONE){
1300 cpl_frame* cur_frame = NULL;
1301 cpl_frame* temp =NULL;
1312 nfrm=cpl_frameset_get_size(input);
1314 for (i = 0; i< nfrm ; i++) {
1315 const char* tag = NULL;
1316 cur_frame = cpl_frameset_get_frame(input,i);
1317 check(tag = cpl_frame_get_tag(cur_frame));
1319 if ( strstr(tag,
"ON") != NULL) {
1320 check(temp = cpl_frame_duplicate(cur_frame));
1321 check(cpl_frameset_insert(*on, temp));
1324 else if ( strstr(tag,
"OFF") != NULL) {
1325 check(temp = cpl_frame_duplicate(cur_frame));
1326 check(cpl_frameset_insert(*off, temp));
1331 cpl_frame_get_filename (cur_frame));
1336 if (cpl_error_get_code() != CPL_ERROR_NONE){
1358 const char * object_tag,
1359 const char * sky_tag,
1360 cpl_frameset **
object,
1361 cpl_frameset ** sky)
1363 cpl_frame* cur_frame = NULL;
1364 cpl_frame* temp =NULL;
1365 int nobj = 0, nsky = 0 ;
1374 *
object=cpl_frameset_new();
1375 *sky=cpl_frameset_new();
1376 nfrm=cpl_frameset_get_size(input);
1378 for (i = 0; i < nfrm; i++ ) {
1379 const char* tag = NULL;
1380 cur_frame=cpl_frameset_get_frame(input,i);
1382 check(tag = cpl_frame_get_tag(cur_frame));
1386 if ( strstr(tag, object_tag) != NULL) {
1387 check(temp = cpl_frame_duplicate(cur_frame));
1388 check(cpl_frameset_insert(*
object, temp));
1392 else if ( strstr(tag, sky_tag) != NULL) {
1393 check(temp = cpl_frame_duplicate(cur_frame));
1394 check(cpl_frameset_insert(*sky, temp));
1400 cpl_frame_get_filename (cur_frame));
1410 if (cpl_error_get_code() != CPL_ERROR_NONE){
1429 const cpl_frame* frame)
1433 const char* pro_catg=NULL;
1435 if(pcatg_prefix==NULL) {
1436 pro_catg = cpl_frame_get_tag (frame);
1453 char* final_name=NULL;
1460 final_prefix,
"_", date,
".fits",
"" ) ;
1461 }
else if ( strstr( final_prefix,
".fits" ) == NULL ) {
1490 for( i=0; i<
size; i++){
1491 if ( strstr( tag, tag_list[i])!=NULL){
1512 cpl_frame *cur_frame = NULL;
1519 cpl_frameset_iterator* it = cpl_frameset_iterator_new(set);
1520 cur_frame = cpl_frameset_iterator_get(it);
1522 while(cur_frame != NULL){
1523 const char* ftag = NULL;
1525 check( ftag = cpl_frame_get_tag( cur_frame));
1527 cpl_frame *del_frame = NULL;
1529 del_frame = cur_frame;
1530 cpl_frameset_iterator_advance(it, 1);
1531 cur_frame = cpl_frameset_iterator_get(it);
1533 check( cpl_frameset_erase_frame( set, del_frame));
1536 cpl_frameset_iterator_advance(it, 1);
1537 cur_frame = cpl_frameset_iterator_get(it);
1540 cpl_frameset_iterator_delete(it);
1558 cpl_frameset* set=NULL;
1559 cpl_frame* current=NULL;
1560 cpl_frame* found=NULL;
1566 check(sz=cpl_frameset_get_size(frameset));
1568 check(set=cpl_frameset_new());
1570 check( current = cpl_frameset_get_frame(frameset, i));
1571 sprintf(name,
"%s_PRE_%d.fits", prefix, i);
1572 sprintf(tag,
"%s_PRE_%d", prefix, i);
1575 check(found=cpl_frame_duplicate(current));
1576 check( cpl_frame_set_filename(found, name) );
1577 cpl_frameset_insert(set,found);
1597 cpl_frame *cur_frame = NULL;
1601 nfrm=cpl_frameset_get_size(set);
1603 for (i = 0; i < nfrm; i++) {
1604 cur_frame = cpl_frameset_get_frame(set,i);
1605 if (strstr (cpl_frame_get_tag (cur_frame),
"BADPIXEL_MAP")) {
1623 cpl_frame *cur_frame = NULL;
1627 nfrm=cpl_frameset_get_size(set);
1629 for (i = 0; i < nfrm; i++) {
1630 cur_frame=cpl_frameset_get_frame(set,i);
1647 cpl_frame *cur_frame = NULL;
1651 nfrm=cpl_frameset_get_size(set);
1653 for (i=0;i<nfrm; i++) {
1654 cur_frame=cpl_frameset_get_frame(set,i);
1655 if (strstr (cpl_frame_get_tag (cur_frame),
"OFF")) {
1671 cpl_frame *cur_frame = NULL;
1674 nfrm=cpl_frameset_get_size(set);
1676 for (i = 0; i< nfrm; i++) {
1677 cur_frame=cpl_frameset_get_frame(set,i);
1678 if (strstr (cpl_frame_get_tag (cur_frame),
"ON")) {
1695 cpl_frame *cur_frame = NULL;
1696 const char* tag = NULL;
1701 assure (raws != NULL, CPL_ERROR_NULL_INPUT,
"Null frameset");
1702 assure (flat != NULL, CPL_ERROR_NULL_INPUT,
"Null frameset");
1705 nfrm=cpl_frameset_get_size(raws);
1707 for (i = 0; i < nfrm; i++)
1709 cur_frame=cpl_frameset_get_frame(raws,i);
1710 tag = cpl_frame_get_tag (cur_frame);
1711 if (strstr(tag,
"FLAT")!=NULL)
1712 cpl_frameset_insert (flat, cur_frame);
1738 const char *pro_catg)
1740 if (context != NULL) {
1742 return xsh_stringcat_6 (context,
"-", caller_id,
"-", pro_catg,
".fits");
1762 cpl_frameset * frameset,
1763 const cpl_parameterlist * parameters,
1764 const char *recipe_id,
1766 const char *final_prefix ,
1769 cpl_propertylist *primary_header = NULL;
1770 cpl_propertylist *tbl_header = NULL;
1772 const char *pro_catg = NULL;
1773 cpl_frame* product_frame = NULL;
1775 cpl_table *table = NULL ;
1776 cpl_image *image = NULL ;
1777 cpl_imagelist *imagelist = NULL ;
1780 const char *fname = NULL;
1781 char *final_name = NULL ;
1793 check(pro_catg = cpl_frame_get_tag (frame));
1797 check(fname = cpl_frame_get_filename( frame ));
1798 check(primary_header = cpl_propertylist_load( fname, 0 ));
1800 if(strcmp(type,
"imagelist") == 0) {
1801 check(imagelist = cpl_imagelist_load( fname, CPL_TYPE_FLOAT, 0 ));
1802 }
else if(strcmp(type,
"image") == 0) {
1803 check(image = cpl_image_load( fname, CPL_TYPE_FLOAT, 0,0 ));
1804 }
else if(strcmp(type,
"table") == 0) {
1805 check(table = cpl_table_load( fname, 1,0 ));
1811 check( cpl_frame_set_group( frame, CPL_FRAME_GROUP_PRODUCT));
1812 check_msg (cpl_dfs_setup_product_header ( primary_header,
1813 frame,frameset,parameters,
1817 "Problem in the product DFS-compliance");
1827 if(strcmp(type,
"imagelist") == 0) {
1828 cpl_imagelist_save(imagelist, final_name, CPL_BPP_IEEE_FLOAT,
1829 primary_header,CPL_IO_DEFAULT ) ;
1830 }
else if(strcmp(type,
"image") == 0) {
1831 cpl_image_save(image, final_name, CPL_BPP_IEEE_FLOAT,
1832 primary_header,CPL_IO_DEFAULT ) ;
1833 }
else if(strcmp(type,
"table") == 0) {
1834 check(cpl_table_save( table, primary_header, tbl_header,
1835 final_name, extension ));
1854 if(strcmp(type,
"imagelist") == 0) {
1856 CPL_FRAME_TYPE_IMAGE,
1857 CPL_FRAME_GROUP_PRODUCT,
1858 CPL_FRAME_LEVEL_FINAL));
1859 }
else if(strcmp(type,
"image") == 0) {
1861 CPL_FRAME_TYPE_IMAGE,
1862 CPL_FRAME_GROUP_PRODUCT,
1863 CPL_FRAME_LEVEL_FINAL));
1864 }
else if(strcmp(type,
"table") == 0) {
1866 CPL_FRAME_TYPE_TABLE,
1867 CPL_FRAME_GROUP_PRODUCT,
1868 CPL_FRAME_LEVEL_FINAL));
1872 check(cpl_frameset_insert(frameset, product_frame));
1896 cpl_frameset *frameset,
1897 const cpl_parameterlist *parameters,
1898 const char *recipe_id,
1900 const char * final_prefix)
1903 cpl_vector *vect = NULL;
1904 cpl_propertylist *primary_header = NULL;
1905 const char *pro_catg =
"";
1906 cpl_frame* product_frame = NULL;
1907 const char *fname = NULL;
1908 char *final_name = NULL ;
1921 check(pro_catg = cpl_frame_get_tag (frame));
1925 check( fname = cpl_frame_get_filename( frame));
1926 check( primary_header = cpl_propertylist_load( fname, 0));
1927 check( vect = cpl_vector_load( fname, 0));
1930 check( cpl_frame_set_group( frame, CPL_FRAME_GROUP_PRODUCT));
1931 check_msg (cpl_dfs_setup_product_header ( primary_header,
1932 frame,frameset,parameters,
1936 "Problem in the product DFS-compliance");
1944 primary_header, CPL_IO_CREATE));
1948 CPL_FRAME_TYPE_IMAGE,
1949 CPL_FRAME_GROUP_PRODUCT,
1950 CPL_FRAME_LEVEL_FINAL));
1952 check(cpl_frameset_insert(frameset, product_frame));
1956 if (cpl_error_get_code () != CPL_ERROR_NONE) {
1958 product_frame = NULL;
1982 cpl_propertylist* keywords = NULL;
1983 cpl_frameset_iterator* iter = NULL;
1986 iter = cpl_frameset_iterator_new(usedframes);
1987 const cpl_frame* frame = cpl_frameset_iterator_get_const(iter);
1988 while (frame != NULL) {
1989 if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_RAW) {
1991 const char* filename;
1992 check(filename = cpl_frame_get_filename(frame));
1993 check(keywords = cpl_propertylist_load(filename, 0));
2001 check(nditskip = cpl_propertylist_get_int(keywords,
2003 if (nditskip == 0) {
2007 " to handle this case so will not set '%s'. This keyword must"
2017 const char* dpr_type = cpl_propertylist_get_string(keywords,
XSH_DPR_TYPE) ;
2019 int dpr_is_not_obj = strcmp(dpr_type,
"OBJECT") ;
2020 int dpr_is_not_stdtell = strcmp(dpr_type,
"STD,TELLURIC") ;
2023 if (!dpr_is_not_obj || !dpr_is_not_stdtell) {
2030 cpl_propertylist_delete(keywords);
2034 cpl_errorstate status = cpl_errorstate_get();
2035 cpl_frameset_iterator_advance(iter, 1);
2036 if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) {
2037 cpl_errorstate_set(status);
2039 frame = cpl_frameset_iterator_get_const(iter);
2042 cpl_frameset_iterator_delete(iter);
2043 cpl_propertylist_delete(keywords);
2049 cpl_frameset_iterator_delete(iter);
2050 cpl_propertylist_delete(keywords);
2068 cpl_frameset *frameset,
2069 const cpl_parameterlist *parameters,
2070 const char *recipe_id,
2072 cpl_frame ** result_frame,
2073 cpl_propertylist* qclist)
2076 const char *pro_catg =
"";
2078 cpl_frame *product_frame = NULL;
2079 char product_id[256];
2080 char* product_name = NULL;
2093 check( pro_catg = cpl_frame_get_tag (frame));
2095 assure( pro_catg != NULL, CPL_ERROR_NULL_INPUT,
2096 "Frame tag has not been set");
2103 cpl_frame_set_group( frame, CPL_FRAME_GROUP_PRODUCT);
2105 frame, frameset, parameters, recipe_id, instr->
pipeline_id,
2111 if(cpl_propertylist_has(qclist,
"ESO QC CURVE 0") &&
2112 cpl_propertylist_has(qclist,
"ESO QC CURVE 1") &&
2113 cpl_propertylist_has(qclist,
"ESO QC CURVE X")){
2114 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC CURVE 0",cpl_propertylist_get_double(qclist,
"ESO QC CURVE 0"));
2115 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC CURVE 1",cpl_propertylist_get_double(qclist,
"ESO QC CURVE 1"));
2116 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC CURVE X",cpl_propertylist_get_double(qclist,
"ESO QC CURVE X"));
2118 if(cpl_propertylist_has(qclist,
"ESO QC RESP SPEC A") &&
2119 cpl_propertylist_has(qclist,
"ESO QC RESP SPEC B") &&
2120 cpl_propertylist_has(qclist,
"ESO QC RESP SPEC DA") &&
2121 cpl_propertylist_has(qclist,
"ESO QC RESP SPEC DB")){
2122 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC A",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC A"));
2123 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC B",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC B"));
2124 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC DA",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC DA"));
2125 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC DB",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC DB"));
2127 if(cpl_propertylist_has(qclist,
"ESO QC RESP SPEC A QTH") &&
2128 cpl_propertylist_has(qclist,
"ESO QC RESP SPEC B QTH") &&
2129 cpl_propertylist_has(qclist,
"ESO QC RESP SPEC DA QTH") &&
2130 cpl_propertylist_has(qclist,
"ESO QC RESP SPEC DB QTH")){
2131 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC A QTH",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC A QTH"));
2132 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC B QTH",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC B QTH"));
2133 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC DA QTH",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC DA QTH"));
2134 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC DB QTH",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC DB QTH"));
2136 if(cpl_propertylist_has(qclist,
"ESO QC RESP SPEC A D2") &&
2137 cpl_propertylist_has(qclist,
"ESO QC RESP SPEC B D2") &&
2138 cpl_propertylist_has(qclist,
"ESO QC RESP SPEC DA D2") &&
2139 cpl_propertylist_has(qclist,
"ESO QC RESP SPEC DB D2")){
2140 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC A D2",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC A D2"));
2141 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC B D2",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC B D2"));
2142 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC DA D2",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC DA D2"));
2143 cpl_propertylist_update_double(spectrum->
flux_header,
"ESO QC RESP SPEC DB D2",cpl_propertylist_get_double(qclist,
"ESO QC RESP SPEC DB D2"));
2147 if(strstr(pro_catg,
XSH_MERGE1D) != NULL && strstr(pro_catg,
"FLUX") == NULL && qclist != NULL){
2148 cpl_image* flux = cpl_image_duplicate(spectrum->
flux);
2149 cpl_image* errs = cpl_image_duplicate(spectrum->
errs);
2150 cpl_propertylist_append_double(qclist,
"ESO QC MEAN RED",cpl_image_get_mean(flux));
2151 cpl_propertylist_append_double(qclist,
"ESO QC RMS RED",cpl_image_get_stdev(flux));
2152 cpl_image* div = cpl_image_duplicate(flux);
2154 cpl_image_divide(div,errs);
2155 cpl_propertylist_append_double(qclist,
"ESO QC MEAN S2N",cpl_image_get_mean(div));
2156 cpl_image_delete(flux);
2157 cpl_image_delete(errs);
2158 cpl_image_delete(div);
2163 if(strstr(pro_catg,
"SCI_SLIT_MERGE2D") || strstr(pro_catg,
"TELL_SLIT_MERGE2D"))
2170 strstr(recipe_id,
"xsh_respon") != NULL ||
2171 strstr(recipe_id,
"xsh_scired") != NULL ||
2172 strstr(recipe_id,
"xsh_util_ifu") != NULL ) {
2224 cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE);
2225 cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT);
2226 cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL);
2227 cpl_frame_set_tag( product_frame, pro_catg);
2228 cpl_frameset_insert( frameset, product_frame);
2231 if (result_frame != NULL) {
2232 *result_frame = cpl_frame_duplicate(product_frame);
2236 if (cpl_error_get_code () != CPL_ERROR_NONE) {
2238 product_frame = NULL;
2261 cpl_frameset *frameset,
2262 const cpl_parameterlist *parameters,
2263 const char *recipe_id,
2265 cpl_frame ** result_frame)
2268 const char *pro_catg =
"";
2270 cpl_frame *product_frame = NULL;
2271 char product_id[256];
2272 char* product_name = NULL;
2277 cpl_vector* vec_data=NULL;
2278 cpl_vector* vec_errs=NULL;
2279 cpl_vector* vec_qual=NULL;
2280 const char *name_s = NULL;
2281 cpl_propertylist* h_data=NULL;
2282 cpl_propertylist* h_errs=NULL;
2283 cpl_propertylist* h_qual=NULL;
2284 char *final_name = NULL ;
2294 check( pro_catg = cpl_frame_get_tag (frame));
2296 assure( pro_catg != NULL, CPL_ERROR_NULL_INPUT,
2297 "Frame tag has not been set");
2316 xsh_msg(
"Final product name: %s", final_name ) ;
2317 name_s=cpl_frame_get_filename(frame);
2318 int next=cpl_frame_get_nextensions(frame);
2320 if(strcmp(name_s,final_name) == 0) {
2321 sprintf(cmd,
"mv %s tmp_spc.fits",name_s);
2323 name_s=
"tmp_spc.fits";
2327 cpl_propertylist* primary_header;
2328 check( primary_header = cpl_propertylist_load( name_s, 0));
2330 strstr(recipe_id,
"xsh_respon") != NULL ||
2331 strstr(recipe_id,
"xsh_scired") != NULL ||
2332 strstr(recipe_id,
"xsh_util_ifu") != NULL ) {
2346 cpl_propertylist_append_double(primary_header,
"TEXPTIME",
exptime) ;
2358 "FLUX",
"ERRS",
"QUAL",0);
2363 for(
int i=0;i<next;i+=3) {
2364 vec_data=cpl_vector_load(name_s,i);
2365 vec_errs=cpl_vector_load(name_s,i+1);
2366 vec_qual=cpl_vector_load(name_s,i+2);
2368 check(h_data=cpl_propertylist_load(name_s,i));
2369 check(h_errs=cpl_propertylist_load(name_s,i+1));
2370 check(h_qual=cpl_propertylist_load(name_s,i+2));
2385 cpl_dfs_setup_product_header(primary_header,frame, frameset, parameters,
2411 product_frame=cpl_frame_new();
2413 cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE);
2414 cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT);
2415 cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL);
2416 cpl_frame_set_tag( product_frame, pro_catg);
2417 cpl_frame_set_filename( product_frame, product_name);
2419 cpl_frameset_insert( frameset, product_frame);
2422 if (result_frame != NULL) {
2423 *result_frame = cpl_frame_duplicate(product_frame);
2427 if (cpl_error_get_code () != CPL_ERROR_NONE) {
2429 product_frame = NULL;
2466 cpl_frameset * frameset,
2467 const cpl_parameterlist *parameters,
2468 const char *recipe_id,
2470 cpl_propertylist* qclist)
2472 const char *pro_catg =
"";
2474 cpl_frame* product_frame = NULL;
2475 char product_id[256];
2476 char* product_name = NULL;
2480 cpl_propertylist* plist=NULL;
2493 check( pro_catg = cpl_frame_get_tag (frame));
2495 assure( pro_catg != NULL, CPL_ERROR_NULL_INPUT,
2496 "Frame tag has not been set");
2508 if(qclist != NULL && cpl_propertylist_get_size(qclist) > 0){
2509 cpl_propertylist_append(product_pre->
data_header,qclist);
2512 cpl_frame_set_group( frame, CPL_FRAME_GROUP_PRODUCT);
2514 frame, frameset, parameters, recipe_id, instr->
pipeline_id,
2519 strstr(recipe_id,
"xsh_respon") != NULL ||
2520 strstr(recipe_id,
"xsh_scired") != NULL ||
2521 strstr(recipe_id,
"xsh_util_ifu") != NULL ) {
2545 if(strstr(pro_catg,
"SCI_SLIT_MERGE2D") || strstr(pro_catg,
"TELL_SLIT_MERGE2D"))
2561 "FLUX",
"ERRS",
"QUAL",0);
2564 "FLUX",
"ERRS",
"QUAL",1);
2567 "FLUX",
"ERRS",
"QUAL",2);
2592 cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE);
2593 cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT);
2594 cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL);
2595 cpl_frame_set_tag( product_frame, pro_catg);
2596 cpl_frameset_insert( frameset, product_frame);
2600 if (cpl_error_get_code () != CPL_ERROR_NONE) {
2602 product_frame = NULL;
2628 cpl_frameset * frameset,
2629 const cpl_parameterlist *parameters,
2630 const char *recipe_id,
2633 const char * pro_catg =
"";
2635 cpl_frame * product_frame = NULL;
2636 char product_id[256];
2637 char * product_name = NULL;
2649 check( pro_catg = cpl_frame_get_tag (frame));
2651 assure( pro_catg != NULL, CPL_ERROR_NULL_INPUT,
2652 "Frame tag has not been set");
2659 cpl_frame_set_group( frame, CPL_FRAME_GROUP_PRODUCT);
2661 frame, frameset, parameters,
2686 cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE);
2687 cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT);
2688 cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL);
2689 cpl_frame_set_tag( product_frame, pro_catg);
2690 cpl_frameset_insert( frameset, product_frame);
2694 if (cpl_error_get_code () != CPL_ERROR_NONE) {
2696 product_frame = NULL;
2717 cpl_frameset * frameset,
2718 const cpl_parameterlist * parameters,
2719 const char *recipe_id,
2721 const char *final_prefix )
2723 cpl_propertylist *primary_header = NULL;
2724 const char* pro_catg=NULL;
2725 cpl_frame* product_frame = NULL;
2726 cpl_image *image = NULL ;
2727 const char *fname = NULL;
2728 char *final_name = NULL ;
2748 check(fname = cpl_frame_get_filename( frame ));
2749 check(primary_header = cpl_propertylist_load( fname, 0 ));
2750 check(image = cpl_image_load( fname, CPL_TYPE_INT, 0, 0 ));
2753 check( cpl_frame_set_group( frame, CPL_FRAME_GROUP_PRODUCT));
2754 check_msg (cpl_dfs_setup_product_header ( primary_header,
2755 frame,frameset,parameters,
2759 "Problem in the product DFS-compliance");
2767 cpl_image_save( image, final_name, CPL_BPP_32_SIGNED, primary_header,
2781 CPL_FRAME_TYPE_IMAGE,
2782 CPL_FRAME_GROUP_PRODUCT,
2783 CPL_FRAME_LEVEL_FINAL));
2797 check(cpl_frameset_insert(frameset, product_frame));
2805 if(final_prefix!=NULL) {
2826 cpl_frameset *frameset,
2827 const cpl_parameterlist *parameters,
2828 const char *recipe_id,
2830 const char *final_prefix)
2832 cpl_propertylist *primary_header = NULL;
2833 const char *pro_catg = NULL;
2834 cpl_frame* product_frame = NULL;
2835 const char *fname = NULL;
2836 char *final_name = NULL ;
2845 cpl_imagelist* ext_iml=NULL;
2846 cpl_propertylist* ext_header=NULL;
2861 check(fname = cpl_frame_get_filename( frame ));
2862 nbext = cpl_frame_get_nextensions( frame);
2863 check(primary_header = cpl_propertylist_load( fname, 0 ));
2864 check(ext_iml = cpl_imagelist_load( fname, CPL_TYPE_FLOAT, 0 ));
2873 check( cpl_frame_set_group( frame, CPL_FRAME_GROUP_PRODUCT));
2874 check_msg ( cpl_dfs_setup_product_header ( primary_header,
2875 frame,frameset,parameters,
2879 "Problem in the product DFS-compliance");
2883 xsh_msg(
"Final product name: %s", final_name ) ;
2885 if(strcmp(fname,final_name) == 0) {
2886 sprintf(cmd,
"mv %s tmp_ima.fits",fname);
2888 fname=
"tmp_ima.fits";
2894 check(cpl_imagelist_save(ext_iml, final_name, CPL_BPP_IEEE_FLOAT,
2895 primary_header,CPL_IO_DEFAULT));
2897 for( i = 0 ; i<=nbext ; i++ ) {
2900 check(ext_iml = cpl_imagelist_load( fname, CPL_TYPE_FLOAT, i ));
2901 check(ext_header = cpl_propertylist_load( fname ,i));
2904 extension = CPL_IO_DEFAULT ;
2905 check(cpl_imagelist_save(ext_iml, final_name, CPL_BPP_IEEE_FLOAT,
2906 primary_header,extension));
2909 extension = CPL_IO_EXTEND ;
2910 check(cpl_imagelist_save(ext_iml, final_name, CPL_BPP_IEEE_FLOAT,
2911 ext_header,extension));
2923 CPL_FRAME_TYPE_IMAGE,
2924 CPL_FRAME_GROUP_PRODUCT,
2925 CPL_FRAME_LEVEL_FINAL));
2928 strstr(recipe_id,
"xsh_respon") != NULL ||
2929 strstr(recipe_id,
"xsh_scired") != NULL ||
2930 strstr(recipe_id,
"xsh_util_ifu") != NULL ) {
2934 check(cpl_frameset_insert(frameset, product_frame));
2941 if(final_prefix!=NULL) {
2966 cpl_frameset *frameset,
2967 const cpl_parameterlist *parameters,
2968 const char *recipe_id,
2970 const char *final_prefix)
2972 cpl_propertylist *primary_header = NULL;
2973 const char *pro_catg = NULL;
2974 cpl_frame* product_frame = NULL;
2975 cpl_image *image = NULL ;
2976 const char *fname = NULL;
2977 char *final_name = NULL ;
2997 check( fname = cpl_frame_get_filename( frame));
2998 nbext = cpl_frame_get_nextensions( frame);
3000 check( primary_header = cpl_propertylist_load( fname, 0));
3001 check( image = cpl_image_load( fname, CPL_TYPE_FLOAT, 0, 0));
3010 check( cpl_frame_set_group( frame, CPL_FRAME_GROUP_PRODUCT));
3011 check_msg (cpl_dfs_setup_product_header ( primary_header,
3012 frame,frameset,parameters,
3016 "Problem in the product DFS-compliance");
3018 xsh_msg(
"recipe_id=%s",recipe_id);
3020 strstr(recipe_id,
"xsh_respon") != NULL ||
3021 strstr(recipe_id,
"xsh_scired") != NULL ||
3022 strstr(recipe_id,
"xsh_util_ifu") != NULL ) {
3034 cpl_propertylist_append_double(primary_header,
"TEXPTIME",
exptime) ;
3047 xsh_msg(
"Final product name: %s", final_name ) ;
3049 if(strcmp(fname,final_name) == 0) {
3050 sprintf(cmd,
"mv %s tmp_ima.fits",fname);
3052 fname=
"tmp_ima.fits";
3058 "FLUX",
"ERRS",
"QUAL",0);
3060 check(cpl_image_save( image, final_name, CPL_BPP_IEEE_FLOAT, primary_header,
3065 for( i = 0 ; i<=nbext ; i++ ) {
3067 cpl_image* ext_img=NULL;
3068 cpl_propertylist* ext_header=NULL;
3070 check( ext_img = cpl_image_load( fname, CPL_TYPE_FLOAT,0, i));
3071 check( ext_header = cpl_propertylist_load( fname ,i));
3078 extension = CPL_IO_DEFAULT ;
3082 extension = CPL_IO_EXTEND ;
3084 "FLUX",
"ERRS",
"QUAL",i));
3085 check(cpl_propertylist_erase_regexp(ext_header,
3086 "^(ARCFILE|ORIGFILE|CHECKSUM|DATASUM|COMMENT)$", CPL_FALSE));
3087 check(cpl_image_save( ext_img, final_name, CPL_BPP_IEEE_FLOAT,ext_header,
3111 CPL_FRAME_TYPE_IMAGE,
3112 CPL_FRAME_GROUP_PRODUCT,
3113 CPL_FRAME_LEVEL_FINAL));
3115 check(cpl_frameset_insert(frameset, product_frame));
3116 cpl_msg_info(__func__,
"Adding XSH product %s",
3122 if(final_prefix!=NULL) {
3147 cpl_frameset *frameset,
3148 const cpl_parameterlist * parameters,
3149 const char *recipe_id,
3151 const char *final_prefix)
3153 cpl_propertylist *primary_header = NULL;
3154 cpl_propertylist *tbl_header = NULL;
3155 const char *pro_catg =NULL;
3156 cpl_frame* product_frame = NULL;
3157 cpl_table * table = NULL ;
3158 const char *fname = NULL;
3159 char *product_id = NULL;
3160 char *product_name = NULL ;
3161 char *tmp_name = NULL ;
3178 check( fname = cpl_frame_get_filename( frame));
3179 check( primary_header = cpl_propertylist_load( fname, 0));
3181 check( tbl_header = cpl_propertylist_load( fname, 1));
3183 nbext = cpl_frame_get_nextensions( frame);
3186 check( cpl_frame_set_group (frame, CPL_FRAME_GROUP_PRODUCT));
3187 check( cpl_dfs_setup_product_header ( primary_header,
3193 strstr(recipe_id,
"xsh_respon") != NULL ||
3194 strstr(recipe_id,
"xsh_scired") != NULL ||
3195 strstr(recipe_id,
"xsh_util_ifu") != NULL ) {
3204 for( i = 0 ; i<nbext ; i++ ) {
3206 cpl_table *tbl_ext = NULL;
3207 cpl_propertylist *tbl_ext_header = NULL;
3211 check( tbl_ext = cpl_table_load( fname, i+1, 0));
3212 check( tbl_ext_header = cpl_propertylist_load( fname, i+1));
3214 if ( i == 0 ) extension = CPL_IO_DEFAULT ;
3215 else extension = CPL_IO_EXTEND ;
3216 check(cpl_table_save( tbl_ext, primary_header, tbl_ext_header,
3217 tmp_name, extension));
3227 CPL_FRAME_TYPE_TABLE,
3228 CPL_FRAME_GROUP_PRODUCT,
3229 CPL_FRAME_LEVEL_FINAL));
3231 cpl_frameset_insert(frameset, product_frame);
3235 if(final_prefix!=NULL) {
3264 const char *tags[] = {
3321 const char *tags[2] ={NULL,NULL};
3322 cpl_frame* result = NULL;
3352 cpl_frame* result = NULL;
3376 char* composed_tag=NULL;
3378 int len = strlen(tag);
3380 if(tag[len-1]==
'_') {
3381 composed_tag=cpl_sprintf(
"%s%s",tag,arm);
3383 composed_tag=cpl_sprintf(
"%s%s%s",tag,
"_",arm);
3387 return composed_tag;
3406 const char *tags[2];
3428 const char *tags[2];
3447 const char* tags[2] = {NULL, NULL};
3448 cpl_frame* result = NULL;
3470 const char *tags[2] = {NULL, NULL};
3471 cpl_frame* result = NULL;
3492 const char *tags[2] = {NULL, NULL};
3493 cpl_frame* result = NULL;
3522 const char *tags[2] = {NULL, NULL};
3523 cpl_frame* result = NULL;
3547 const char *tags[2] = {NULL, NULL};
3548 cpl_frame* result = NULL;
3572 const char *tags[2] = {NULL, NULL};
3573 cpl_frame* result = NULL;
3597 const char *tags[3] = {NULL, NULL};
3598 cpl_frame* result = NULL;
3609 xsh_msg(
"Use order tab: %s", cpl_frame_get_tag( result));
3627 const char *tags[2] = {NULL, NULL};
3628 cpl_frame* result = NULL;
3652 const char *tags[2] = {NULL, NULL};
3653 cpl_frame* result = NULL;
3676 const char *tags[3] = {NULL, NULL, NULL};
3677 cpl_frame* result = NULL;
3702 const char *tags[4] = {NULL, NULL};
3703 cpl_frame* result = NULL;
3730 const char *tags[4] = {NULL, NULL};
3731 cpl_frame* result = NULL;
3758 const char * tags[3] = { NULL, NULL, NULL} ;
3759 cpl_frameset * result = NULL;
3760 cpl_frame * resframe = NULL ;
3766 check( result = cpl_frameset_new() ) ;
3776 if (resframe != NULL ) {
3777 cpl_frame * down = NULL, * cen = NULL , * up = NULL ;
3779 xsh_msg_warning(
"Only one Wave Solution Frame %s, use it for the 3 slitlets",
3780 cpl_frame_get_filename( resframe)) ;
3781 check( down = cpl_frame_duplicate( resframe ) ) ;
3783 check( cpl_frame_set_tag( down, tags[0] ) ) ;
3784 check( cpl_frameset_insert( result, down ) ) ;
3786 check( cen = cpl_frame_duplicate( resframe ) ) ;
3788 check( cpl_frame_set_tag( cen, tags[0] ) ) ;
3789 check( cpl_frameset_insert( result, cen ) ) ;
3791 check( up = cpl_frame_duplicate( resframe ) ) ;
3793 check( cpl_frame_set_tag( up, tags[0] ) ) ;
3794 check( cpl_frameset_insert( result, up ) ) ;
3797 xsh_msg(
"Three wave solution found" ) ;
3801 check( cpl_frameset_insert( result, resframe ) ) ;
3805 check( cpl_frameset_insert( result, resframe ) ) ;
3809 check( cpl_frameset_insert( result, resframe ) ) ;
3813 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
3814 cpl_frameset_delete( result ) ;
3834 cpl_frameset *result = NULL;
3835 const char *tags[2] = {NULL, NULL};
3836 cpl_frame *down = NULL;
3837 cpl_frame *cen = NULL;
3838 cpl_frame *up = NULL;
3844 check( result = cpl_frameset_new());
3849 check( cpl_frameset_insert( result, cpl_frame_duplicate(down)));
3854 check( cpl_frameset_insert( result, cpl_frame_duplicate(cen)));
3859 check( cpl_frameset_insert( result, cpl_frame_duplicate(up)));
3862 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
3864 " The rectified spectra will not be straightened and the resulting" \
3865 " datacube may not be aligned.");
3884 const char *tags[2] = {NULL, NULL};
3885 cpl_frame* result = NULL;
3910 const char *tags[2] = {NULL, NULL};
3911 cpl_frame* result = NULL;
3934 const char *tags[2] = {NULL, NULL};
3935 cpl_frame* result = NULL;
3959 const char *tags[2] = {NULL, NULL};
3960 cpl_frame* result = NULL;
3986 const char *tags[2] ={NULL,NULL};
3987 cpl_frame* result = NULL;
4007 char *tags[4] ={NULL,NULL, NULL,NULL};
4008 cpl_frame* result = NULL;
4009 const char* tag=NULL;
4016 tag=cpl_frame_get_tag(result);
4017 nraw=cpl_frameset_get_size(frames);
4026 xsh_msg(
"Use orderdef frame %s",tag);
4045 char *tags[] ={NULL,NULL};
4046 cpl_frame* result = NULL;
4069 const char *tags[3] ={NULL,NULL};
4070 cpl_frame* result = NULL;
4077 if (result == NULL){
4078 xsh_msg(
"No DISP TAB frame found !!");
4080 xsh_msg(
"Use DISP TAB %s",cpl_frame_get_tag(result));
4100 char *tags[] ={NULL,NULL};
4101 cpl_frame* result = NULL;
4121 char *tags[] ={NULL,NULL};
4122 cpl_frame* result = NULL;
4146 char *tags[] ={NULL,NULL};
4147 cpl_frame* result = NULL;
4166 char *tags[] ={NULL,NULL};
4167 cpl_frame* result = NULL;
4189 char *tags[] ={NULL,NULL};
4190 cpl_frame* result = NULL;
4216 char *tags[] ={NULL,NULL};
4217 cpl_frame* result = NULL;
4243 char *tags[] ={NULL,NULL};
4244 cpl_frame* result = NULL;
4268 char *tags[] ={NULL,NULL};
4269 cpl_frame* result = NULL;
4295 char *tags[] ={NULL,NULL};
4296 cpl_frame* result = NULL;
4321 char *tags[] ={NULL,NULL};
4322 cpl_frame* result = NULL;
4352 cpl_frame *frame = NULL;
4354 char *tags_string = NULL;
4358 assure (frames != NULL, CPL_ERROR_NULL_INPUT,
"Null frameset");
4359 assure (tags != NULL, CPL_ERROR_NULL_INPUT,
"Null tags");
4363 for (i = 0; !found && tags[i] != NULL; i++) {
4370 cpl_free (tags_string);
4375 cpl_free (tags_string);
4381 frame = cpl_frameset_find (frames, tags[i]);
4383 if (frame != NULL) {
4394 cpl_free (tags_string);
4403 cpl_propertylist* qc = NULL;
4404 const char* name = NULL;
4405 name = cpl_frame_get_filename(frm);
4406 qc = cpl_propertylist_load_regexp(name, 0,
"^ESO QC *", 0);
4441 cpl_frame*
ref=NULL;
4442 cpl_frame* frm=NULL;
4443 const char* namer=NULL;
4444 const char* namef=NULL;
4445 const char* tagr=NULL;
4446 const char* tagf=NULL;
4449 cpl_propertylist* href=NULL;
4450 cpl_propertylist* head=NULL;
4466 check(
ref=cpl_frameset_get_frame(set,0));
4467 namer=cpl_frame_get_filename(
ref);
4468 tagr=cpl_frame_get_tag(
ref);
4470 href=cpl_propertylist_load(namer,0);
4476 ncal=cpl_frameset_get_size(calib);
4478 for(i=0;i<ncal;i++) {
4480 frm=cpl_frameset_get_frame(calib,i);
4481 namef=cpl_frame_get_filename(frm);
4482 head=cpl_propertylist_load(namef,0);
4485 if(frm_naxis == 2) {
4490 if(frm_binx != ref_binx ||
4491 frm_biny != ref_biny )
4493 tagf=cpl_frame_get_tag(frm);
4495 namef,tagf,frm_binx,frm_biny);
4496 xsh_msg_error(
"mismatch raw frame's bin %s (tag=%s, bin=%d,%d).",
4497 namer,tagr,ref_binx,ref_biny);
4498 cpl_error_set(cpl_func,CPL_ERROR_ILLEGAL_INPUT);
4508 return cpl_error_get_code();
4518 const char* name=NULL;
4522 cpl_frame* frm_o=NULL;
4523 const char* tag=NULL;
4525 const char* basename=NULL;
4527 cpl_propertylist* plist=NULL;
4528 check(name=cpl_frame_get_filename(frm_i));
4529 check(tag=cpl_frame_get_tag(frm_i));
4533 sprintf(new_name,
"fctx%d_fcty%d_%s",
binx,
biny,basename);
4535 xsh_msg(
"new_name=%s",new_name);
4547 cpl_frame_set_filename(frm_o,new_name);
4563 cpl_frameset* correct=NULL;
4564 cpl_frame* frm=NULL;
4565 cpl_frame* frm_new=NULL;
4566 cpl_propertylist* plist=NULL;
4568 const char* name=NULL;
4569 const char* tag=NULL;
4577 sz=cpl_frameset_get_size(input);
4578 correct=cpl_frameset_new();
4580 frm=cpl_frameset_get_frame(input,i);
4581 name=cpl_frame_get_filename(frm);
4582 tag=cpl_frame_get_tag(frm);
4583 if(strstr(tag,
"MASTER") != NULL) {
4584 plist=cpl_propertylist_load(name,0);
4588 if(inp_binx < ref_binx || inp_biny < ref_biny) {
4589 xsh_msg(
"rescaling calib frame %s",cpl_frame_get_tag(frm));
4590 fctx=ref_binx/inp_binx;
4591 fcty=ref_biny/inp_biny;
4593 check(cpl_frameset_insert(correct,frm_new));
4596 check(cpl_frameset_insert(correct,cpl_frame_duplicate(frm)));
4599 check(cpl_frameset_insert(correct,cpl_frame_duplicate(frm)));
4615 cpl_frameset* correct=NULL;
4616 cpl_frame* frm=NULL;
4617 cpl_frame* frm_new=NULL;
4618 cpl_propertylist* plist=NULL;
4620 const char* name=NULL;
4628 sz=cpl_frameset_get_size(input);
4629 correct=cpl_frameset_new();
4631 frm=cpl_frameset_get_frame(input,i);
4632 name=cpl_frame_get_filename(frm);
4634 plist = cpl_propertylist_load(name, 0);
4639 xsh_msg(
"rescaling raw frame %s", cpl_frame_get_tag(frm));
4641 fctx = ref_binx / inp_binx;
4642 fcty = ref_biny / inp_biny;
4646 check(cpl_frameset_insert(correct,frm_new));
4668 if((*raws != NULL) && (*calib != NULL) &&
4674 const char* name=NULL;
4675 cpl_propertylist* plist=NULL;
4679 cpl_frame* raw_frm=NULL;
4680 cpl_frame* mflat=NULL;
4681 raw_frm=cpl_frameset_get_frame(*raws,0);
4683 name=cpl_frame_get_filename(raw_frm);
4684 plist=cpl_propertylist_load(name,0);
4691 cpl_error_set(cpl_func, CPL_ERROR_FILE_NOT_FOUND);
4695 name=cpl_frame_get_filename(mflat);
4696 plist=cpl_propertylist_load(name,0);
4706 if ( raw_binx == cal_binx && raw_biny == cal_biny) {
4707 }
else if ( raw_binx > cal_binx || raw_biny > cal_biny) {
4722 return cpl_error_get_code();
4736 cpl_propertylist* plist=NULL;
4737 const char* name=NULL;
4738 cpl_frame* frm=NULL;
4739 cpl_frame* frm_new=NULL;
4742 const char* tag=NULL;
4743 cpl_frameset* calib_new=NULL;
4745 check(frm=cpl_frameset_get_frame(raws,0));
4746 name=cpl_frame_get_filename(frm);
4747 plist=cpl_propertylist_load(name,0);
4751 sz=cpl_frameset_get_size(calib);
4753 calib_new=cpl_frameset_new();
4755 frm=cpl_frameset_get_frame(calib,i);
4756 name=cpl_frame_get_filename(frm);
4757 tag=cpl_frame_get_tag(frm);
4758 if(strstr(tag,
"MASTER") != NULL) {
4759 plist=cpl_propertylist_load(name,0);
4763 if(cal_binx > raw_binx || cal_biny > raw_biny) {
4764 xsh_msg(
"rescaling cal frame %s",cpl_frame_get_tag(frm));
4765 fctx=cal_binx/raw_binx;
4766 fcty=cal_biny/raw_biny;
4768 cpl_frameset_insert(calib_new,frm_new);
4769 }
else if(cal_binx < raw_binx || cal_biny < raw_biny) {
4770 xsh_msg(
"rescaling cal frame %s",cpl_frame_get_tag(frm));
4771 fctx=raw_binx/cal_binx;
4772 fcty=raw_biny/cal_biny;
4774 check(cpl_frameset_insert(calib_new,frm_new));
4777 check(cpl_frameset_insert(calib_new,cpl_frame_duplicate(frm)));
4780 check(cpl_frameset_insert(calib_new,cpl_frame_duplicate(frm)));
4794static cpl_error_code
4796 const char* colname)
4799 cpl_table* tab=NULL;
4800 cpl_table* ext=NULL;
4801 const char* name=NULL;
4802 const char* basename=NULL;
4804 cpl_propertylist* head=NULL;
4805 cpl_propertylist* hext=NULL;
4809 name=cpl_frame_get_filename(frame);
4811 sprintf(new_name,
"cut_nir_HJ_%s",basename);
4812 next=cpl_frame_get_nextensions(frame);
4814 head=cpl_propertylist_load(name,0);
4815 for(i=1;i<=next;i++) {
4816 tab=cpl_table_load(name,i,0);
4817 hext=cpl_propertylist_load(name,i);
4818 cpl_table_and_selected_int(tab,colname,CPL_GREATER_THAN,absordmin-1);
4819 ext=cpl_table_extract_selected(tab);
4821 check(cpl_table_save(ext,head,hext,new_name,CPL_IO_DEFAULT));
4823 check(cpl_table_save(ext,head,hext,new_name,CPL_IO_EXTEND));
4829 cpl_frame_set_filename(frame,new_name);
4838 return cpl_error_get_code();
4844static cpl_error_code
4851 return cpl_error_get_code();
4855static cpl_error_code
4859 cpl_frame* order_tab_guess=NULL;
4871 return cpl_error_get_code();
4877static cpl_error_code
4880 cpl_frame* cen_order_tab_frame = NULL;
4892 return cpl_error_get_code();
4897static cpl_error_code
4900 cpl_frame* order_tab_edges = NULL;
4901 cpl_frame* theo_tab_mult = NULL;
4917 return cpl_error_get_code();
4923static cpl_error_code
4929 cpl_frame* order_tab_edges=NULL;
4930 cpl_frame* disp_tab_frame=NULL;
4943 return cpl_error_get_code();
4948static cpl_error_code
4952 cpl_frame* order_tab_edges=NULL;
4953 cpl_frame* disp_tab_frame=NULL;
4954 cpl_frame* wave_tab_frame=NULL;
4968 return cpl_error_get_code();
4976 cpl_frame* edges_order_tab_frame = NULL;
4977 cpl_frame* spectral_format_frame = NULL;
4978 cpl_table* tab_edges=NULL;
4980 const char* fname = NULL;
4987 fname=cpl_frame_get_filename(edges_order_tab_frame);
4988 tab_edges=cpl_table_load(fname,1,0);
4989 min=cpl_table_get_column_min(tab_edges,
"ABSORDER");
5010 return cpl_error_get_code();
5029 if(strcmp(recid,
"xsh_predict") == 0) {
5031 }
else if(strcmp(recid,
"xsh_orderpos") == 0) {
5033 }
else if(strcmp(recid,
"xsh_mflat") == 0) {
5035 }
else if(strcmp(recid,
"xsh_2dmap") == 0) {
5037 }
else if(strcmp(recid,
"xsh_wavecal") == 0) {
5039 }
else if(strcmp(recid,
"xsh_flexcomp") == 0) {
5041 }
else if(strcmp(recid,
"xsh_respon_slit_stare") == 0) {
5043 }
else if(strcmp(recid,
"xsh_respon_slit_offset") == 0) {
5045 }
else if(strcmp(recid,
"xsh_respon_slit_nod") == 0) {
5047 }
else if(strcmp(recid,
"xsh_scired_slit_stare") == 0) {
5049 }
else if(strcmp(recid,
"xsh_scired_slit_offset") == 0) {
5051 }
else if(strcmp(recid,
"xsh_scired_slit_nod") == 0) {
5057 return cpl_error_get_code();
5065 cpl_frame* frm_mflat=NULL;
5066 cpl_frame* frm_mflat_new=NULL;
5073 cpl_propertylist* plist=NULL;
5074 const char* name=NULL;
5079 ref_binx=inst->
binx;
5080 ref_biny=inst->
biny;
5082 xsh_msg(
"binx=%d biny=%d",ref_binx,ref_biny);
5083 check(frm_mflat=cpl_frameset_find(*calib,tag));
5084 check(name=cpl_frame_get_filename(frm_mflat));
5085 plist=cpl_propertylist_load(name,0);
5089 if(
binx > ref_binx ||
biny > ref_biny) {
5090 xsh_msg(
"compute syntetic frame by division");
5094 cpl_frameset_erase_frame(*calib,frm_mflat);
5095 cpl_frameset_insert(*calib,frm_mflat_new);
5097 }
else if(
binx < ref_binx ||
biny < ref_biny) {
5098 xsh_msg(
"compute syntetic frame by multiplication");
5102 cpl_frameset_erase_frame(*calib,frm_mflat);
5103 cpl_frameset_insert(*calib,frm_mflat_new);
5105 xsh_msg(
"keep same frame binx=%d ref_binx=%d biny=%d ref_biny=%d",
5113 return cpl_error_get_code();
5123 cpl_frame* frm=NULL;
5124 cpl_propertylist* plist=NULL;
5125 const char* name=NULL;
5126 double ref_exptime=0;
5127 double tmp_exptime=0;
5130 const char* info=NULL;
5136 sz=cpl_frameset_get_size(raws);
5138 check(frm=cpl_frameset_get_frame(raws,i));
5139 name=cpl_frame_get_filename(frm);
5140 plist=cpl_propertylist_load(name,0);
5148 tmp_exptime=ref_exptime;
5155 if( fabs(tmp_exptime-ref_exptime) > 0.001) {
5156 xsh_msg_error(
"Some dark has %s different from others.",info);
5157 xsh_msg(
"%s(%d)=%g %s(0)=%g",info,i,tmp_exptime,info,ref_exptime);
5158 cpl_error_set(cpl_func, CPL_ERROR_ILLEGAL_INPUT);
5166 return cpl_error_get_code();
5172 const char* fname,
const int ext) {
5175 cpl_table_save(t,ph,xh,fname,CPL_IO_DEFAULT);
5177 cpl_table_save(t,ph,xh,fname,CPL_IO_EXTEND);
5180 return cpl_error_get_code();
5189 cpl_vector_save(v,fname,CPL_BPP_IEEE_FLOAT,ph,CPL_IO_DEFAULT);
5191 cpl_vector_save(v,fname,CPL_BPP_IEEE_FLOAT,ph,CPL_IO_EXTEND);
5194 return cpl_error_get_code();
5203 cpl_propertylist* head_m=NULL;
5204 cpl_propertylist* head_o=NULL;
5205 const char* name_m=NULL;
5206 const char* name_o=NULL;
5207 cpl_image* ima=NULL;
5209 name_m=cpl_frame_get_filename(frm_m);
5210 name_o=cpl_frame_get_filename(frm_o);
5211 head_m=cpl_propertylist_load(name_m,0);
5212 head_o=cpl_propertylist_load(name_o,0);
5234 return cpl_error_get_code();
5252 assert(
string != NULL);
5253 assert(aperture != NULL);
5258 const char*
x = strchr(
string,
'x');
5259 if (
x == NULL)
return CPL_FALSE;
5260 int lenx = strlen(
x);
5264 strncpy(value,
string,lenx);
5268 char* endptr = NULL;
5270 *aperture = strtod(value, &endptr);
5271 if (endptr == NULL)
return CPL_FALSE;
5274 if (*endptr !=
'\0') {
5275 if (isdigit(*endptr))
return CPL_FALSE;
5278 if (errno == ERANGE) {
5279 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT,
5280 "Value overflowed and is out of range.");
5296 const char * colname)
5298 cpl_errorstate prestate = cpl_errorstate_get();
5299 const char* bunit = cpl_propertylist_get_string(header,
XSH_BUNIT);
5300 const char* column_unit = NULL;
5301 if (bunit != NULL) {
5302 if (strcasecmp(bunit,
"ADU") == 0) {
5304 }
else if (strcasecmp(bunit,
"erg/s/cm2/Angstrom") == 0) {
5307 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
5308 "Could not identify the units for the %s.", colname);
5311 if (! cpl_errorstate_is_equal(prestate))
return NULL;
5322 cpl_frameset_iterator* iter = NULL;
5324 iter = cpl_frameset_iterator_new(frames);
5325 const cpl_frame* frame = cpl_frameset_iterator_get_const(iter);
5326 while (frame != NULL) {
5327 if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_RAW) {
5330 cpl_errorstate status = cpl_errorstate_get();
5331 cpl_frameset_iterator_advance(iter, 1);
5332 if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) {
5333 cpl_errorstate_set(status);
5335 frame = cpl_frameset_iterator_get_const(iter);
5337 cpl_frameset_iterator_delete(iter);
5357 const cpl_frameset *usedframes,
5360 cpl_propertylist* keywords = NULL;
5361 cpl_frameset_iterator* iter = NULL;
5362 double mjdend = NAN;
5366 const char* filename;
5367 check(filename = cpl_frame_get_filename(product_frame));
5368 check(keywords = cpl_propertylist_load(filename, 0));
5371 iter = cpl_frameset_iterator_new(usedframes);
5372 const cpl_frame* frame = cpl_frameset_iterator_get_const(iter);
5373 while (frame != NULL) {
5374 if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_RAW) {
5376 check(filename = cpl_frame_get_filename(frame));
5377 cpl_propertylist_delete(keywords);
5378 check(keywords = cpl_propertylist_load(filename, 0));
5381 double obsval=0, expval=0, total=0, dit=0;
5382 double factor=1./(86400.);
5389 check(nditskip = cpl_propertylist_get_int(keywords,
5391 if (nditskip == 0) {
5392 expval = dit * ndit;
5395 " to handle this case so will over estimate '%s'.",
5403 total = obsval + expval * factor;
5404 if (total > mjdend) mjdend = total;
5408 cpl_errorstate status = cpl_errorstate_get();
5409 cpl_frameset_iterator_advance(iter, 1);
5410 if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) {
5411 cpl_errorstate_set(status);
5413 frame = cpl_frameset_iterator_get_const(iter);
5418 cpl_frameset_iterator_delete(iter);
5419 cpl_propertylist_delete(keywords);
5436 cpl_propertylist* keywords = NULL;
5437 cpl_frameset_iterator* iter = NULL;
5438 double mjdobs = NAN;
5440 iter = cpl_frameset_iterator_new(usedframes);
5441 const cpl_frame* frame = cpl_frameset_iterator_get_const(iter);
5442 while (frame != NULL) {
5443 if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_RAW) {
5445 const char* filename;
5446 check(filename = cpl_frame_get_filename(frame));
5447 check(keywords = cpl_propertylist_load(filename, 0));
5451 cpl_propertylist_delete(keywords);
5453 if (isnan(mjdobs)) {
5455 }
else if (val < mjdobs) {
5460 cpl_errorstate status = cpl_errorstate_get();
5461 cpl_frameset_iterator_advance(iter, 1);
5462 if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) {
5463 cpl_errorstate_set(status);
5465 frame = cpl_frameset_iterator_get_const(iter);
5469 cpl_frameset_iterator_delete(iter);
5470 cpl_propertylist_delete(keywords);
5491 const cpl_frameset* usedframes)
5493 cpl_propertylist* keywords = NULL;
5494 cpl_frameset_iterator* iter = NULL;
5498 iter = cpl_frameset_iterator_new(usedframes);
5499 const cpl_frame* frame = cpl_frameset_iterator_get_const(iter);
5500 while (frame != NULL) {
5501 if (cpl_frame_get_group(frame) == CPL_FRAME_GROUP_RAW) {
5503 const char* filename;
5504 check(filename = cpl_frame_get_filename(frame));
5505 check(keywords = cpl_propertylist_load(filename, 0));
5509 const char* prov_value = NULL;
5510 if (cpl_propertylist_has(keywords,
XSH_ARCFILE)) {
5512 }
else if (cpl_propertylist_has(keywords,
XSH_ORIGFILE)) {
5515 prov_value = filename;
5520 const char* dpr_type = cpl_propertylist_get_string(keywords,
XSH_DPR_TYPE);
5521 int is_a_sky = strcmp(dpr_type,
"SKY");
5524 if (is_a_sky == 0) {
5525 xsh_msg_warning(
"xsh_fill_provenance_keywords: Disallowing a SKY input from being tracked as PROV: %s", prov_value);
5530 check(irplib_sdp_spectrum_set_prov(spectrum, ncombine, prov_value));
5532 cpl_propertylist_delete(keywords);
5536 cpl_errorstate status = cpl_errorstate_get();
5537 cpl_frameset_iterator_advance(iter, 1);
5538 if (cpl_error_get_code() == CPL_ERROR_ACCESS_OUT_OF_RANGE) {
5539 cpl_errorstate_set(status);
5541 frame = cpl_frameset_iterator_get_const(iter);
5545 check(irplib_sdp_spectrum_set_ncombine(spectrum, ncombine));
5548 cpl_frameset_iterator_delete(iter);
5549 cpl_propertylist_delete(keywords);
5584 irplib_sdp_spectrum * sdp_spectrum,
5585 const cpl_frameset * usedframes,
5586 const cpl_propertylist * sourcekeys,
5591 cpl_errorstate prestate;
5592 cpl_error_code error = CPL_ERROR_NONE;
5594 cpl_ensure_code(sdp_spectrum != NULL, CPL_ERROR_NULL_INPUT);
5595 cpl_ensure_code(usedframes != NULL, CPL_ERROR_NULL_INPUT);
5596 cpl_ensure_code(sourcekeys != NULL, CPL_ERROR_NULL_INPUT);
5597 cpl_ensure_code(
instrument != NULL, CPL_ERROR_NULL_INPUT);
5599 assert( !(spectrum == NULL && uncal_spectrum == NULL) );
5604 if (spectrum == NULL) {
5605 spectrum = uncal_spectrum;
5606 uncal_spectrum = NULL;
5611 if (uncal_spectrum != NULL) {
5613 if (nelem != uncal_size) {
5614 return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
5615 "Both input spectra must have the same size.");
5619 prestate = cpl_errorstate_get();
5623 if (! cpl_errorstate_is_equal(prestate)) {
5624 return cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
5625 "Failed to find required wavelength information.");
5630 error |= irplib_sdp_spectrum_set_mepoch(sdp_spectrum, CPL_FALSE);
5631 error |= irplib_sdp_spectrum_set_contnorm(sdp_spectrum, CPL_FALSE);
5632 error |= irplib_sdp_spectrum_set_fluxerr(sdp_spectrum,
5634 error |= irplib_sdp_spectrum_set_referenc(sdp_spectrum,
5636 error |= irplib_sdp_spectrum_set_voclass(sdp_spectrum,
5638 error |= irplib_sdp_spectrum_set_vopub(sdp_spectrum,
5644 error |= irplib_sdp_spectrum_copy_prodlvl(sdp_spectrum, sourcekeys,
5647 error |= irplib_sdp_spectrum_set_prodlvl(sdp_spectrum,
5651 error |= irplib_sdp_spectrum_copy_origin(sdp_spectrum, sourcekeys,
5654 error |= irplib_sdp_spectrum_set_origin(sdp_spectrum,
5658 error |= irplib_sdp_spectrum_copy_specsys(sdp_spectrum, sourcekeys,
5661 error |= irplib_sdp_spectrum_set_specsys(sdp_spectrum,
5667 error |= irplib_sdp_spectrum_copy_procsoft(sdp_spectrum, sourcekeys,
5672 const char* dispelem;
5683 if (dispelem != NULL) {
5684 error |= irplib_sdp_spectrum_set_dispelem(sdp_spectrum, dispelem);
5686 error = cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
5687 "Could not identify the correct ARM value to be used"
5692 error |= irplib_sdp_spectrum_copy_progid(sdp_spectrum, sourcekeys,
5696 error |= irplib_sdp_spectrum_copy_obid(sdp_spectrum, 1,
5700 error |= irplib_sdp_spectrum_copy_obstech(sdp_spectrum, sourcekeys,
5706 const char* procatg = cpl_propertylist_get_string(sourcekeys,
5708 if (procatg != NULL) {
5709 const char* fluxcal =
"UNCALIBRATED";
5710 if (strstr(procatg,
"_FLUX_") != NULL) {
5711 fluxcal =
"ABSOLUTE";
5713 error |= irplib_sdp_spectrum_set_fluxcal(sdp_spectrum, fluxcal);
5715 error = cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
5716 "Could not set '%s' since the '%s' keyword was not"
5721 prestate = cpl_errorstate_get();
5722 double crpix1 = cpl_propertylist_get_double(sourcekeys,
XSH_CRPIX1);
5723 double cdelt1 = cpl_propertylist_get_double(sourcekeys,
XSH_CDELT1);
5724 double crval1 = cpl_propertylist_get_double(sourcekeys,
XSH_CRVAL1);
5725 long naxis1 = cpl_propertylist_get_long(sourcekeys,
XSH_NAXIS1);
5726 if (cpl_errorstate_is_equal(prestate)) {
5727 double wavelmin = (1 - crpix1) * cdelt1 + crval1;
5728 double wavelmax = (naxis1 - crpix1) * cdelt1 + crval1;
5729 double specbin = cdelt1;
5730 cpl_msg_info(__func__,
"Setting SDP wavelmin = %3.10f from crval1 = %3.10f", wavelmin, crval1);
5732 error |= irplib_sdp_spectrum_set_wavelmin(sdp_spectrum, wavelmin);
5733 error |= irplib_sdp_spectrum_set_wavelmax(sdp_spectrum, wavelmax);
5734 error |= irplib_sdp_spectrum_set_specbin(sdp_spectrum, specbin);
5736 error = cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
5737 "Could not find WCS information.");
5742 const char*
object = cpl_propertylist_get_string(sourcekeys,
5744 if (
object != NULL) {
5745 error |= irplib_sdp_spectrum_set_object(sdp_spectrum,
object);
5747 char* objstr = cpl_strdup(
object);
5750 char* c = strchr(objstr,
',');
5752 c = strchr(c+1,
',');
5753 if (c != NULL) *c =
'\0';
5757 char* title = cpl_sprintf(
"%s_%d_%s", objstr,obsid, dateobs);
5759 error |= irplib_sdp_spectrum_set_title(sdp_spectrum, title);
5763 error = cpl_error_set_message(cpl_func, cpl_error_get_code(),
5764 "Could not assign '%s' or '%s' since the '%s' keyword could"
5769 error |= irplib_sdp_spectrum_copy_ra(sdp_spectrum, sourcekeys,
XSH_RA);
5770 error |= irplib_sdp_spectrum_copy_dec(sdp_spectrum, sourcekeys,
XSH_DEC);
5773 prestate = cpl_errorstate_get();
5777 error |= irplib_sdp_spectrum_set_exptime(sdp_spectrum,
exptime);
5778 error |= irplib_sdp_spectrum_set_texptime(sdp_spectrum,
exptime);
5779 }
else if (! cpl_errorstate_is_equal(prestate)) {
5780 error = cpl_error_get_code();
5785 prestate = cpl_errorstate_get();
5786 double mjdobs = cpl_propertylist_get_double(sourcekeys,
XSH_MJDOBS);
5787 double mjdend = cpl_propertylist_get_double(sourcekeys,
XSH_MJDEND);
5789 if (cpl_errorstate_is_equal(prestate)) {
5790 error |= irplib_sdp_spectrum_set_mjdobs(sdp_spectrum, mjdobs);
5791 error |= irplib_sdp_spectrum_set_mjdend(sdp_spectrum, mjdend);
5793 mjdobs = mjdend = NAN;
5798 error |= irplib_sdp_spectrum_copy_snr(sdp_spectrum, sourcekeys,
5805 double specres = -1;
5807 int lamnlin_lut[3] = {280, 310, 140};
5808 double lamrms_lut[3][2] = {
5815 double specres_lut[14][3] = {
5818 { -1 , 18340 , 11424 },
5821 { -1 , 11333 , -1 },
5823 { -1 , 8935 , 5573 },
5825 { -1 , 6505 , 4287 },
5827 { -1 , 5040 , 3416 },
5829 { 1040 , 1512 , 1029 },
5836 const char* used_keyword;
5841 default: usedarm = -1; used_keyword = NULL;
break;
5847 double date_threshold = 55927.0;
5850 prestate = cpl_errorstate_get();
5852 if (cpl_errorstate_is_equal(prestate)) {
5853 if (! (first_mjdobs < date_threshold && date_threshold < mjdend)) {
5854 if (first_mjdobs < date_threshold) {
5861 error = cpl_error_get_code();
5866 const char* lengthstr = cpl_propertylist_get_string(sourcekeys, used_keyword);
5867 if (lengthstr != NULL) {
5868 if (strstr(lengthstr,
"0.4x11") == lengthstr) {
5870 }
else if (strstr(lengthstr,
"0.5x11") == lengthstr) {
5872 }
else if (strstr(lengthstr,
"0.6x11") == lengthstr) {
5874 }
else if (strstr(lengthstr,
"0.7x11") == lengthstr) {
5876 }
else if (strstr(lengthstr,
"0.8x11") == lengthstr) {
5878 }
else if (strstr(lengthstr,
"0.9x11") == lengthstr) {
5880 }
else if (strstr(lengthstr,
"1.0x11") == lengthstr) {
5882 }
else if (strstr(lengthstr,
"1.2x11") == lengthstr) {
5884 }
else if (strstr(lengthstr,
"1.3x11") == lengthstr) {
5886 }
else if (strstr(lengthstr,
"1.5x11") == lengthstr) {
5888 }
else if (strstr(lengthstr,
"1.6x11") == lengthstr) {
5890 }
else if (strstr(lengthstr,
"5.0x11") == lengthstr) {
5892 }
else if (strstr(lengthstr,
"0.6JHx11") == lengthstr) {
5894 }
else if (strstr(lengthstr,
"0.9JHx11") == lengthstr) {
5898 error = cpl_error_get_code();
5904 prestate = cpl_errorstate_get();
5906 if (cpl_errorstate_is_equal(prestate)) {
5909 error = cpl_error_get_code();
5912 if (usedarm != -1) {
5913 lamnlin = lamnlin_lut[usedarm];
5917 prestate = cpl_errorstate_get();
5918 double val = cpl_propertylist_get_double(sourcekeys,
5920 if (cpl_errorstate_is_equal(prestate)) {
5923 error = cpl_error_get_code();
5926 if (usedarm != -1 && softepoch != -1) {
5927 lamrms = lamrms_lut[usedarm][softepoch];
5931 prestate = cpl_errorstate_get();
5932 double val = cpl_propertylist_get_double(sourcekeys,
5934 if (cpl_errorstate_is_equal(prestate)) {
5937 error = cpl_error_get_code();
5940 if (usedslit != -1 && usedarm != -1) {
5941 specres = specres_lut[usedslit][usedarm];
5947 if (lamnlin != -1) {
5948 error |= irplib_sdp_spectrum_set_lamnlin(sdp_spectrum, lamnlin);
5951 error |= irplib_sdp_spectrum_set_lamrms(sdp_spectrum, lamrms);
5953 if (specres != -1) {
5954 error |= irplib_sdp_spectrum_set_specres(sdp_spectrum, specres);
5961 prestate = cpl_errorstate_get();
5962 double val = cpl_propertylist_get_double(sourcekeys,
5964 if (cpl_errorstate_is_equal(prestate)) {
5965 error |= irplib_sdp_spectrum_set_specerr(sdp_spectrum, val);
5967 error = cpl_error_get_code();
5969 }
else if (lamnlin > 0) {
5970 double specerr = -1;
5971 if (cpl_propertylist_has(sourcekeys,
XSH_CRDER1)) {
5972 prestate = cpl_errorstate_get();
5973 double crder1 = cpl_propertylist_get_double(sourcekeys,
XSH_CRDER1);
5974 if (cpl_errorstate_is_equal(prestate) && crder1 != 0) {
5975 specerr = crder1 / sqrt(lamnlin);
5977 error = cpl_error_get_code();
5980 if (specerr == -1 && lamrms != -1) {
5981 specerr = lamrms / sqrt(lamnlin);
5983 if (specerr != -1) {
5984 error |= irplib_sdp_spectrum_set_specerr(sdp_spectrum, specerr);
5992 error |= irplib_sdp_spectrum_copy_specsye(sdp_spectrum, sourcekeys,
5994 }
else if (lamnlin > 0) {
5995 double specsye = NAN;
5996 if (cpl_propertylist_has(sourcekeys,
XSH_CSYER1)) {
5997 prestate = cpl_errorstate_get();
5998 double csyer1 = cpl_propertylist_get_double(sourcekeys,
XSH_CSYER1);
5999 if (cpl_errorstate_is_equal(prestate)) {
6000 specsye = csyer1 / sqrt(lamnlin);
6002 error = cpl_error_get_code();
6005 if (! isnan(specsye)) {
6006 error |= irplib_sdp_spectrum_set_specsye(sdp_spectrum, specsye);
6010 prestate = cpl_errorstate_get();
6011 double gainvalue = NAN;
6012 double detron = NAN;
6017 gainvalue = 1./2.12;
6021 if (! cpl_errorstate_is_equal(prestate)) {
6022 error = cpl_error_get_code();
6027 gainvalue = cpl_propertylist_get_double(sourcekeys,
XSH_CONAD);
6028 if (! cpl_errorstate_is_equal(prestate)) {
6029 error = cpl_error_set_message(cpl_func, cpl_error_get_code(),
6030 "Could not assign '%s' since the '%s' keyword was"
6034 detron = cpl_propertylist_get_double(sourcekeys,
XSH_RON);
6035 if (! cpl_errorstate_is_equal(prestate)) {
6036 error = cpl_error_set_message(cpl_func, cpl_error_get_code(),
6037 "Could not assign '%s' and '%s' since the '%s' keyword"
6047 if (! isnan(detron)) {
6048 error |= irplib_sdp_spectrum_set_detron(sdp_spectrum, detron);
6049 error |= irplib_sdp_spectrum_set_effron(sdp_spectrum, detron);
6055 if (lengthstr != NULL) {
6057 cpl_boolean totflux = CPL_FALSE;
6058 if (strstr(lengthstr,
"5.0x") == lengthstr) totflux = CPL_TRUE;
6059 error |= irplib_sdp_spectrum_set_totflux(sdp_spectrum, totflux);
6061 error |= irplib_sdp_spectrum_set_aperture(sdp_spectrum, aperture);
6063 error = cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
6064 "The '%s' keyword contains an invalid value '%s'."
6065 " An example of the expected format is '0.9x11'.",
6066 used_keyword, lengthstr);
6069 error = cpl_error_set_message(cpl_func, cpl_error_get_code(),
6070 "Could not assign '%s' or '%s' since one could not read the"
6076 if (! isnan(mjdobs) && ! isnan(mjdend)) {
6086 double dit = cpl_propertylist_get_double(sourcekeys,
XSH_DET_DIT);
6087 int ndit = cpl_propertylist_get_int(sourcekeys,
XSH_DET_NDIT);
6089 if (nditskip == 0) {
6090 telapse = dit * ndit;
6093 " to handle this case so will over estimate '%s'.",
6097 telapse = cpl_propertylist_get_double(sourcekeys,
XSH_EXPTIME);
6099 error |= irplib_sdp_spectrum_set_telapse(sdp_spectrum,telapse);
6101 error |= irplib_sdp_spectrum_set_telapse(sdp_spectrum,
6102 (mjdend - mjdobs) * 86400.);
6104 error |= irplib_sdp_spectrum_set_tmid(sdp_spectrum,
6105 (mjdend + mjdobs) * 0.5);
6107 error = cpl_error_set_message(cpl_func, cpl_error_get_code(),
6108 "Could not assign '%s' nor '%s' since one could not read"
6114 error |= irplib_sdp_spectrum_set_tdmin(sdp_spectrum, wavemin);
6115 error |= irplib_sdp_spectrum_set_tdmax(sdp_spectrum, wavemax);
6119 error |= irplib_sdp_spectrum_set_specval(sdp_spectrum,
6120 (wavemax + wavemin)*0.5);
6121 error |= irplib_sdp_spectrum_set_specbw(sdp_spectrum, wavemax - wavemin);
6123 error |= irplib_sdp_spectrum_set_nelem(sdp_spectrum, nelem);
6124 error |= irplib_sdp_spectrum_set_extname(sdp_spectrum,
6126 error |= irplib_sdp_spectrum_set_inherit(sdp_spectrum,
6132 return cpl_error_set_message(cpl_func, cpl_error_get_code(),
6133 "Failed to initialise keyword list for the SDP spectrum.");
6141 if (column_flux_unit == NULL || column_errs_unit == NULL) {
6142 return cpl_error_get_code();
6163 {NULL, CPL_TYPE_INVALID, NULL, NULL, NULL, NULL}
6168 for (column = columns; column->
name != NULL; ++column) {
6169 error = irplib_sdp_spectrum_add_column(sdp_spectrum, column->
name,
6173 return cpl_error_set_message(cpl_func, cpl_error_get_code(),
6174 "Failed to setup the '%s' column.", column->
name);
6178 "TUCD",
"Air wavelength");
6181 if (uncal_spectrum != NULL) {
6185 "uncalibrated flux");
6187 "uncalibrated flux error");
6188 if (column_flux_unit == NULL || column_errs_unit == NULL) {
6189 return cpl_error_get_code();
6201 {NULL, CPL_TYPE_INVALID, NULL, NULL, NULL, NULL}
6205 for (column = uncalib_columns; column->
name != NULL; ++column) {
6206 error = irplib_sdp_spectrum_add_column(sdp_spectrum, column->
name,
6212 return cpl_error_set_message(cpl_func, cpl_error_get_code(),
6213 "Failed to setup the '%s' column.", column->
name);
6222 if (specflux != NULL && specerrs != NULL && specqual != NULL) {
6224 double*
data = cpl_malloc(nelem *
sizeof(
double));
6225 cpl_array* array = cpl_array_wrap_double(
data, nelem);
6228 for (i = 0; i < nelem; ++i) {
6229 data[i] = wavemin + i * wavestep;
6232 error |= cpl_error_get_code();
6234 error |= irplib_sdp_spectrum_set_column_data(sdp_spectrum,
6236 cpl_array_unwrap(array);
6240 array = cpl_array_wrap_double(specflux, nelem);
6241 error |= irplib_sdp_spectrum_set_column_data(sdp_spectrum,
6243 cpl_array_unwrap(array);
6244 array = cpl_array_wrap_double(specerrs, nelem);
6245 error |= irplib_sdp_spectrum_set_column_data(sdp_spectrum,
6247 cpl_array_unwrap(array);
6248 array = cpl_array_wrap_int(specqual, nelem);
6249 error |= irplib_sdp_spectrum_set_column_data(sdp_spectrum,
6251 cpl_array_unwrap(array);
6254 data = cpl_malloc(nelem *
sizeof(
double));
6255 array = cpl_array_wrap_double(
data, nelem);
6258 for (i = 0; i < nelem; ++i) {
6259 double denom = fabs(specerrs[i]);
6260 data[i] = denom != 0 ? fabs(specflux[i]) / denom : 0;
6263 error |= cpl_error_get_code();
6265 error |= irplib_sdp_spectrum_set_column_data(sdp_spectrum,
6267 cpl_array_unwrap(array);
6271 error = cpl_error_get_code();
6275 if (uncal_spectrum != NULL) {
6278 if (specflux != NULL && specerrs != NULL) {
6279 cpl_array* array = cpl_array_wrap_double(specflux, nelem);
6280 error |= irplib_sdp_spectrum_set_column_data(sdp_spectrum,
6282 cpl_array_unwrap(array);
6283 array = cpl_array_wrap_double(specerrs, nelem);
6284 error |= irplib_sdp_spectrum_set_column_data(sdp_spectrum,
6286 cpl_array_unwrap(array);
6288 error = cpl_error_get_code();
6293 return cpl_error_set_message(cpl_func, cpl_error_get_code(),
6294 "Failed to copy spectrum data to table.");
6296 return CPL_ERROR_NONE;
6327 const cpl_frame *uncal_frame,
6328 cpl_frameset *frameset,
6329 const cpl_frameset *usedframes,
6330 const cpl_parameterlist *parameters,
6331 const char *recipe_id,
6333 cpl_propertylist* qclist)
6335 cpl_table* table = cpl_table_new(0);
6336 cpl_propertylist* tablekeys = cpl_propertylist_new();
6337 cpl_propertylist* primarykeys = cpl_propertylist_new();
6338 cpl_propertylist* sourcekeys = NULL;
6339 char* output_procatg = NULL;
6340 char* filename = NULL;
6343 irplib_sdp_spectrum* sdp_spectrum = irplib_sdp_spectrum_new();
6351 if (flux_cal_frame == NULL && uncal_frame == NULL) {
6352 cpl_error_set_message(cpl_func, CPL_ERROR_NULL_INPUT,
6353 "Cannot have both the flux calibrated and"
6354 " uncalibrated frames set to NULL.");
6359 const cpl_frame* product_frame = flux_cal_frame != NULL ? flux_cal_frame
6361 const char* fname = cpl_frame_get_filename(product_frame);
6362 filename = cpl_sprintf(
"SDP_%s", fname);
6364 check(sourcekeys = cpl_propertylist_load(fname, 0));
6367 check(cpl_propertylist_copy_property_regexp(primarykeys, sourcekeys,
6368 "^ESO QC ", CPL_FALSE));
6371 if (uncal_frame != NULL) {
6373 cpl_propertylist* tmpkeys;
6374 tmpkeys = cpl_propertylist_load(cpl_frame_get_filename(uncal_frame), 0);
6375 assure(tmpkeys != NULL, cpl_error_get_code(),
6376 "%s", cpl_error_get_message());
6378 cpl_propertylist_copy_property(sourcekeys, tmpkeys,
XSH_QC_FLUX_SN);
6381 cpl_propertylist_copy_property_regexp(primarykeys, tmpkeys,
6382 "^ESO QC ", CPL_FALSE);
6383 cpl_propertylist_delete(tmpkeys);
6384 assure(cpl_error_get_code() == CPL_ERROR_NONE, cpl_error_get_code(),
6385 "%s", cpl_error_get_message());
6393 const char* inst_comment = cpl_propertylist_get_comment(primarykeys,
6395 if (inst_comment == NULL || strcmp(inst_comment,
"") == 0) {
6397 "Instrument used."));
6412 const char* producttype = NULL;
6413 const char* dprtype ;
6414 cpl_frameset_iterator* iter_new = cpl_frameset_iterator_new(usedframes);
6415 const cpl_frame* testframe = cpl_frameset_iterator_get_const(iter_new);
6416 cpl_propertylist* proptest;
6417 while (testframe != NULL) {
6418 proptest = cpl_propertylist_load(cpl_frame_get_filename(testframe), 0);
6420 dprtype = cpl_propertylist_get_string(proptest,
XSH_DPR_TYPE);
6421 if (strcmp(dprtype,
"OBJECT") == 0) {
6423 producttype =
"SCI" ;
6426 }
else if (strcmp(dprtype,
"STD,TELLURIC") == 0) {
6428 producttype =
"TELL" ;
6431 cpl_frameset_iterator_advance(iter_new, 1);
6432 testframe = cpl_frameset_iterator_get_const(iter_new);
6433 cpl_propertylist_delete(proptest);
6435 cpl_frameset_iterator_delete(iter_new);
6437 if (producttype == NULL) {
6438 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
6439 "Could not identify the correct product type value to be used"
6440 " for '%s'.", CPL_DFS_PRO_CATG);
6443 if (armtag != NULL) {
6444 output_procatg = cpl_sprintf(
"%s_SLIT_FLUX_IDP_%s", producttype, armtag);
6445 check(cpl_propertylist_update_string(primarykeys, CPL_DFS_PRO_CATG,
6448 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
6449 "Could not identify the correct ARM value to be used"
6450 " for '%s'.", CPL_DFS_PRO_CATG);
6460 check(cpl_propertylist_update_double(sourcekeys,
XSH_MJDEND, mjdend));
6463 if (flux_cal_frame != NULL) {
6466 if (uncal_frame != NULL) {
6469 cpl_errorstate prestate = cpl_errorstate_get();
6471 spectrum, uncal_spectrum);
6472 if (! cpl_errorstate_is_equal(prestate)) {
6499 "dummy-association-keys"));
6501 for (assoi = 1; assoi <= assoc_count; ++assoi) {
6502 check(irplib_sdp_spectrum_set_asson(sdp_spectrum, assoi,
" "));
6503 check(irplib_sdp_spectrum_set_assoc(sdp_spectrum, assoi,
" "));
6504 check(irplib_sdp_spectrum_set_assom(sdp_spectrum, assoi,
" "));
6507 cpl_msg_info(cpl_func,
"Writing SDP spectrum as FITS table product(%s): %s",
6508 output_procatg, filename);
6511 if(qclist != NULL && primarykeys != NULL){
6512 if(!cpl_propertylist_has(primarykeys,
"ESO QC FLUX SN") &&
6513 cpl_propertylist_has(primarykeys,
"ESO QC FLUX1 SN") &&
6514 cpl_propertylist_has(primarykeys,
"ESO QC FLUX2 SN")){
6515 double avg = 0.5*(cpl_propertylist_get_double(primarykeys,
"ESO QC FLUX1 SN") + cpl_propertylist_get_double(primarykeys,
"ESO QC FLUX2 SN"));
6516 cpl_propertylist_append_double(qclist,
"ESO QC FLUX SN",avg);
6522 if(cpl_propertylist_get_size(qclist) > 0){
6523 cpl_propertylist_append(primarykeys,qclist);
6528 const char* remregexp =
"^(CHECKSUM|DATASUM)$";
6529 check(irplib_dfs_save_spectrum(
6530 frameset, NULL, parameters, usedframes, product_frame,
6531 sdp_spectrum, recipe_id, primarykeys, tablekeys, remregexp,
6537 if (cpl_version_get_binary_version() >= CPL_VERSION(6, 4, 2)) {
6538 check(irplib_fits_update_checksums(filename));
6544 irplib_sdp_spectrum_delete(sdp_spectrum);
6548 cpl_free(output_procatg);
6549 cpl_propertylist_delete(sourcekeys);
6550 cpl_propertylist_delete(primarykeys);
6551 cpl_propertylist_delete(tablekeys);
6552 cpl_table_delete(table);
static xsh_instrument * instrument
cpl_error_code xsh_baryvel_correct_header(cpl_propertylist *header, cpl_propertylist *bary_header, xsh_bary_corr_param *bary_param)
void xsh_pre_3d_free(xsh_pre_3d **pre_3d)
xsh_pre_3d * xsh_pre_3d_load(cpl_frame *frame)
Load a xsh_pre_3d structure from a frame.
cpl_frame * xsh_pre_3d_save(const xsh_pre_3d *pre, const char *filename, int temp)
Save PRE_3D on disk.
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
double xsh_compute_ron_nir(const double dit)
xsh_pre * xsh_pre_subsample(xsh_pre *self, const int binx, const int biny, const int rescale, xsh_instrument *inst)
Subsample a PRE image of a bin factor binx X biny.
cpl_frame * xsh_pre_save(const xsh_pre *pre, const char *filename, const char *tag, int temp)
Save PRE on disk.
double xsh_spectrum_get_lambda_min(xsh_spectrum *s)
Get minimum lambda of spectrum.
xsh_spectrum * xsh_spectrum_load(cpl_frame *s1d_frame)
Load a 1D spectrum structure.
double * xsh_spectrum_get_errs(xsh_spectrum *s)
Get errs of spectrum.
double xsh_spectrum_get_lambda_step(xsh_spectrum *s)
Get bin in lambda of spectrum.
int * xsh_spectrum_get_qual(xsh_spectrum *s)
Get qual of spectrum.
int xsh_spectrum_get_size(xsh_spectrum *s)
Get size of spectrum.
cpl_frame * xsh_spectrum_save(xsh_spectrum *s, const char *filename, const char *tag)
save a spectrum
double * xsh_spectrum_get_flux(xsh_spectrum *s)
Get flux of spectrum.
double xsh_spectrum_get_lambda_max(xsh_spectrum *s)
Get maximum lambda of spectrum.
void xsh_spectrum_free(xsh_spectrum **s)
free memory associated to an 1D spectrum
#define XSH_ASSURE_NOT_NULL_MSG(pointer, msg)
#define XSH_ASSURE_NOT_ILLEGAL(cond)
#define assure(CONDITION, ERROR_CODE,...)
#define check_msg(COMMAND,...)
#define xsh_error_msg(...)
#define XSH_ASSURE_NOT_NULL(pointer)
#define passure(CONDITION,...)
const char * xsh_instrument_mode_tostring(xsh_instrument *i)
Get the string associated with a mode.
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
XSH_MODE xsh_instrument_get_mode(xsh_instrument *i)
Get a mode on instrument structure.
void xsh_instrument_set_biny(xsh_instrument *instrument, const int biny)
const char * xsh_arm_tostring(XSH_ARM arm)
Get the string associated with an arm.
void xsh_instrument_set_binx(xsh_instrument *instrument, const int binx)
XSH_INSTRCONFIG * xsh_instrument_get_config(xsh_instrument *i)
Get the instrument default set of keywords.
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
void xsh_instrument_parse_tag(xsh_instrument *inst, const char *tag)
analyse a frame tag to set data in instrument structure
void xsh_instrument_free(xsh_instrument **instrument)
free an instrument structure
xsh_instrument * xsh_instrument_new(void)
create new instrument structure
#define xsh_msg_warning(...)
Print an warning message.
#define xsh_msg_dbg_medium(...)
#define xsh_msg_debug(...)
Print a debug message.
#define xsh_msg_error(...)
Print an error message.
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_low(...)
#define xsh_msg_dbg_high(...)
cpl_error_code xsh_plist_set_extra_keys(cpl_propertylist *plist, const char *hduclas1, const char *hduclas2, const char *hduclas3, const char *scidata, const char *errdata, const char *qualdata, const int type)
set hdu keys
double xsh_pfits_get_ra_cumoffset(const cpl_propertylist *plist)
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
int xsh_pfits_get_binx(const cpl_propertylist *plist)
find out the BINX value
double xsh_pfits_get_det_win1_uit1(const cpl_propertylist *plist)
find out the user defined exposure time
double xsh_pfits_get_dit(const cpl_propertylist *plist)
find out the DIT value
void xsh_pfits_set_extname(cpl_propertylist *plist, const char *value)
Write the EXTNAME value.
double xsh_pfits_get_posang(const cpl_propertylist *plist)
double xsh_pfits_get_dec_cumoffset(const cpl_propertylist *plist)
const char * xsh_pfits_get_date_obs(const cpl_propertylist *plist)
find out the DATE
cpl_error_code xsh_plist_div_by_fct(cpl_propertylist **plist, const int fctx, const int fcty)
int xsh_pfits_get_biny(const cpl_propertylist *plist)
find out the BINY value
int xsh_pfits_get_obs_id(cpl_propertylist *plist)
find out the OBS ID
double xsh_pfits_get_mjdobs(const cpl_propertylist *plist)
Find out the modified julian observation date.
cpl_error_code xsh_pfits_combine_headers(cpl_propertylist *header, cpl_frameset *set)
int xsh_pfits_get_naxis(const cpl_propertylist *plist)
find out the NAXIS value
double xsh_pfits_get_cumoffsety(const cpl_propertylist *plist)
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
char * xsh_stringcat_4(const char *s1, const char *s2, const char *s3, const char *s4)
String concatenation.
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
int xsh_fileutils_move(const char *srcpath, const char *dstpath)
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
char * xsh_stringcat_6(const char *s1, const char *s2, const char *s3, const char *s4, const char *s5, const char *s6)
String concatenation.
char * xsh_stringcat_3(const char *s1, const char *s2, const char *s3)
String concatenation.
char * xsh_get_basename(const char *filename)
Return base filename.
char * xsh_stringcat_any(const char *s,...)
Concatenate an arbitrary number of strings.
int xsh_time_stamp_get(void)
get timestamp
char * xsh_stringdup(const char *s)
String duplication.
char * xsh_sdate_utc(time_t *now)
void xsh_free_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
void xsh_add_product_file(const char *name)
Add temporary file to temprary files list.
void xsh_free_imagelist(cpl_imagelist **i)
Deallocate an image list and set the pointer to NULL.
void xsh_free(const void *mem)
Deallocate memory.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
cpl_propertylist * data_header
cpl_propertylist * qual_header
cpl_propertylist * errs_header
cpl_propertylist * data_header
cpl_propertylist * errs_header
cpl_propertylist * flux_header
cpl_propertylist * qual_header
#define XSH_PRE_DATA_TYPE
#define XSH_SPECTRUM_DATA_BPP
#define XSH_SPECTRUM_QUAL_BPP
#define XSH_SPECTRUM_ERRS_BPP
cpl_frame * xsh_find_wavemap(cpl_frameset *frames, xsh_instrument *instr)
Find Wave Map frame. The frame returned should not be free by the caller.
void xsh_dfs_split_qth_d2(cpl_frameset *input, cpl_frameset **qth, cpl_frameset **d2)
Extracts QTH and D2 frames from input frameset.
cpl_error_code xsh_dfs_fix_key_start_end(cpl_frameset *set, cpl_propertylist *head)
cpl_frame * xsh_find_bpmap(cpl_frameset *set)
find the bad pixel map in a set of files
cpl_frame * xsh_find_order_tab_centr(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab CENTR.
static double xsh_calculate_exptime(const cpl_frameset *usedframes, XSH_ARM arm)
Calculates a value for EXPTIME from the list of used frames.
cpl_frame * xsh_find_raw_orderdef_vis_uvb(cpl_frameset *frames)
Find orderdef raw frame for UVB or VIS.
cpl_frame * xsh_find_std_star_flux(cpl_frameset *frames)
Find standard standard star flux frame.
cpl_error_code xsh_vector_save(cpl_vector *v, cpl_propertylist *ph, const char *fname, const int ext)
void xsh_add_product_imagelist(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
static cpl_error_code xsh_sdp_spectrum_create(irplib_sdp_spectrum *sdp_spectrum, const cpl_frameset *usedframes, const cpl_propertylist *sourcekeys, xsh_instrument *instrument, xsh_spectrum *spectrum, xsh_spectrum *uncal_spectrum)
Converts data into Science Data Product 1D spectrum format.
void xsh_add_product_vector(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
cpl_frame * xsh_find_master_dark(cpl_frameset *frames, xsh_instrument *instr)
Find master dark frame.
cpl_frame * xsh_find_spectral_format(cpl_frameset *frames, xsh_instrument *instr)
Find spectral format frame.
static cpl_frameset * xsh_correct_frameset_raws_bin(cpl_frameset *input, const int ref_binx, const int ref_biny, xsh_instrument *inst)
int xsh_dfs_split_offset(cpl_frameset *input, const char *object_tag, const char *sky_tag, cpl_frameset **object, cpl_frameset **sky)
split input RAW offset sof in OBJECT_... and SKY_... framesets
cpl_error_code xsh_calib_nir_respon_corr_if_JH(cpl_frameset *calib, xsh_instrument *instr)
cpl_frame * xsh_find_disp_tab(cpl_frameset *frames, xsh_instrument *instr)
Find Dispersol tab frame. The frame returned should not be free by the caller.
void xsh_add_product_pre(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instr, cpl_propertylist *qclist)
Add DFS keywords to a product frame.
cpl_error_code xsh_dfs_check_binning(cpl_frameset *set, cpl_frameset *calib)
cpl_error_code xsh_calib_nir_corr_if_JH(cpl_frameset *calib, xsh_instrument *instr, const char *recid)
cpl_frameset * xsh_frameset_drl_frames(cpl_frameset *set)
extract DRL specific frames from frameset
cpl_frame * xsh_find_wave_tab_guess(cpl_frameset *frames, xsh_instrument *instr)
Find a wave tab guess.
cpl_frame * xsh_find_model_wavelist(cpl_frameset *frames, xsh_instrument *instr)
Find model wavelength list frame.
cpl_error_code xsh_frameset_merge(cpl_frameset *set1, cpl_frameset *set2)
Extracts raw frames.
cpl_frame * xsh_find_usr_lines_guess_tab(cpl_frameset *frames, xsh_instrument *instr)
Find a user guess line positions table frame.
cpl_error_code xsh_frameset_uniform_bin(cpl_frameset **raws, cpl_frameset **calib, xsh_instrument *instrument)
static void replace_spaces_with_underscores(char *str)
static char * xsh_create_final_name(const char *final_prefix)
creates file name based on tag prefix
cpl_frame * xsh_find_raw_arc_slit_nir_off(cpl_frameset *frames)
Find raw frame for Slit NIR OFF.
static double xsh_get_offsety(cpl_propertylist *plist)
Computes offsety.
void xsh_add_product(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix, const char *type)
cpl_frameset * xsh_frameset_extract_offsety_mismatches(cpl_frameset *raws, const double offset)
Extract frames that has different cumoffy than offset.
cpl_frame * xsh_find_calpro_model_meas_coord(cpl_frameset *frames, xsh_instrument *instr)
Find model config frame.
static cpl_error_code xsh_clean_header(cpl_propertylist *header)
void xsh_add_product_bpmap(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
cpl_frameset * xsh_frameset_ext_table_frames(cpl_frameset *set)
Extract frameset sub set containing only table frames.
static void xsh_fill_provenance_keywords(irplib_sdp_spectrum *spectrum, const cpl_frameset *usedframes)
Fills SDP spectrum object with PROVi keywords.
cpl_frame * xsh_find_order_tab_edges(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab EDGES.
cpl_frame * xsh_find_master_bias(cpl_frameset *frames, xsh_instrument *instr)
Find master bias frame.
void xsh_add_product_pre_3d(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instr)
Add 3d product frame.
cpl_frame * xsh_find_order_tab_recov(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab RECOV.
cpl_frame * xsh_find_raw_orderdef_nir(cpl_frameset *frames)
Find orderdef raw frame for NIR.
int xsh_parameter_get_default_flag(const cpl_parameter *p)
Check if an input parameter has been changed by the user.
static cpl_error_code xsh_calib_nir_mflat_corr_if_JH(cpl_frameset *calib, xsh_instrument *instr)
int xsh_print_rec_status(const int val)
Check if an error has happened and returns error kind and location.
cpl_frame * xsh_find_wave_tab_2d(cpl_frameset *frames, xsh_instrument *instr)
Find a wave tab 2D.
cpl_boolean xsh_mode_is_physmod(cpl_frameset *set, xsh_instrument *instrument)
cpl_error_code xsh_dfs_extract_calib_frames(cpl_frameset *input, cpl_frameset *calib)
split input sof in groups: raw and calib
void xsh_add_product_image(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
void xsh_dfs_split_in_group(cpl_frameset *input, cpl_frameset *raws, cpl_frameset *calib)
split input sof in groups: raw and calib
int xsh_file_exists(const char *filename)
void xsh_add_product_table(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, const char *final_prefix)
Save Table product (input frame has several extensions, 1 table per extension)
void xsh_dfs_split_nir(cpl_frameset *input, cpl_frameset **on, cpl_frameset **off)
split input RAW NIR sof in ON and OFF
static cpl_frame * xsh_frame_pre_subsample(cpl_frame *frm_i, const int binx, const int biny, const int rescale, xsh_instrument *inst)
cpl_frame * xsh_find_off(cpl_frameset *set)
find the off frame in set of files
static const char * xsh_create_final_tag(const char *pcatg_prefix, xsh_instrument *inst, const cpl_frame *frame)
creates tag value based on tag prefix or uses frame tag
cpl_frameset * xsh_find_wave_tab_ifu(cpl_frameset *frames, xsh_instrument *instrument)
Find wave tab ARC (for IFU 3 frames)
cpl_frameset * xsh_find_offset_tab_ifu(cpl_frameset *frames, xsh_instrument *instr)
Find offset tab (One for each slitlet)
static cpl_error_code xsh_calib_nir_orderpos_corr_if_JH(cpl_frameset *calib, xsh_instrument *instr)
static const char * xsh_get_column_unit(cpl_propertylist *header, const char *colname)
Tries to identify the units string to used based in BUNIT.
cpl_frameset * xsh_frameset_extract_offsety_matches(cpl_frameset *raws, const double offset)
Extract frames that has same cumoffy as offset.
cpl_error_code xsh_table_save(cpl_table *t, cpl_propertylist *ph, cpl_propertylist *xh, const char *fname, const int ext)
static cpl_error_code xsh_frame_nir_tab_chop_Kband(cpl_frame *frame, const int absordmin, const char *colname)
void xsh_add_product_spectrum(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instr, cpl_frame **result_frame, cpl_propertylist *qclist)
cpl_frame * xsh_find_slitmap(cpl_frameset *frames, xsh_instrument *instr)
Find a slit map.
static cpl_error_code xsh_calib_nir_scired_corr_if_JH(cpl_frameset *calib, xsh_instrument *instr)
cpl_frame * xsh_find_raw_arc_slit_uvb_vis(cpl_frameset *frames, XSH_ARM arm)
Find raw frame for Slit UVB/VIS.
cpl_frame * xsh_find_order_tab_guess(cpl_frameset *frames, xsh_instrument *instr)
Find an order tab GUESS.
static bool xsh_dfs_tag_check(const char *tag, const char *tag_list[], int size)
check if the tag is in the tag list
cpl_frameset * xsh_frameset_ext_image_frames(cpl_frameset *set)
Extract frameset sub set containing only table frames.
int xsh_dfs_files_dont_exist(cpl_frameset *frameset)
Check if all SOF files exist.
static cpl_error_code xsh_calib_nir_predict_corr_if_JH(cpl_frameset *calib, xsh_instrument *instr)
cpl_frame * xsh_find_std_flux(cpl_frameset *frames)
Find standard star frame.
void xsh_add_product_orders_spectrum(cpl_frame *frame, cpl_frameset *frameset, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instr, cpl_frame **result_frame)
cpl_frame * xsh_find_theo_tab_mult(cpl_frameset *frames, xsh_instrument *instr)
Find a theoretical tab multi pinhole in SOF.
cpl_error_code xsh_dfs_extract_raw_frames(cpl_frameset *input, cpl_frameset *raws)
split input sof in groups: raw and calib
xsh_instrument * xsh_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset and return the instrument detected.
cpl_frame * xsh_find_wave_tab(cpl_frameset *frames, xsh_instrument *instr)
Find a wave tab 2D or a wave tab ARC.
void xsh_dfs_find_flat(cpl_frameset *raws, cpl_frameset *flat)
find the flat set of files in the input SOF and detect the mode of instrument. This function assure t...
cpl_propertylist * xsh_frame_head_extract_qc(cpl_frame *frm)
static int xsh_get_nraws(const cpl_frameset *frames)
Calculates number of raw frames.
void xsh_dfs_filter(cpl_frameset *set, const char *tags[], int size)
filter the frameset with the given tag list
char * xsh_get_tag_from_arm(const char *tag, xsh_instrument *instr)
Find arm specific tag from base and instrument setting.
cpl_error_code xsh_validate_model_cfg(cpl_frame *mod, cpl_frameset *set)
Validate model cfg.
cpl_frame * xsh_find_model_config_tab(cpl_frameset *frames, xsh_instrument *instr)
Find a model configuration table frame.
cpl_frame * xsh_find_model_testpar(cpl_frameset *frames, xsh_instrument *instr)
Find model test parameter list.
cpl_frameset * xsh_frameset_extract_pre(cpl_frameset *frameset, const char *prefix)
Extracts pre frames from a frameset.
static cpl_frameset * xsh_correct_frameset_calib_bin(cpl_frameset *input, const int ref_binx, const int ref_biny, xsh_instrument *inst)
cpl_error_code xsh_add_afc_info(cpl_frame *frm_m, cpl_frame *frm_o)
static double xsh_calculate_mjd_end(const cpl_frame *product_frame, const cpl_frameset *usedframes, XSH_ARM arm)
Calculates a value for MJD-END from the list of used frames.
cpl_frame * xsh_ensure_raws_number_is_even(cpl_frameset *raws)
Make sure input frames is an even number (eventually removes the last from the input list)
static cpl_frame * xsh_find_frame(cpl_frameset *frames, const char *tags[])
Find a frame.
cpl_frame * xsh_find_theo_tab_sing(cpl_frameset *frames, xsh_instrument *instr)
Find a theoretical tab signle pinhole in SOF.
cpl_frameset * xsh_extract_obj_and_sky_pairs(cpl_frameset *raws, xsh_instrument *instrument)
Make sure input frames is composed by obj-sky pairs.
void xsh_add_sdp_product_spectrum(const cpl_frame *flux_cal_frame, const cpl_frame *uncal_frame, cpl_frameset *frameset, const cpl_frameset *usedframes, const cpl_parameterlist *parameters, const char *recipe_id, xsh_instrument *instrument, cpl_propertylist *qclist)
Creates a 1D spectrum product in the Science Data Product format.
cpl_frame * xsh_find_model_config_open(cpl_frameset *frames, xsh_instrument *instr)
Find model config frame.
cpl_error_code xsh_ensure_raws_input_offset_recipe_is_proper(cpl_frameset **raws, xsh_instrument *instrument)
Make sure input frames is an even number (eventually removes the last from the input list)
cpl_frame * xsh_find_raw_orderdef_nir_off(cpl_frameset *frames)
Find orderdef raw frame for NIR OFF.
cpl_frame * xsh_find_arc_line_list_clean(cpl_frameset *frames, xsh_instrument *instr)
Find an arc lines list clean frame.
static cpl_boolean xsh_aperture_string_to_double(const char *string, double *aperture)
Extracts the aperture from a slit string.
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
cpl_frame * xsh_find_arc_line_list(cpl_frameset *frames, xsh_instrument *instr)
Find an arc line list frame.
cpl_frameset * xsh_correct_calib(cpl_frameset *raws, cpl_frameset *calib)
cpl_frameset * xsh_extract_nod_pairs(cpl_frameset *raws, cpl_vector *offset)
Make sure input frames is composed by nod a-b sequence.
cpl_frame * xsh_find_on(cpl_frameset *set)
find the on frame in set of files
cpl_frame * xsh_find_theo_tab_mode(cpl_frameset *frames, xsh_instrument *instr)
Find a theoretical tab IFU or SINg depending of MODE in SOF.
cpl_error_code xsh_dfs_check_mflat_is_proper(xsh_instrument *inst, cpl_frameset **calib)
cpl_frame * xsh_find_raw_arc_slit_nir_on(cpl_frameset *frames)
Find raw frame for Slit NIR ON.
cpl_error_code xsh_dfs_extract_pro_frames(cpl_frameset *input, cpl_frameset *pros)
split input sof in groups: raw and calib
static cpl_error_code xsh_calib_nir_wavecal_corr_if_JH(cpl_frameset *calib, xsh_instrument *instr)
cpl_frame * xsh_find_frame_with_tag(cpl_frameset *frames, const char *tag, xsh_instrument *instr)
Find frame with a given tag.
cpl_frame * xsh_find_master_flat(cpl_frameset *frames, xsh_instrument *instr)
Find master flat frame.
static cpl_error_code xsh_calib_nir_2dmap_corr_if_JH(cpl_frameset *calib, xsh_instrument *instr)
static double xsh_find_first_mjd_obs(const cpl_frameset *usedframes)
Finds the earliest value for MJD_OBS in the set of inputs.
char * xsh_unique_filename(const char *context, const char *caller_id, const char *pro_catg)
Get unique product filename.
void xsh_frame_config(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level, cpl_frame **frame)
Define a frame characteristics.
cpl_frame * xsh_find_calpro_model_config(cpl_frameset *frames, xsh_instrument *instr)
Find model config frame.
cpl_frameset * xsh_frameset_extract(const cpl_frameset *frames, const char *tag)
Extract frames with given tag from frameset.
cpl_error_code xsh_frameset_check_uniform_exptime(cpl_frameset *raws, xsh_instrument *inst)
cpl_frame * xsh_find_model_config(cpl_frameset *frames, xsh_instrument *instr)
Find a model config.
cpl_frame * xsh_find_master_bpmap(cpl_frameset *set)
find the master bad pixel map in a set of files
#define XSH_WAVE_TAB_ARC_CEN_IFU
#define XSH_MOD_CFG_OPT_AFC
#define XSH_THEO_TAB_SING
#define XSH_GUESS_LINES_POS
#define XSH_OFFSET_CEN_IFU
#define XSH_MODEL_TEST_PAR
#define XSH_WAVE_TAB_ARC_DOWN_IFU
#define XSH_MOD_CFG_OPT_2D
#define XSH_OBJECT_SLIT_OFFSET
#define XSH_ORDER_TAB_EDGES
#define XSH_STD_FLUX_IFU_OFFSET
#define XSH_OFFSET_UP_IFU
#define XSH_SCIENCE_SPECTRUM
#define XSH_STD_TELL_SLIT(arm)
#define XSH_MODEL_WAVE_LIST
#define XSH_STD_FLUX_SLIT_OFFSET
#define XSH_STD_TELL_OFFSET(arm)
#define XSH_WAVE_TAB_GUESS
#define XSH_ORDER_TAB_GUESS
#define XSH_IS_CALIB(tag)
#define XSH_MASTER_BP_MAP
#define XSH_STD_FLUX_SLIT(arm)
#define XSH_ORDER_TAB_AFC
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
#define XSH_PRODUCT_PREFIX
#define XSH_ORDER_TAB_RECOV
#define XSH_ORDER_TAB_CENTR
#define XSH_OFFSET_DOWN_IFU
#define XSH_MOD_CFG_OPT_FMT
#define XSH_SPECTRAL_FORMAT
#define XSH_OBJECT_IFU_OFFSET
#define XSH_ORDERDEF_QTH_UVB
#define XSH_STD_FLUX_OFFSET(arm)
#define XSH_MASTER_FLAT_SLIT
#define XSH_ARC_LINE_LIST
#define XSH_THEO_TAB_MULT
#define XSH_STD_STAR_FLUX(arm)
#define XSH_SPECTRAL_FORMAT_JH_NIR
#define XSH_GET_TAG_FROM_MODE(TAG, instr)
#define XSH_ORDERDEF_D2_UVB
#define XSH_WAVE_TAB_ARC_UP_IFU
#define XSH_GET_TAG_FROM_LAMP(TAG, instr)
xsh_bary_corr_param * xsh_parameters_bary_corr_get(const char *recipe_id, cpl_parameterlist *list)
get the barycentric correction parameters in a parameters list
int xsh_parameters_get_int(const cpl_parameterlist *list, const char *recipe_id, const char *name)
#define XSH_SDP_KEYWORD_FLUXERR_VALUE
#define XSH_SDP_COLUMN_ERR_FORMAT
#define XSH_SDP_COLUMN_ERR_UCD
#define XSH_SDP_COLUMN_FLUX_REDUCED_TYPE
#define XSH_SDP_COLUMN_ERR_TYPE
#define XSH_SDP_COLUMN_FLUX_REDUCED_FORMAT
#define XSH_SDP_KEYWORD_PRODCATG
#define XSH_SDP_KEYWORD_GAIN
#define XSH_SDP_COLUMN_QUAL_UCD
#define XSH_SDP_KEYWORD_TELAPSE
#define XSH_SDP_KEYWORD_PRODLVL_VALUE
#define XSH_INSTRUME_VALUE
#define XSH_SDP_COLUMN_FLUX
#define XSH_SDP_KEYWORD_LAMNLIN
#define XSH_SDP_COLUMN_WAVE
#define XSH_SDP_COLUMN_FLUX_UCD
#define XSH_SDP_COLUMN_ERR_REDUCED
#define XSH_SDP_KEYWORD_LAMRMS
#define XSH_SDP_COLUMN_WAVE_UCD
#define XSH_SDP_COLUMN_WAVE_UNIT
#define XSH_SDP_COLUMN_QUAL_FORMAT
#define XSH_SDP_COLUMN_ERR_REDUCED_UCD
#define XSH_SDP_FLUX_UNIT
#define XSH_SDP_KEYWORD_EXTNAME_VALUE
#define XSH_SDP_KEYWORD_OBJECT
#define XSH_SDP_KEYWORD_ORIGIN
#define XSH_SDP_COLUMN_QUAL
#define XSH_SDP_KEYWORD_INHERIT_VALUE
#define XSH_SDP_KEYWORD_APERTURE
#define XSH_SDP_COLUMN_FLUX_REDUCED
#define XSH_SDP_COLUMN_SNR
#define XSH_SDP_KEYWORD_SPEC_RES
#define XSH_SDP_COLUMN_QUAL_UNIT
#define XSH_SDP_COLUMN_ERR
#define XSH_NOD_CUMULATIVE_OFFSETY
#define XSH_SDP_KEYWORD_PRODLVL
#define XSH_PRO_REC1_PIPE_ID
#define XSH_SDP_KEYWORD_ORIGIN_VALUE
#define XSH_SDP_KEYWORD_SPEC_ERR
#define XSH_SDP_COLUMN_SNR_FORMAT
#define XSH_SDP_COLUMN_SNR_UNIT
#define XSH_SDP_COLUMN_WAVE_FORMAT
#define XSH_SDP_KEYWORD_REFERENC_VALUE
#define XSH_SDP_COLUMN_FLUX_TYPE
#define XSH_SDP_KEYWORD_VOCLASS_VALUE
#define XSH_SDP_KEYWORD_DISPELEM
#define XSH_SDP_KEYWORD_SPECSYS
#define XSH_SDP_KEYWORD_DETRON
#define XSH_SDP_COLUMN_QUAL_TYPE
#define XSH_SDP_KEYWORD_FLUXCAL
#define XSH_SDP_COLUMN_FLUX_REDUCED_UCD
#define XSH_SDP_KEYWORD_SPECSYS_VALUE
#define XSH_SDP_KEYWORD_TOT_FLUX
#define XSH_SDP_KEYWORD_TITLE
#define XSH_SDP_KEYWORD_VOPUB_VALUE
#define XSH_OBS_TARG_NAME
#define XSH_SDP_COLUMN_SNR_UCD
#define XSH_SDP_COLUMN_FLUX_FORMAT
#define XSH_SDP_COLUMN_SNR_TYPE
#define XSH_SDP_KEYWORD_TMID
#define XSH_SDP_COLUMN_WAVE_TYPE
#define XSH_SDP_COLUMN_ERR_REDUCED_TYPE
#define XSH_SDP_COLUMN_ERR_REDUCED_FORMAT
#define XSH_SDP_KEYWORD_SPEC_SYE
#define XSH_SDP_KEYWORD_EFFRON
#define XSH_QC_AFC_XSHIFT_C
#define XSH_QC_AFC_YSHIFT
#define XSH_QC_AFC_XSHIFT
#define XSH_QC_AFC_YSHIFT_C
#define XSH_FREE(POINTER)
#define XSH_NEW_FRAMESET(POINTER)
cpl_frame * xsh_frame_image_mult_by_fct(cpl_frame *frm, const int fctx, const int fcty)
cpl_frame * xsh_frame_image_div_by_fct(cpl_frame *frm, const int fctx, const int fcty)
#define XSH_TABLE_FREE(TABLE)