SINFONI Pipeline Reference Manual  2.6.0
sinfo_utilities_scired.c
1 /*
2  * This file is part of the ESO SINFONI Pipeline
3  * Copyright (C) 2004,2005 European Southern Observatory
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18  */
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22 #include <irplib_stdstar.h>
23 
24 //Used only for cpl_propertylist_has
25 #include "sinfo_dfs.h"
26 
27 //Used only for sinfo_band
28 #include "sinfo_tpl_utils.h"
29 
30 #include "sinfo_utilities_scired.h"
31 #include "sinfo_functions.h"
32 #include "sinfo_pfits.h"
33 #include "sinfo_spiffi_types.h"
34 #include "sinfo_utils_wrappers.h"
35 #include "sinfo_error.h"
36 
37 static double
38 sinfo_sess2deg(const double sess);
39 
40 static void
41 sinfo_set_spect_coord1(cpl_propertylist** plist,
42  const int crpix1,
43  const double crval1,
44  const double cdelt1);
45 
46 static void
47 sinfo_set_spect_coord2(cpl_propertylist** plist,
48  const int crpix2,
49  const double crval2,
50  const double cdelt2);
51 
52 
53 static void
54 sinfo_set_coord1(cpl_propertylist** plist,
55  const double crpix1,
56  const double crval1,
57  const double cdelt1,
58  const int is_science);
59 static void
60 sinfo_set_coord2(cpl_propertylist** plist,
61  const double crpix2,
62  const double crval2,
63  const double cdelt2,
64  const int is_science);
65 static void
66 sinfo_set_coord3(cpl_propertylist** plist,
67  const int crpix3,
68  const double crval3,
69  const double cdelt3);
70 
71 
72 static void
73 sinfo_set_cd_matrix2(cpl_propertylist** plist,
74  const double cd1_1,
75  const double cd1_2,
76  const double cd2_1,
77  const double cd2_2);
78 
79 
80 static void
81 sinfo_set_cd_matrix3(cpl_propertylist** plist,
82  const double cd1_3,
83  const double cd2_3,
84  const double cd3_1,
85  const double cd3_2,
86  const double cd3_3);
87 
88 
89 static void
90 sinfo_new_change_plist_cube (cpl_propertylist * plist,
91  float cenLambda,
92  float dispersion,
93  int center_z,
94  float center_x,
95  float center_y );
96 
97 
98 static void
99 sinfo_new_change_plist_image (cpl_propertylist * plist,
100  float center_x,
101  float center_y );
102 
103 
104 static void
105 sinfo_new_change_plist_spectrum (cpl_propertylist * plist,
106  double cenLambda,
107  double dispersion,
108  int cenpix);
109 
110 static cpl_image *
111 sinfo_new_image_getvig(
112  cpl_image * image_in,
113  int loleft_x,
114  int loleft_y,
115  int upright_x,
116  int upright_y);
117 
118 
119 
132 int
133 sinfo_check_input_data(object_config* cfg)
134 {
135 
136 
137  if (cfg == NULL)
138  {
139  sinfo_msg_error (" could not parse cpl input!\n") ;
140  return -1 ;
141  }
142 
143 
144  if(sinfo_is_fits_file(cfg->wavemap) != 1) {
145  sinfo_msg_error("Input file wavemap %s is not FITS",cfg->wavemap);
146  return -1;
147  }
148 
149 
150  if (cfg->halocorrectInd == 1)
151  {
152  if(sinfo_is_fits_file(cfg->halospectrum) != 1) {
153  sinfo_msg_error("Input file %s is not FITS",cfg->halospectrum);
154  return -1;
155  }
156 
157  }
158 
159  if (cfg->northsouthInd == 0) {
160  if (sinfo_is_fits_file(cfg->poslist) != 1)
161  {
162  sinfo_msg_error("File %s with tag %s is not FITS!",
163  cfg->poslist,PRO_SLIT_POS);
164  return -1 ;
165  }
166  } else {
167 
168  if (sinfo_is_fits_file(cfg->distlist) != 1)
169  {
170  sinfo_msg_error("File %s with tag %s is not FITS!",
171  cfg->distlist,PRO_SLITLETS_DISTANCE);
172  return -1;
173  }
174  }
175 
176 
177  return 0;
178 
179 
180 }
188 static double
189 sinfo_hms2deg(const double hms)
190 {
191  int hrs=0;
192  int min=0;
193  double sec=0;
194  double deg=0;
195  double rest=hms;
196  int sign=1;
197 
198  //sinfo_msg("hms=%f",hms);
199 
200  if(hms<0) {
201  sign=-1;
202  rest=-hms;
203  }
204  //sinfo_msg("rest=%f",rest);
205  //sinfo_msg("sign=%d",sign);
206 
207  hrs=(int)(rest/10000.);
208  //sinfo_msg("hrs=%d",hrs);
209 
210  rest=rest-(double)(hrs*10000.);
211  min=(int)(rest/100.);
212  //sinfo_msg("min=%d",min);
213 
214  sec=rest-(double)(min*100.);
215  //sinfo_msg("sec=%f",sec);
216 
217  deg=hrs*15+(double)(min/4.)+(double)(sec/240.);
218  //sinfo_msg("deg=%f",deg);
219 
220  deg=sign*deg;
221  //sinfo_msg("deg=%f",deg);
222 
223  return deg;
224 
225 }
226 
234 static double
235 sinfo_sess2deg(const double sess)
236 {
237  int grad=0;
238  int min=0;
239  double sec=0;
240  double deg=0;
241  double rest=sess;
242  int sign=1;
243 
244  //sinfo_msg("sess=%f",sess);
245 
246  if(sess<0) {
247  sign=-1;
248  rest=-sess;
249  }
250  //sinfo_msg("rest=%f",rest);
251  //sinfo_msg("sign=%d",sign);
252 
253  grad=(int)(rest/10000.);
254  //sinfo_msg("grad=%d",grad);
255 
256  rest=rest-(double)(grad*10000.);
257  min=(int)(rest/100.);
258  //sinfo_msg("min=%d",min);
259 
260  sec=rest-(double)(min*100.);
261  //sinfo_msg("sec=%f",sec);
262 
263  deg=grad+(double)(min/60.)+(double)(sec/3600.);
264  //sinfo_msg("deg=%f",deg);
265 
266  deg=sign*deg;
267  //sinfo_msg("deg=%f",deg);
268 
269  return deg;
270 
271 }
272 
273 
286 int
287 sinfo_auto_size_cube(float* offsetx,
288  float* offsety,
289  const int nframes,
290  float* ref_offx,
291  float* ref_offy,
292  int* size_x,
293  int* size_y)
294 {
295 
296  int n=0;
297 
298  float min_offx=0;
299  float max_offx=0;
300  float min_offy=0;
301  float max_offy=0;
302 
303  sinfo_msg ("Computation of output cube size") ;
304  for ( n = 0 ; n < nframes ; n++ ) {
305  float offx = offsetx[n]; /* was - */
306  float offy = offsety[n]; /* was - */
307  /* sinfo_msg("frame %d offx=%f offy=%f",n,offx,offy); */
308  if(n==0) {
309  min_offx=offx;
310  min_offy=offy;
311  max_offx=offx;
312  max_offy=offy;
313  } else {
314  if(offx > max_offx) max_offx=offx;
315  if(offy > max_offy) max_offy=offy;
316  if(offx < min_offx) min_offx=offx;
317  if(offy < min_offy) min_offy=offy;
318  }
319  }
320  /*
321  sinfo_msg("max_offx=%f max_offy=%f",max_offx,max_offy);
322  sinfo_msg("min_offx=%f min_offy=%f",min_offx,min_offy);
323  */
324  *ref_offx=(min_offx+max_offx)/2;
325  *ref_offy=(min_offy+max_offy)/2;
326  *size_x+=2*floor(max_offx-min_offx+0.5);
327  *size_y+=2*floor(max_offy-min_offy+0.5);
328  sinfo_msg("Output cube size: %d x %d",*size_x,*size_y);
329  sinfo_msg("Ref offset. x: %f y: %f",*ref_offx,*ref_offy);
330  sinfo_msg_debug("Max offset. x: %f y: %f",max_offx,max_offy);
331  sinfo_msg_debug("Min offset. x: %f y: %f",min_offx,min_offy);
332  return 0;
333 
334 }
335 
343 int
344 sinfo_auto_size_cube5(object_config * cfg,
345  float* ref_offx, float* ref_offy,
346  float* min_offx, float* min_offy,
347  float* max_offx, float* max_offy)
348 {
349 
350 
351  int n=0;
352 
353  cpl_propertylist * plist=NULL;
354  sinfo_msg ("Automatic computation of output cube size") ;
355  for ( n = 0 ; n < cfg->nframes ; n++ ) {
356  char* name = cfg->framelist[n] ;
357  plist=cpl_propertylist_load(name,0);
358  float offx = sinfo_pfits_get_cumoffsetx(plist); /* was - */
359  if(cpl_error_get_code() != CPL_ERROR_NONE) {
360  sinfo_msg_warning(" could not read fits header keyword cummoffsetx!");
361  sinfo_msg_warning(" set it to 0");
362  offx = 0;
363  cpl_error_reset();
364  /* return -1 ; */
365  }
366 
367  float offy = sinfo_pfits_get_cumoffsety(plist); /* was - */
368  sinfo_free_propertylist(&plist);
369  if(cpl_error_get_code() != CPL_ERROR_NONE) {
370  sinfo_msg_warning(" could not read fits header keyword! cumoffsety") ;
371  sinfo_msg_warning(" set it to 0");
372  offy = 0;
373  cpl_error_reset();
374  /* return -1 ; */
375  }
376  //sinfo_msg("n=%d offx=%f offy=%f",n,offx,offy);
377 
378  if(n==0) {
379  *min_offx=offx;
380  *min_offy=offy;
381  *max_offx=offx;
382  *max_offy=offy;
383  } else {
384  if(offx > *max_offx) *max_offx=offx;
385  if(offy > *max_offy) *max_offy=offy;
386  if(offx < *min_offx) *min_offx=offx;
387  if(offy < *min_offy) *min_offy=offy;
388  }
389  }
390  *ref_offx=(*min_offx+*max_offx)/2;
391  *ref_offy=(*min_offy+*max_offy)/2;
392 
393  if(cfg->size_x == 0) cfg->size_x=2*floor(*max_offx-*min_offx+0.5)+64 ;
394 /* The formula above doesn't give always the right result (DSF07663)
395  * for example, if diff in offset is 35.5, the formula gives 72 but 71 would be
396  * enough, the following candidate is working fine:
397  * if(cfg->size_x == 0)
398  cfg->size_x=floor(2.0*(*max_offx-*min_offx + 0.5 - 0.00001))+64 ;
399  Currently the ticket is suspended, because the formula above
400  would change the scientific results for the previous data.
401  The same is actual for Y axis.
402 */
403  if(cfg->size_y == 0) cfg->size_y=2*floor(*max_offy-*min_offy+0.5)+64 ;
404 
405  sinfo_msg("Output cube size: %d x %d",cfg->size_x,cfg->size_y);
406  sinfo_msg("Ref offset. x: %f y: %f",*ref_offx,*ref_offy);
407  sinfo_msg("Max offset. x: %f y: %f",*max_offx,*max_offy);
408  sinfo_msg("Min offset. x: %f y: %f",*min_offx,*min_offy);
409  return 0;
410 
411 
412 }
413 
423 float*
424 sinfo_read_distances(const int nslits, const char* distlist)
425 {
426  int i=0;
427  int* status=NULL;
428  float * distances = NULL;
429  char tbl_distances_name[FILE_NAME_SZ];
430  cpl_table* tbl_distances = NULL;
431 
432  sinfo_msg("Read distances");
433  distances = (float*) cpl_calloc (nslits - 1, sizeof (float));
434 
435  if ( NULL == distances )
436  {
437  sinfo_msg_error ("could allocate memory!") ;
438  return NULL ;
439  }
440 
441  /*READ TFITS TABLE*/
442  if(cpl_error_get_code() != CPL_ERROR_NONE) {
443  sinfo_msg_error("Before loading input table");
444  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
445  cpl_free(distances);
446  return NULL;
447  }
448  strcpy(tbl_distances_name,distlist);
449  tbl_distances = cpl_table_load(tbl_distances_name,1,0);
450  if(cpl_error_get_code() != CPL_ERROR_NONE) {
451  sinfo_msg_error("loading input table %s",tbl_distances_name);
452  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
453  cpl_free(distances);
454  return NULL;
455  }
456 
457  for (i =0 ; i< nslits-1; i++){
458  float tmp_float=cpl_table_get_float(tbl_distances,"slitlet_distance",i,status);
459  if(cpl_error_get_code() != CPL_ERROR_NONE) {
460  sinfo_msg_error("reading col %s from table %s","slitlet_distance",
461  tbl_distances_name);
462  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
463  return NULL;
464  }
465  sinfo_new_array_set_value(distances,tmp_float,i);
466  }
467  cpl_table_delete(tbl_distances);
468  return distances;
469 
470 }
471 
472 
473 
481 float**
482 sinfo_read_slitlets_edges(const int nslits, const char* poslist)
483 {
484 
485 
486  char tbl_slitpos_name[FILE_NAME_SZ];
487  cpl_table* tbl_slitpos=NULL;
488  int n=0;
489  int i=0;
490  int* status=NULL;
491 
492  float ** slit_edges = NULL;
493 
494  slit_edges = sinfo_new_2Dfloatarray(nslits, 2) ;
495 
496  strcpy(tbl_slitpos_name,poslist);
497  tbl_slitpos = cpl_table_load(tbl_slitpos_name,1,0);
498  if(cpl_error_get_code() != CPL_ERROR_NONE) {
499  sinfo_msg_error("error loading tbl %s",tbl_slitpos_name);
500  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
501  return NULL;
502  }
503  n = cpl_table_get_nrow(tbl_slitpos);
504  if (n != nslits) {
505  sinfo_msg_error("No of slitlets in table is n = %d != %d !",n,nslits);
506  return NULL;
507  }
508 
509  for (i =0 ; i< nslits; i++){
510  float edge_x=cpl_table_get_double(tbl_slitpos,"pos1",i,status);
511  float edge_y=cpl_table_get_double(tbl_slitpos,"pos2",i,status);
512  if(cpl_error_get_code() != CPL_ERROR_NONE) {
513  sinfo_msg_error("error reading tbl %s row %d",tbl_slitpos_name,i);
514  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
515  return NULL;
516  }
517  sinfo_new_array2D_set_value(slit_edges,edge_x,i,0);
518  sinfo_new_array2D_set_value(slit_edges,edge_y,i,1);
519  }
520  cpl_table_delete(tbl_slitpos);
521  if(cpl_error_get_code() != CPL_ERROR_NONE) {
522  sinfo_msg_error("error reading tbl %s",tbl_slitpos_name);
523  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
524  return NULL;
525  }
526 
527  return slit_edges;
528 
529 }
530 
531 
532 /*---------------------------------------------------------------------------*/
555 /*---------------------------------------------------------------------------*/
556 cpl_imagelist * sinfo_new_cube_getvig(
557  cpl_imagelist * cube_in,
558  int loleft_x,
559  int loleft_y,
560  int upright_x,
561  int upright_y)
562 {
563  cpl_imagelist * cube_out ;
564  int i ;
565  /*
566  int outlx,
567  outly ;
568 
569  int ilx=0;
570  int ily=0;
571  int inp=0;
572  */
573 
574 
575  if (cube_in==NULL) return NULL ;
576 /*
577  ilx=cpl_image_get_size_x(cpl_imagelist_get(cube_in,0));
578  ily=cpl_image_get_size_y(cpl_imagelist_get(cube_in,0));
579  inp=cpl_imagelist_get_size(cube_in);
580 */
581  if ((loleft_x>upright_x) ||
582  (loleft_y>upright_y)) {
583  sinfo_msg_error("ill-defined slit for extraction: aborting");
584  return NULL ;
585  }
586 
587  /* Extraction coordinates include rectangular zone */
588  /*
589  outlx = upright_x - loleft_x + 1 ;
590  outly = upright_y - loleft_y + 1 ;
591  */
592  /*
593  cube_out = sinfo_new_cube(outlx, outly, cube_in->np) ;
594  */
595  cube_out = cpl_imagelist_new() ;
596  /* Loop on all input planes */
597  for (i=0 ; i<cpl_imagelist_get_size(cube_in) ; i++) {
598 
599  cpl_image* i_img=cpl_imagelist_get(cube_in,i);
600  /* Extract a slit from this plane */
601  cpl_image* o_img = sinfo_new_image_getvig(i_img,
602  loleft_x, loleft_y,
603  upright_x, upright_y) ;
604  cpl_imagelist_set(cube_out,o_img,i);
605  }
606  return cube_out ;
607 }
608 /*---------------------------------------------------------------------------*/
625 /*---------------------------------------------------------------------------*/
626 
627 static cpl_image *
628 sinfo_new_image_getvig(
629  cpl_image * image_in,
630  int loleft_x,
631  int loleft_y,
632  int upright_x,
633  int upright_y)
634 {
635  cpl_image * slit_img ;
636  int i, j ;
637  register
638 
639  int outlx, outly ;
640  int ilx=0;
641  int ily=0;
642 
643  float* pidata=NULL;
644  float* podata=NULL;
645 
646  if (image_in==NULL) return NULL ;
647 
648  ilx=cpl_image_get_size_x(image_in);
649  ily=cpl_image_get_size_y(image_in);
650  pidata=cpl_image_get_data_float(image_in);
651 
652  if ((loleft_x<1) || (loleft_x>ilx) ||
653  (loleft_y<1) || (loleft_y>ily) ||
654  (upright_x<1) || (upright_x>ilx) ||
655  (upright_y<1) || (upright_y>ily) ||
656  (loleft_x>upright_x) || (loleft_y>upright_y)) {
657  sinfo_msg_error("extraction zone is [%d %d] [%d %d]\n"
658  "cannot extract such zone: aborting slit extraction",
659  loleft_x, loleft_y, upright_x, upright_y) ;
660  return NULL ;
661  }
662 
663  outlx = upright_x - loleft_x + 1 ;
664  outly = upright_y - loleft_y + 1 ;
665  slit_img = cpl_image_new(outlx, outly,CPL_TYPE_FLOAT) ;
666  podata=cpl_image_get_data_float(slit_img);
667 
668  for (j=0 ; j<outly ; j++) {
669  pixelvalue* inpt = pidata+loleft_x-1 + (j+loleft_y-1)*ilx ;
670  pixelvalue* outpt = podata + j*outlx ;
671  for (i=0 ; i<outlx ; i++) {
672  *outpt++ = *inpt++ ;
673  }
674  }
675  return slit_img ;
676 }
677 
689 int
690 sinfo_new_set_wcs_cube(cpl_imagelist* cub, const char* name, double clambda,
691  double dis, double cpix, double cx, double cy)
692 {
693  cpl_propertylist* plist=NULL;
694 
695  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
696  sinfo_msg_error( "getting header from frame %s",name);
697  cpl_propertylist_delete(plist) ;
698  return -1 ;
699  }
700 
701  sinfo_new_change_plist_cube(plist, clambda, dis, cpix, cx, cy) ;
702  sinfo_plist_set_extra_keys(plist,"IMAGE","DATA","RMSE",
703  "DATA","ERRS","QUAL",0);
704  if (cpl_imagelist_save(cub, name, CPL_BPP_IEEE_FLOAT,
705  plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
706  sinfo_msg_error( "Cannot save the product %s",name);
707  cpl_propertylist_delete(plist) ;
708  return -1 ;
709  }
710  cpl_propertylist_delete(plist) ;
711  return 0;
712 
713 }
714 
715 
716 
730 int
731 sinfo_set_wcs_cal_image(cpl_image* img,
732  const char* name,
733  double crpix1,
734  double crval1,
735  double cdelt1,
736  double crpix2,
737  double crval2,
738  double cdelt2)
739 {
740  cpl_propertylist* plist=NULL;
741 
742  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
743  sinfo_msg_error( "getting header from frame %s",name);
744  cpl_propertylist_delete(plist) ;
745  return -1 ;
746  }
747 
748  sinfo_msg("crpix1=%g crval1=%g cdelt1=%g",crpix1,crval1,cdelt1);
749  sinfo_set_coord1(&plist,crpix1,crval1,cdelt1,0);
750  sinfo_msg("crpix2=%g crval2=%g cdelt2=%g",crpix2,crval2,cdelt2);
751  sinfo_set_coord2(&plist,crpix2,crval2,cdelt2,0);
752  cpl_propertylist_erase_regexp(plist, "^CDELT*",0);
753 
754  double cd1_1=0;
755  double cd1_2=0;
756  double cd2_1=0;
757  double cd2_2=0;
758  /* simple case with radangle=0 */
759  cd1_1 = +cdelt1;
760  cd1_2 = 0;
761  cd2_1 = 0;
762  cd2_2 = +cdelt2;
763  sinfo_set_cd_matrix2(&plist,cd1_1,cd1_2,cd2_1,cd2_2);
764 
765  if (cpl_image_save(img, name, CPL_BPP_IEEE_FLOAT,
766  plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
767  sinfo_msg_error( "Cannot save the product %s",name);
768  cpl_propertylist_delete(plist) ;
769  return -1 ;
770  }
771  cpl_propertylist_delete(plist) ;
772  return 0;
773 
774 }
775 
776 
785 int
786 sinfo_new_set_wcs_image(cpl_image* img,
787  const char* name,
788  double cx,
789  double cy)
790 {
791  cpl_propertylist* plist=NULL;
792 
793  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
794  sinfo_msg_error( "getting header from frame %s",name);
795  cpl_propertylist_delete(plist) ;
796  return -1 ;
797  }
798  sinfo_new_change_plist_image(plist, cx, cy) ;
799 
800  if (cpl_image_save(img, name, CPL_BPP_IEEE_FLOAT,
801  plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
802  sinfo_msg_error( "Cannot save the product %s",name);
803  cpl_propertylist_delete(plist) ;
804  return -1 ;
805  }
806  cpl_propertylist_delete(plist) ;
807  return 0;
808 
809 }
810 
811 
821 int
822 sinfo_new_set_wcs_spectrum(cpl_image* img, const char* name, double clambda,
823  double dis, double cpix)
824 {
825  cpl_propertylist* plist=NULL;
826 
827  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
828  sinfo_msg_error( "getting header from frame %s",name);
829  cpl_propertylist_delete(plist) ;
830  return -1 ;
831  }
832  sinfo_new_change_plist_spectrum(plist, clambda, dis,cpix) ;
833 
834  if (cpl_image_save(img, name, CPL_BPP_IEEE_FLOAT,
835  plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
836  sinfo_msg_error( "Cannot save the product %s",name);
837  cpl_propertylist_delete(plist) ;
838  return -1 ;
839  }
840  cpl_propertylist_delete(plist) ;
841  return 0;
842 
843 }
855 static void
856 sinfo_new_change_plist_cube (cpl_propertylist * plist,
857  float cenLambda,
858  float dispersion,
859  int center_z,
860  float center_x,
861  float center_y )
862 {
863 
864 
865 
866 
867  double angle ;
868  float radangle ;
869  double cd1_1, cd1_2, cd2_1, cd2_2 ;
870  int sign_swap = -1;
871  char firsttext[2*FILE_NAME_SZ] ;
872 
873  double cdelt1=0;
874  double cdelt2=0;
875  double cdelt3=dispersion;
876 
877  double crpix1=center_x;
878  double crpix2=center_y;
879  int crpix3=center_z;
880 
881  double crval1=0;
882  double crval2=0;
883  double crval3=cenLambda;
884 
885 
886  strcpy(firsttext, "sinfo_rec_objnod -f \0") ;
887 
888  float pixelscale = sinfo_pfits_get_pixscale(plist)/2. ;
889 /*
890  double ra = sinfo_pfits_get_ra(plist) ;
891  double dec = sinfo_pfits_get_DEC(plist) ;
892 */
893 
894  //get better coordinate values
895  double ra=sinfo_pfits_get_targ_alpha(plist);
896  double dec=sinfo_pfits_get_targ_delta(plist);
897  //sinfo_msg("ra=%f",ra);
898  //sinfo_msg("dec=%f",dec);
899  ra=sinfo_hms2deg(ra);
900  dec=sinfo_sess2deg(dec);
901  //sinfo_msg("ra=%f",ra);
902  //sinfo_msg("dec=%f",dec);
903 
904  crval1=ra;
905  crval2=dec;
906 
907  angle = sinfo_pfits_get_posangle(plist) ;
908  /* in PUPIL data there is not posangle info: we reset the error */
909  if(cpl_error_get_code() != CPL_ERROR_NONE) {
910  cpl_error_reset();
911  }
912  cdelt1=sign_swap*pixelscale / 3600.;
913  cdelt2= +pixelscale / 3600.;
914 
915 
916  radangle = angle * PI_NUMB / 180. ;
917  cd1_1 = +cdelt1*cos(radangle);
918  cd1_2 = -cdelt2*sin(radangle);
919  cd2_1 = +cdelt1*sin(radangle);
920  cd2_2 = +cdelt2*cos(radangle);
921 
922 
923  sinfo_set_coord1(&plist,crpix1,crval1,cdelt1,1);
924  sinfo_set_coord2(&plist,crpix2,crval2,cdelt2,1);
925  sinfo_set_coord3(&plist,crpix3,crval3,cdelt3);
926  sinfo_set_cd_matrix2(&plist,cd1_1,cd1_2,cd2_1,cd2_2);
927  sinfo_set_cd_matrix3(&plist,0,0,0,0,dispersion);
928 
929 
930  }
931 
932 
933 
934 
944 static void
945 sinfo_set_coord1(cpl_propertylist** plist,
946  const double crpix1,
947  const double crval1,
948  const double cdelt1,
949  const int is_science)
950 {
951 
952  if(is_science) {
953  cpl_propertylist_erase_regexp(*plist, "^CTYPE1",0);
954  cpl_propertylist_insert_after_string(*plist,"EXPTIME","CTYPE1","RA---TAN");
955  cpl_propertylist_set_comment(*plist, "CTYPE1", "Projected Rectascension");
956  } else {
957  cpl_propertylist_erase_regexp(*plist, "^CTYPE1",0);
958  cpl_propertylist_insert_after_string(*plist,"EXPTIME","CTYPE1","PIPXEL");
959  cpl_propertylist_set_comment(*plist, "CTYPE1", "pixel unit");
960  }
961 
962  cpl_propertylist_erase_regexp(*plist, "^CRPIX1",0);
963  cpl_propertylist_insert_after_double(*plist,"CTYPE1","CRPIX1", crpix1) ;
964  cpl_propertylist_set_comment(*plist, "CRPIX1","Reference pixel in RA" ) ;
965 
966  cpl_propertylist_erase_regexp(*plist, "^CRVAL1",0);
967  cpl_propertylist_insert_after_double(*plist, "CRPIX1", "CRVAL1", crval1 ) ;
968  cpl_propertylist_set_comment(*plist, "CRVAL1","Reference RA" ) ;
969 
970  cpl_propertylist_erase_regexp(*plist, "^CDELT1",0);
971  cpl_propertylist_insert_after_double(*plist,"CRVAL1","CDELT1",cdelt1 ) ;
972  cpl_propertylist_set_comment(*plist, "CDELT1","pixel scale" ) ;
973  if(is_science) {
974  cpl_propertylist_erase_regexp(*plist, "^CUNIT1",0);
975  cpl_propertylist_insert_after_string(*plist, "CDELT1", "CUNIT1", "deg" ) ;
976  cpl_propertylist_set_comment(*plist, "CUNIT1","RA-UNIT" ) ;
977  } else {
978  cpl_propertylist_erase_regexp(*plist, "^CUNIT1",0);
979  cpl_propertylist_insert_after_string(*plist, "CDELT1", "CUNIT1", "PIXEL" ) ;
980  cpl_propertylist_set_comment(*plist, "CUNIT1","pixel unit" ) ;
981  }
982  return;
983 }
984 
985 
994 static void
995 sinfo_set_coord2(cpl_propertylist** plist,
996  const double crpix2,
997  const double crval2,
998  const double cdelt2,
999  const int is_science)
1000 {
1001  if(is_science) {
1002  cpl_propertylist_erase_regexp(*plist, "^CTYPE2",0);
1003  cpl_propertylist_insert_after_string(*plist,"CUNIT1","CTYPE2","DEC--TAN");
1004  cpl_propertylist_set_comment(*plist, "CTYPE2", "Projected Declination") ;
1005  } else {
1006  cpl_propertylist_erase_regexp(*plist, "^CTYPE2",0);
1007  cpl_propertylist_insert_after_string(*plist,"CUNIT1","CTYPE2","PIXEL");
1008  cpl_propertylist_set_comment(*plist, "CTYPE2", "pixel unit") ;
1009  }
1010  cpl_propertylist_erase_regexp(*plist, "^CRPIX2",0);
1011  cpl_propertylist_insert_after_double(*plist,"CTYPE2","CRPIX2",crpix2 ) ;
1012  cpl_propertylist_set_comment(*plist, "CRPIX2", "Reference pixel in DEC") ;
1013 
1014  cpl_propertylist_erase_regexp(*plist,"^CRVAL2",0);
1015  cpl_propertylist_insert_after_double(*plist,"CRPIX2","CRVAL2",crval2) ;
1016  cpl_propertylist_set_comment(*plist,"CRVAL2","Reference DEC") ;
1017 
1018  cpl_propertylist_erase_regexp(*plist,"^CDELT2",0);
1019  cpl_propertylist_insert_after_double(*plist,"CRVAL2","CDELT2",cdelt2 ) ;
1020  cpl_propertylist_set_comment(*plist,"CDELT2","pixel scale") ;
1021  if(is_science) {
1022  cpl_propertylist_erase_regexp(*plist,"^CUNIT2",0);
1023  cpl_propertylist_insert_after_string(*plist,"CDELT2","CUNIT2", "deg" ) ;
1024  cpl_propertylist_set_comment(*plist,"CUNIT2","DEC-UNIT") ;
1025  } else {
1026  cpl_propertylist_erase_regexp(*plist,"^CUNIT2",0);
1027  cpl_propertylist_insert_after_string(*plist,"CDELT2","CUNIT2", "PIXEL" ) ;
1028  cpl_propertylist_set_comment(*plist,"CUNIT2","pixel unitT") ;
1029  }
1030 
1031 
1032 }
1033 
1034 
1043 static void
1044 sinfo_set_coord3(cpl_propertylist** plist,
1045  const int crpix3,
1046  const double crval3,
1047  const double cdelt3)
1048 {
1049  cpl_propertylist_erase_regexp(*plist, "^CTYPE3",0);
1050  cpl_propertylist_insert_after_string(*plist,"EXPTIME", "CTYPE3", "WAVE" ) ;
1051  cpl_propertylist_set_comment(*plist,"CTYPE3","wavelength axis in microns") ;
1052 
1053  cpl_propertylist_erase_regexp(*plist, "^CRPIX3",0);
1054  cpl_propertylist_insert_after_double(*plist,"CTYPE3","CRPIX3", (double)crpix3 ) ;
1055  cpl_propertylist_set_comment(*plist, "CRPIX3", "Reference pixel in z") ;
1056 
1057  cpl_propertylist_erase_regexp(*plist, "^CRVAL3",0);
1058  cpl_propertylist_insert_after_double(*plist,"CRPIX3", "CRVAL3", crval3) ;
1059  cpl_propertylist_set_comment(*plist, "CRVAL3", "central wavelength") ;
1060 
1061  cpl_propertylist_erase_regexp(*plist, "^CDELT3",0);
1062 
1063  cpl_propertylist_insert_after_double(*plist,"CRVAL3","CDELT3",cdelt3) ;
1064  cpl_propertylist_set_comment(*plist, "CDELT3", "microns per pixel") ;
1065 
1066  cpl_propertylist_erase_regexp(*plist, "^CUNIT3",0);
1067  cpl_propertylist_insert_after_string(*plist,"CDELT3", "CUNIT3", "um" ) ;
1068  cpl_propertylist_set_comment(*plist, "CUNIT3", "spectral unit" ) ;
1069 
1070  cpl_propertylist_erase_regexp(*plist, "^SPECSYS",0);
1071  cpl_propertylist_insert_after_string(*plist,"CUNIT3", "SPECSYS", "TOPOCENT" ) ;
1072  cpl_propertylist_set_comment(*plist, "SPECSYS", "Coordinate reference frame" ) ;
1073 }
1074 
1075 
1086 static void
1087 sinfo_set_cd_matrix2(cpl_propertylist** plist,
1088  const double cd1_1,
1089  const double cd1_2,
1090  const double cd2_1,
1091  const double cd2_2)
1092 {
1093 
1094  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD1_1",0));
1095  check_nomsg(cpl_propertylist_insert_after_double(*plist,"EXPTIME",
1096  "CD1_1", cd1_1 )) ;
1097  check_nomsg(cpl_propertylist_set_comment(*plist, "CD1_1",
1098  "CD rotation matrix" )) ;
1099 
1100  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD1_2",0));
1101  check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD1_1",
1102  "CD1_2", cd1_2 )) ;
1103  check_nomsg(cpl_propertylist_set_comment(*plist, "CD1_2",
1104  "CD rotation matrix" )) ;
1105 
1106  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD2_1",0));
1107  check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD1_2",
1108  "CD2_1", cd2_1 )) ;
1109  check_nomsg(cpl_propertylist_set_comment(*plist, "CD2_1",
1110  "CD rotation matrix" )) ;
1111 
1112  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD2_2",0));
1113  check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD2_1",
1114  "CD2_2", cd2_2 )) ;
1115  check_nomsg(cpl_propertylist_set_comment(*plist, "CD2_2",
1116  "CD rotation matrix" )) ;
1117 
1118  cleanup:
1119  return;
1120 
1121 
1122 }
1123 
1124 
1137 static void
1138 sinfo_set_cd_matrix3(cpl_propertylist** plist,
1139  const double cd1_3,
1140  const double cd2_3,
1141  const double cd3_1,
1142  const double cd3_2,
1143  const double cd3_3)
1144 {
1145 
1146 
1147  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD1_3",0));
1148  check_nomsg(cpl_propertylist_insert_after_double(*plist,"EXPTIME",
1149  "CD1_3", cd1_3 )) ;
1150  check_nomsg(cpl_propertylist_set_comment(*plist, "CD1_3",
1151  "CD rotation matrix" )) ;
1152 
1153 
1154  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD2_3",0));
1155  check_nomsg(cpl_propertylist_insert_after_double(*plist,"CD1_3",
1156  "CD2_3", cd2_3 )) ;
1157  check_nomsg(cpl_propertylist_set_comment(*plist, "CD2_3",
1158  "CD rotation matrix" )) ;
1159 
1160 
1161 
1162  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD3_1",0));
1163  check_nomsg(cpl_propertylist_insert_after_double(*plist,"CD2_3",
1164  "CD3_1", cd3_1 )) ;
1165  check_nomsg(cpl_propertylist_set_comment(*plist, "CD3_1",
1166  "CD rotation matrix" )) ;
1167 
1168  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD3_2",0));
1169  check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD3_1",
1170  "CD3_2", cd3_2 )) ;
1171  check_nomsg(cpl_propertylist_set_comment(*plist, "CD3_2",
1172  "CD rotation matrix" )) ;
1173 
1174  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD3_3",0));
1175  check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD3_2",
1176  "CD3_3", cd3_3 )) ;
1177  check_nomsg(cpl_propertylist_set_comment(*plist, "CD3_3",
1178  "CD rotation matrix" )) ;
1179 
1180  cleanup:
1181  return;
1182 
1183 
1184 }
1185 
1186 
1195 static void
1196 sinfo_set_spect_coord1(cpl_propertylist** plist,
1197  const int crpix1,
1198  const double crval1,
1199  const double cdelt1)
1200 {
1201 
1202  cpl_propertylist_erase_regexp(*plist, "^CTYPE1",0);
1203  cpl_propertylist_insert_after_string(*plist,"EXPTIME", "CTYPE1", "PIXEL");
1204  cpl_propertylist_set_comment(*plist, "CTYPE1", "Pixel coordinate system.");
1205 
1206  cpl_propertylist_erase_regexp(*plist, "^CRPIX1",0);
1207  cpl_propertylist_insert_after_double(*plist, "CTYPE1", "CRPIX1", (double)crpix1 ) ;
1208  cpl_propertylist_set_comment(*plist, "CRPIX1", "Reference pixel in x") ;
1209 
1210  cpl_propertylist_erase_regexp(*plist, "^CRVAL1",0);
1211  cpl_propertylist_insert_after_double(*plist,"CRPIX1", "CRVAL1", crval1 ) ;
1212  cpl_propertylist_set_comment(*plist, "CRVAL1", "value of ref pixel.") ;
1213 
1214  cpl_propertylist_erase_regexp(*plist, "^CDELT1",0);
1215  cpl_propertylist_insert_after_double(*plist,"CRVAL1", "CDELT1", cdelt1 ) ;
1216  cpl_propertylist_set_comment(*plist,"CDELT1", "pixel scale") ;
1217 
1218 
1219  cpl_propertylist_erase_regexp(*plist, "^CUNIT1",0);
1220  cpl_propertylist_insert_after_string(*plist,"CDELT1", "CUNIT1", "Pixel" );
1221  cpl_propertylist_set_comment(*plist, "CUNIT1", "spectral unit" );
1222 
1223 }
1224 
1225 
1226 
1227 
1228 
1237 static void
1238 sinfo_set_spect_coord2(cpl_propertylist** plist,
1239  const int crpix2,
1240  const double crval2,
1241  const double cdelt2)
1242 {
1243 
1244  cpl_propertylist_erase_regexp(*plist, "^CTYPE2",0);
1245  cpl_propertylist_insert_after_string(*plist, "EXPTIME","CTYPE2","WAVE" );
1246  cpl_propertylist_set_comment(*plist,"CTYPE2","wavelength axis in microns");
1247 
1248  cpl_propertylist_erase_regexp(*plist, "^CRPIX2",0);
1249  cpl_propertylist_insert_after_double(*plist, "CTYPE2", "CRPIX2",(double)crpix2 ) ;
1250  cpl_propertylist_set_comment(*plist, "CRPIX2", "Reference pixel in x") ;
1251 
1252  cpl_propertylist_erase_regexp(*plist, "^CRVAL2",0);
1253  cpl_propertylist_insert_after_double(*plist, "CRPIX2","CRVAL2",crval2 ) ;
1254  cpl_propertylist_set_comment(*plist,"CRVAL2", "central wavelength") ;
1255 
1256  cpl_propertylist_erase_regexp(*plist, "^CDELT2",0);
1257  cpl_propertylist_insert_after_double(*plist, "CRVAL2", "CDELT2",cdelt2);
1258  cpl_propertylist_set_comment(*plist,"CDELT2", "microns per pixel");
1259 
1260  cpl_propertylist_erase_regexp(*plist, "^CUNIT2",0);
1261  cpl_propertylist_insert_after_string(*plist,"CDELT2", "CUNIT2", "um");
1262  cpl_propertylist_set_comment(*plist, "CUNIT2", "spectral unit" );
1263 
1264 
1265 }
1275 static void
1276 sinfo_new_change_plist_spectrum (cpl_propertylist * plist,
1277  double cenLambda,
1278  double dispersion,
1279  int cenpix)
1280 {
1281 
1282  int crpix1=1;
1283  double crval1=1;
1284  double cdelt1=1;
1285 
1286  int crpix2=cenpix;
1287  double crval2=cenLambda;
1288  double cdelt2=dispersion;
1289 
1290 
1291 
1292  cpl_propertylist_erase_regexp(plist, "^CTYPE3",0);
1293  cpl_propertylist_erase_regexp(plist, "^CRPIX3",0);
1294  cpl_propertylist_erase_regexp(plist, "^CRVAL3",0);
1295  cpl_propertylist_erase_regexp(plist, "^CDELT3",0);
1296  cpl_propertylist_erase_regexp(plist, "^CUNIT3",0);
1297 
1298  cpl_propertylist_erase_regexp(plist, "^CTYPE2",0);
1299  cpl_propertylist_erase_regexp(plist, "^CRPIX2",0);
1300  cpl_propertylist_erase_regexp(plist, "^CRVAL2",0);
1301  cpl_propertylist_erase_regexp(plist, "^CDELT2",0);
1302  cpl_propertylist_erase_regexp(plist, "^CUNIT2",0);
1303 
1304 
1305  cpl_propertylist_erase_regexp(plist, "^CD1_1",0);
1306  cpl_propertylist_erase_regexp(plist, "^CD1_2",0);
1307  cpl_propertylist_erase_regexp(plist, "^CD2_1",0);
1308  cpl_propertylist_erase_regexp(plist, "^CD2_2",0);
1309 
1310 
1311 
1312 
1313  sinfo_set_spect_coord1(&plist,crpix1,crval1,cdelt1);
1314  sinfo_set_spect_coord2(&plist,crpix2,crval2,cdelt2);
1315 
1316 
1317 
1318 }
1328 static void
1329 sinfo_new_change_plist_image (cpl_propertylist * plist,
1330  float center_x,
1331  float center_y )
1332 {
1333 
1334 
1335 
1336 
1337  double angle ;
1338  float radangle ;
1339  float cd1_1, cd1_2, cd2_1, cd2_2 ;
1340  char firsttext[2*FILE_NAME_SZ] ;
1341  int sign_swap = -1;
1342 
1343 
1344  double cdelt1=0;
1345  double cdelt2=0;
1346 
1347  double crpix1=center_x;
1348  double crpix2=center_y;
1349 
1350  double crval1=0;
1351  double crval2=0;
1352 
1353 
1354 
1355 
1356  strcpy(firsttext, "sinfo_rec_objnod -f \0") ;
1357 
1358  float pixelscale = sinfo_pfits_get_pixscale(plist)/2. ;
1359 /*
1360  double ra = sinfo_pfits_get_ra(plist) ;
1361  double dec = sinfo_pfits_get_DEC(plist) ;
1362 */
1363 
1364 
1365 
1366  //get better coordinate values
1367  double ra=sinfo_pfits_get_targ_alpha(plist);
1368  double dec=sinfo_pfits_get_targ_delta(plist);
1369  ra=sinfo_hms2deg(ra);
1370  dec=sinfo_sess2deg(dec);
1371 
1372 
1373 
1374  crval1=ra;
1375  crval2=dec;
1376 
1377  angle = sinfo_pfits_get_posangle(plist) ;
1378  /* in PUPIL data there is not posangle info: we reset the error */
1379  if(cpl_error_get_code() != CPL_ERROR_NONE) {
1380  cpl_error_reset();
1381  }
1382 
1383  radangle = angle * PI_NUMB / 180. ;
1384 
1385  cdelt1=sign_swap * pixelscale / 3600. ;
1386  cdelt2= pixelscale / 3600. ;
1387 
1388 
1389  cd1_1 = +cdelt1*cos(radangle) ;
1390  cd1_2 = -cdelt2*sin(radangle) ;
1391  cd2_1 = +cdelt1*sin(radangle) ;
1392  cd2_2 = +cdelt2*cos(radangle) ;
1393 
1394 
1395 
1396 
1397 
1398  check_nomsg(sinfo_set_coord1(&plist,crpix1,crval1,cdelt1,1));
1399  check_nomsg(sinfo_set_coord2(&plist,crpix2,crval2,cdelt2,1));
1400  check_nomsg(sinfo_set_cd_matrix2(&plist,cd1_1,cd1_2,cd2_1,cd2_2));
1401 
1402 
1403  cleanup:
1404  return;
1405 }
1406 
1413 /* TODO: not used */
1414 cpl_imagelist**
1415 sinfo_new_sinfoni_correct_median(cpl_imagelist** cubes, const int n_cubes)
1416 {
1417  int i=0;
1418  cpl_imagelist** cubes_cor=NULL;
1419  double local_median=0;
1420  int z=0;
1421  cpl_image* i_img=NULL;
1422  cpl_image* o_img=NULL;
1423 
1424 
1425  if ( cubes == NULL ) {
1426  sinfo_msg_error ("no cube list given!") ;
1427  return NULL ;
1428  }
1429  if ( n_cubes <= 0 ) {
1430  sinfo_msg_error ("wrong number of data cubes in list!") ;
1431  return NULL ;
1432  }
1433 
1434  cubes_cor = (cpl_imagelist**) cpl_calloc (n_cubes, sizeof (cpl_imagelist*)) ;
1435 
1436  for ( i = 0 ; i < n_cubes ; i++ ) {
1437  cubes_cor[i] = cpl_imagelist_new();
1438  for(z=0;z< cpl_imagelist_get_size(cubes[i]); z++) {
1439  i_img=cpl_imagelist_get(cubes[i],z);
1440  local_median=cpl_image_get_median(i_img);;
1441  o_img=cpl_image_duplicate(i_img);
1442  if(!isnan(local_median)) {
1443  cpl_image_subtract_scalar(o_img,local_median);
1444  }
1445  cpl_imagelist_set(cubes_cor[i],o_img,z);
1446  }
1447  }
1448 
1449  return cubes_cor;
1450 }
1451 
1458 int sinfo_new_sinfoni_correct_median_it(cpl_imagelist** inp)
1459 {
1460 
1461  for(int z=0;z< cpl_imagelist_get_size((*inp)); z++) {
1462  cpl_image* img=cpl_imagelist_get((*inp),z);
1463  double local_median=sinfo_new_my_median_image(img);
1464  if(!isnan(local_median)) {
1465  cpl_image_subtract_scalar(img,local_median);
1466  } else {
1467  sinfo_msg_error("local_median is NAN");
1468  }
1469  cpl_imagelist_set((*inp),img,z);
1470  }
1471 
1472  return 0;
1473 }
1474 
1483 /* TODO: not used */
1484 cpl_imagelist** sinfo_new_sinfoni_correct_sky(cpl_imagelist** cubes,
1485  const int nc,
1486  cpl_imagelist* sky_cube)
1487 
1488 {
1489  cpl_imagelist** cubes_sky=NULL;
1490  int x=0;
1491  int y=0;
1492  int z=0;
1493  int i=0;
1494  float k=0.5;
1495  int ovr=0;
1496  int ks=0;
1497  int nclip=0;
1498  double med=0;
1499  double avg=0;
1500  double sig=0;
1501  int msk_sum=0;
1502  double val_msk_sum=0;
1503  cpl_vector* val=NULL;
1504  cpl_vector* msk=NULL;
1505  int ilx=0;
1506  int ily=0;
1507  int inp=0;
1508 
1509 
1510  int sky_lx=0;
1511  /* int sky_ly=0; */
1512 
1513 
1514  cpl_image* i_img=NULL;
1515 
1516 
1517 
1518  if ( cubes == NULL ) {
1519  sinfo_msg_error ("no cube list given!") ;
1520  return NULL ;
1521  }
1522  ilx=cpl_image_get_size_x(cpl_imagelist_get(cubes[0],0));
1523  ily=cpl_image_get_size_y(cpl_imagelist_get(cubes[0],0));
1524  inp=cpl_imagelist_get_size(cubes[0]);
1525 
1526 
1527  sky_lx=cpl_image_get_size_x(cpl_imagelist_get(sky_cube,0));
1528  /* sky_ly=cpl_image_get_size_y(cpl_imagelist_get(sky_cube,0)); */
1529  if ( nc <= 0 ) {
1530  sinfo_msg_error ("wrong number of data cubes in list!") ;
1531  return NULL ;
1532  }
1533 
1534  cubes_sky = (cpl_imagelist**) cpl_calloc (nc, sizeof (cpl_imagelist*)) ;
1535  float* pidata;
1536  for(z=0;z< inp; z++) {
1537  cpl_image* sky_img=cpl_imagelist_get(sky_cube,z);
1538  float* p_sky_data=cpl_image_get_data_float(sky_img);
1539  for(y=0;y< ily; y++) {
1540  for(x=0;x< ilx; x++) {
1541  /* here we start to do a k-s clipping */
1542  msk=cpl_vector_new(nc);
1543  for (i=0;i<nc;i++) {
1544  cpl_vector_set(msk,i,1);
1545  }
1546  nclip=0;
1547  for (ks=0;ks<nc;ks++) {
1548  sig=0;
1549  med=0;
1550  ovr=0;
1551  val=cpl_vector_new(nc-nclip);
1552 
1553  for ( i = 0 ; i < nc ; i++ ) {
1554  i_img=cpl_imagelist_get(cubes[i],z);
1555  pidata=cpl_image_get_data_float(i_img);
1556  if ((!isnan(pidata[x+y*ilx])) &&
1557  (cpl_vector_get(msk,i) != 0) ) {
1558  cpl_vector_set(val,ovr,(double)pidata[x+y*ilx]);
1559  ovr++;
1560  }
1561  }
1562 
1563  if(ovr>0) {
1564  avg=cpl_vector_get_mean(val);
1565  med=cpl_vector_get_median_const(val);
1566  if(ovr>1) {
1567  sig=cpl_vector_get_stdev(val);
1568  } else {
1569  sig=0;
1570  }
1571  } else {
1572  avg=cpl_vector_get(val,0);
1573  med=avg;
1574  sig=0;
1575  }
1576 
1577  cpl_vector_delete(val);
1578  for ( i = 0 ; i < nc ; i++ ) {
1579  i_img=cpl_imagelist_get(cubes[i],z);
1580  pidata=cpl_image_get_data_float(i_img);
1581  /* Do k-s clipping at each pixel */
1582  if ((!isnan(pidata[x+y*ilx])) &&
1583  (cpl_vector_get(msk,i) != 0)) {
1584  if(abs((pidata[x+y*ilx]-med))> k*sig) {
1585  cpl_vector_set(msk,i,0);
1586  nclip++;
1587  }
1588  }
1589  }
1590  }/* end of k-s clipping */
1591  msk_sum=0;
1592  val_msk_sum=0;
1593  for ( i = 0 ; i < nc ; i++ ) {
1594  /* computes sky at each point */
1595  if (!isnan(pidata[x+y*ilx])) {
1596  msk_sum+=cpl_vector_get(msk,i);
1597  val_msk_sum+=pidata[x+y*ilx]*
1598  cpl_vector_get(msk,i);
1599  }
1600  }
1601  p_sky_data[x+y*sky_lx]=val_msk_sum/msk_sum;
1602  cpl_vector_delete(msk);
1603  } /* end loop over x */
1604  } /* end loop over y */
1605  } /* end loop over z */
1606  for ( i = 0 ; i < nc ; i++ ) {
1607  cubes_sky[i]=cpl_imagelist_duplicate(cubes[i]);
1608  /* subtract the variable clean sky */
1609  cpl_imagelist_subtract(cubes_sky[i],sky_cube);
1610 
1611  }
1612 
1613 
1614  return cubes_sky;
1615 }
1616 
1631 /* TODO: not used */
1632 cpl_imagelist** sinfo_new_sinfoni_correct_sky2(cpl_imagelist** cubes,
1633  const int nc,
1634  cpl_imagelist* sky_cube,
1635  cpl_imagelist* med_cube,
1636  cpl_imagelist* msk_cube,
1637  cpl_imagelist* avg_cube,
1638  cpl_imagelist* sig_cube,
1639  cpl_imagelist* ovr_cube)
1640 {
1641  cpl_imagelist** cubes_sky=NULL;
1642  int x=0;
1643  int y=0;
1644  int z=0;
1645  int i=0;
1646  float k=0.5;
1647  int ovr=0;
1648  int ks=0;
1649  int nclip=0;
1650  double med=0;
1651  double avg=0;
1652  double sig=0;
1653  int msk_sum=0;
1654  double val_msk_sum=0;
1655  cpl_vector* val=NULL;
1656  cpl_vector* msk=NULL;
1657 
1658  int ilx=0;
1659  int ily=0;
1660  int inp=0;
1661 
1662  int ovr_lx=0;
1663  int msk_lx=0;
1664  int avg_lx=0;
1665  int sig_lx=0;
1666  int sky_lx=0;
1667  int med_lx=0;
1668 
1669  float* pidata=NULL;
1670 
1671  if ( cubes == NULL ) {
1672  sinfo_msg_error ("no cube list given!") ;
1673  return NULL ;
1674  }
1675 
1676  ilx=cpl_image_get_size_x(cpl_imagelist_get(cubes[0],0));
1677  ily=cpl_image_get_size_y(cpl_imagelist_get(cubes[0],0));
1678  inp=cpl_imagelist_get_size(cubes[0]);
1679 
1680  if ( nc <= 0 ) {
1681  sinfo_msg_error ("wrong number of data cubes in list!") ;
1682  return NULL ;
1683  }
1684 
1685  cubes_sky = (cpl_imagelist**) cpl_calloc (nc, sizeof (cpl_imagelist*)) ;
1686 
1687  ovr_lx=ilx;
1688  msk_lx=ilx;
1689  avg_lx=ilx;
1690  sig_lx=ilx;
1691  sky_lx=ilx;
1692  med_lx=ilx;
1693 
1694  for(z=0;z< inp; z++) {
1695  float* p_ovr_data=cpl_image_get_data_float(cpl_imagelist_get(ovr_cube,z));
1696  float* p_msk_data=cpl_image_get_data_float(cpl_imagelist_get(msk_cube,z));
1697  float* p_avg_data=cpl_image_get_data_float(cpl_imagelist_get(avg_cube,z));
1698  float* p_sig_data=cpl_image_get_data_float(cpl_imagelist_get(sig_cube,z));
1699  float* p_sky_data=cpl_image_get_data_float(cpl_imagelist_get(sky_cube,z));
1700  float* p_med_data=cpl_image_get_data_float(cpl_imagelist_get(med_cube,z));
1701 
1702 
1703  for(y=0;y< ily; y++) {
1704  for(x=0;x< ilx; x++) {
1705  /* here we start to do a k-s clipping */
1706  msk=cpl_vector_new(nc);
1707  for (i=0;i<nc;i++) {
1708  cpl_vector_set(msk,i,1);
1709  }
1710  p_ovr_data[x+y*ovr_lx]=nc;
1711  p_msk_data[x+y*msk_lx]=nc;
1712  nclip=0;
1713  for (ks=0;ks<nc;ks++) {
1714  sig=0;
1715  med=0;
1716  ovr=0;
1717  val=cpl_vector_new(nc-nclip);
1718 
1719  for ( i = 0 ; i < nc ; i++ ) {
1720  pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
1721  if ((!isnan(pidata[x+y*ilx])) &&
1722  (cpl_vector_get(msk,i) != 0) ) {
1723  cpl_vector_set(val,ovr,(double)pidata[x+y*ilx]);
1724  ovr++;
1725  }
1726  }
1727 
1728  if(ovr>1) {
1729  avg=cpl_vector_get_mean(val);
1730  med=cpl_vector_get_median_const(val);
1731  sig=cpl_vector_get_stdev(val);
1732  } else {
1733  avg=cpl_vector_get(val,0);
1734  med=avg;
1735  sig=0;
1736  }
1737 
1738  p_med_data[x+y*med_lx]=med;
1739  p_avg_data[x+y*avg_lx]=avg;
1740  p_sig_data[x+y*sig_lx]=sig;
1741  cpl_vector_delete(val);
1742  for ( i = 0 ; i < nc ; i++ ) {
1743  pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
1744  /* Do k-s clipping at each pixel */
1745  if ((!isnan(pidata[x+y*ilx])) &&
1746  (cpl_vector_get(msk,i) != 0)) {
1747  if(abs((pidata[x+y*ilx]-med))> k*sig) {
1748  /* pidata[x+y*ilx]=0; */
1749  p_msk_data[x+y*msk_lx]-=1;
1750  cpl_vector_set(msk,i,0);
1751  nclip++;
1752  }
1753  }
1754  }
1755  }/* end of k-s clipping */
1756  msk_sum=0;
1757  val_msk_sum=0;
1758  for ( i = 0 ; i < nc ; i++ ) {
1759  pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
1760  /* computes sky at each point */
1761  if (!isnan(pidata[x+y*ilx])) {
1762  /*
1763  msk_sum+=p_msk_data[x+y*msk_lx];
1764  val_msk_sum+=pidata[x+y*cubes[i]->lx]*
1765  p_msk_data[x+y*msk_lx];
1766  */
1767  msk_sum+=cpl_vector_get(msk,i);
1768  val_msk_sum+=pidata[x+y*ilx]*
1769  cpl_vector_get(msk,i);
1770  }
1771  }
1772  p_sky_data[x+y*sky_lx]=val_msk_sum/msk_sum;
1773  cpl_vector_delete(msk);
1774  } /* end loop over x */
1775  } /* end loop over y */
1776  } /* end loop over z */
1777  for ( i = 0 ; i < nc ; i++ ) {
1778  cubes_sky[i]=cpl_imagelist_duplicate(cubes[i]);
1779  /* subtract the variable clean sky */
1780  cpl_imagelist_subtract(cubes_sky[i],sky_cube);
1781  }
1782 
1783 
1784  return cubes_sky;
1785 }
1786 
1787 
1800 int
1801 sinfo_new_assign_offset(const int n,
1802  const char* name,
1803  float* offsetx,
1804  float* offsety,
1805  const float ref_offx,
1806  const float ref_offy)
1807 {
1808 
1809  float offx=0;
1810  float offy=0;
1811  double mjd_obs=0;
1812  /*
1813  double pixelscale=0;
1814  double angle=0;
1815  double radangle=0;
1816  double cd1_1=0;
1817  double cd1_2=0;
1818  double cd2_1=0;
1819  double cd2_2=0;
1820  double ra=0;
1821  double dec=0;
1822  */
1823 
1824  cpl_propertylist * plist=NULL;
1825  sinfo_msg_debug("Assign offsets");
1826 
1827  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
1828  sinfo_msg_error( "getting header from reference frame %s",name);
1829  cpl_propertylist_delete(plist) ;
1830  return -1 ;
1831  }
1832 
1833  offx = sinfo_pfits_get_cumoffsetx(plist) - ref_offx ; /* was - */
1834  if(cpl_error_get_code() != CPL_ERROR_NONE) {
1835  sinfo_msg_warning(" could not read fits header keyword cummoffsetx!") ;
1836  sinfo_msg_warning(" Set relative offset to 0 - %f!",ref_offx) ;
1837  offx = - ref_offx;
1838  cpl_error_reset();
1839  /* return -1 ; */
1840  }
1841 
1842  offy = sinfo_pfits_get_cumoffsety(plist) - ref_offy ; /* was - */
1843  if(cpl_error_get_code() != CPL_ERROR_NONE) {
1844  sinfo_msg_warning(" could not read fits header keyword! cumoffsety") ;
1845  sinfo_msg_warning(" Set relative offset to 0 - %f!",ref_offx) ;
1846  offy = - ref_offy;
1847  cpl_error_reset();
1848  /* return -1 ; */
1849  }
1850  sinfo_msg_debug("offx=%f offy=%f",offx,offy);
1851 
1852  if (cpl_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
1853  mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
1854  } else {
1855  sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
1856  cpl_propertylist_delete(plist) ;
1857  return -1;
1858  }
1859 
1860  cpl_propertylist_delete(plist) ;
1861 
1862  if (mjd_obs > 53825. ) {
1863  /* April 1st 2006 */
1864  //sinfo_msg("New cumoffset setting convention");
1865  sinfo_new_array_set_value(offsetx,2*offx,n);
1866  sinfo_new_array_set_value(offsety,2*offy,n);
1867  } else if ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
1868  /* after detector's upgrade */
1869  /*
1870  sinfo_new_array_set_value(offsetx,-offx*2,n);
1871  sinfo_new_array_set_value(offsety,+offy*2,n);
1872  */
1873  sinfo_new_array_set_value(offsetx,-2*offx,n);
1874  sinfo_new_array_set_value(offsety,2*offy,n);
1875  } else {
1876  /* before detector's upgrade */
1877  /*
1878  sinfo_new_array_set_value(offsetx,+offx*2,n);
1879  sinfo_new_array_set_value(offsety,-offy*2,n);
1880  */
1881  sinfo_new_array_set_value(offsetx,2*offx,n);
1882  sinfo_new_array_set_value(offsety,-2*offy,n);
1883  }
1884 
1885  return 0;
1886 
1887 
1888 }
1889 
1890 
1891 
1892 
1893 
1906 int
1907 sinfo_new_assign_offset2(const int n,
1908  const char* name,
1909  float* offsetx,
1910  float* offsety,
1911  const float ref_offx,
1912  const float ref_offy)
1913 {
1914 
1915  float offx=0;
1916  float offy=0;
1917  double mjd_obs=0;
1918 
1919  cpl_propertylist * plist=NULL;
1920  sinfo_msg_debug("Assign offsets as set by user");
1921  offx = offsetx[n] - ref_offx ; /* was - */
1922  offy = offsety[n] - ref_offy ; /* was - */
1923  sinfo_msg_debug("offx=%f offy=%f",offx,offy);
1924 
1925  sinfo_msg_debug("Assign offsets");
1926 
1927  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
1928  sinfo_msg_error( "getting header from reference frame %s",name);
1929  cpl_propertylist_delete(plist) ;
1930  return -1 ;
1931  }
1932 
1933  if (cpl_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
1934  mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
1935  } else {
1936  sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
1937  cpl_propertylist_delete(plist) ;
1938  return -1;
1939  }
1940  cpl_propertylist_delete(plist) ;
1941 
1942  //sinfo_new_array_set_value(offsetx,-2*offx,n);
1943  //sinfo_new_array_set_value(offsety,2*offy,n);
1944 
1945  if (mjd_obs > 53825. ) {
1946  /* April 1st 2006 */
1947  //sinfo_msg("New cumoffset setting convention");
1948  sinfo_new_array_set_value(offsetx,2*offx,n);
1949  sinfo_new_array_set_value(offsety,2*offy,n);
1950  } else if ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
1951  /* after detector's upgrade */
1952  /*
1953  sinfo_new_array_set_value(offsetx,-offx*2,n);
1954  sinfo_new_array_set_value(offsety,+offy*2,n);
1955  */
1956  sinfo_new_array_set_value(offsetx,-2*offx,n);
1957  sinfo_new_array_set_value(offsety,2*offy,n);
1958  } else {
1959  /* before detector's upgrade */
1960  /*
1961  sinfo_new_array_set_value(offsetx,+offx*2,n);
1962  sinfo_new_array_set_value(offsety,-offy*2,n);
1963  */
1964  sinfo_new_array_set_value(offsetx,2*offx,n);
1965  sinfo_new_array_set_value(offsety,-2*offy,n);
1966  }
1967 
1968 
1969  return 0;
1970 
1971 
1972 }
1973 
1974 
1986 /* TODO: not used */
1987 int
1988 sinfo_new_object_assign_offset(const char* name,
1989  const int n,
1990  double* ref_offx,
1991  double* ref_offy,
1992  float** offsetx,
1993  float** offsety)
1994 {
1995 
1996  float offx=0;
1997  float offy=0;
1998  double mjd_obs=0;
1999  cpl_propertylist * plist=NULL;
2000  sinfo_msg_debug("Assign offsets");
2001 
2002  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
2003  sinfo_msg_error( "getting header from reference frame %s",name);
2004  cpl_propertylist_delete(plist) ;
2005  return -1 ;
2006  }
2007  if ( n == 0 ) {
2008 
2009  *ref_offx = sinfo_pfits_get_cumoffsetx(plist) ;
2010  if(cpl_error_get_code() != CPL_ERROR_NONE) {
2011  sinfo_msg_error(" could not read fits header keyword cummoffsetx!") ;
2012  /* return -1 ; */
2013  cpl_error_reset();
2014  }
2015 
2016  *ref_offy = sinfo_pfits_get_cumoffsety(plist) ;
2017  if(cpl_error_get_code() != CPL_ERROR_NONE) {
2018  sinfo_msg_error(" could not read fits header keyword! cumoffsety") ;
2019  cpl_error_reset();
2020  /* return -1 ; */
2021  }
2022  sinfo_msg_debug("Reference offx=%f offy=%f",*ref_offx,*ref_offy);
2023 
2024  offx = 0. ;
2025  offy = 0. ;
2026 
2027  } else {
2028 
2029  offx = sinfo_pfits_get_cumoffsetx(plist) - *ref_offx ; /* was - */
2030  if(cpl_error_get_code() != CPL_ERROR_NONE) {
2031  sinfo_msg_error(" could not read fits header keyword cummoffsetx!") ;
2032  cpl_error_reset();
2033  /* return -1 ; */
2034  }
2035 
2036  offy = sinfo_pfits_get_cumoffsety(plist) - *ref_offy ; /* was - */
2037  if(cpl_error_get_code() != CPL_ERROR_NONE) {
2038  sinfo_msg_error(" could not read fits header keyword! cumoffsety") ;
2039  /* return -1 ; */
2040  cpl_error_reset();
2041  }
2042  sinfo_msg_debug("offx=%f offy=%f",offx,offy);
2043  }
2044 
2045 
2046  /* rotate the coordinates
2047  offx_rot = cd1_1 * offx + cd2_1 * offy ;
2048  offy_rot = cd1_2 * offx + cd2_2 * offy ;
2049  convert the coordinates to pixel units
2050  offx_rot_pix = offx_rot / pixelscale ;
2051  offy_rot_pix = offy_rot / pixelscale ;
2052  offsetx[i] = offx_rot_pix ;
2053  offsety[i] = offy_rot_pix ;
2054  */
2055 
2056 
2057  if (cpl_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
2058  mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
2059  } else {
2060  sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
2061  cpl_propertylist_delete(plist) ;
2062  return -1;
2063  }
2064 
2065  cpl_propertylist_delete(plist) ;
2066 
2067  if (mjd_obs > 53825. ) {
2068  /* April 1st 2006 */
2069  //sinfo_msg("New cumoffset setting convention");
2070  sinfo_new_array_set_value(*offsetx,2*offx,n);
2071  sinfo_new_array_set_value(*offsety,2*offy,n);
2072  } else if ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
2073  /* after detector's upgrade */
2074  sinfo_new_array_set_value(*offsetx,-offx*2,n);
2075  sinfo_new_array_set_value(*offsety,+offy*2,n);
2076  } else {
2077  /* before detector's upgrade */
2078  sinfo_new_array_set_value(*offsetx,+offx*2,n);
2079  sinfo_new_array_set_value(*offsety,-offy*2,n);
2080  }
2081 
2082  return 0;
2083 }
2084 
2096 cpl_imagelist*
2097 sinfo_new_fine_tune(cpl_imagelist* cube,
2098  float* correct_dist,
2099  const char* method,
2100  const int order,
2101  const int nslits) {
2102  int i =0;
2103  cpl_imagelist* outcube2=NULL;
2104  float* neg_dist=NULL;
2105  sinfo_msg("Finetuning, method=%s",method);
2106 
2107  if (strcmp(method,"P")==0)
2108  {
2109  outcube2 = sinfo_new_fine_tune_cube( cube, correct_dist, order ) ;
2110  if (outcube2 == NULL)
2111  {
2112  sinfo_msg_error (" could not fine tune the data cube\n") ;
2113  return NULL ;
2114  }
2115  }
2116  else if (strcmp(method,"F")==0)
2117  {
2118  neg_dist=cpl_calloc(nslits,sizeof(float));
2119  for ( i = 0 ; i < nslits ; i++ )
2120  {
2121  neg_dist[i] = -correct_dist[i] ;
2122  }
2123  outcube2 = sinfo_new_fine_tune_cube_by_FFT( cube, neg_dist ) ;
2124  cpl_free(neg_dist);
2125  if ( outcube2 == NULL )
2126  {
2127  sinfo_msg_error (" could not fine tune the data cube\n") ;
2128  return NULL ;
2129  }
2130  }
2131  else if (strcmp(method,"S")==0)
2132  {
2133  outcube2 = sinfo_new_fine_tune_cube_by_spline( cube, correct_dist ) ;
2134  if ( outcube2 == NULL )
2135  {
2136  sinfo_msg_error (" could not fine tune the data cube\n") ;
2137  return NULL ;
2138  }
2139  }
2140  else
2141  {
2142  sinfo_msg_error (" wrong method indicator given!") ;
2143  return NULL ;
2144  }
2145 
2146 
2147 
2148 return outcube2;
2149 
2150 }
2151 
2152 /*----------------------------------------------------------------------------*/
2158 /*----------------------------------------------------------------------------*/
2159 /* TODO: not used */
2160 sinfo_band sinfo_get_associated_filter(const char * f)
2161 {
2162  if (!strcmp(f, "J")) return SINFO_BAND_J ;
2163  if (!strcmp(f, "Js")) return SINFO_BAND_JS ;
2164  if (!strcmp(f, "Z")) return SINFO_BAND_Z ;
2165  if (!strcmp(f, "SZ")) return SINFO_BAND_SZ ;
2166  if (!strcmp(f, "SH")) return SINFO_BAND_SH ;
2167  if (!strcmp(f, "H")) return SINFO_BAND_H ;
2168  if (!strcmp(f, "Ks")) return SINFO_BAND_KS ;
2169  if (!strcmp(f, "K")) return SINFO_BAND_K ;
2170  if (!strcmp(f, "SK")) return SINFO_BAND_SK ;
2171  if (!strcmp(f, "L")) return SINFO_BAND_L ;
2172  if (!strcmp(f, "SL")) return SINFO_BAND_SL ;
2173  if (!strcmp(f, "M")) return SINFO_BAND_M ;
2174  if (!strcmp(f, "M_NB")) return SINFO_BAND_M ;
2175  if (!strcmp(f, "NB_1.06")) return SINFO_BAND_J ;
2176  if (!strcmp(f, "NB_1.08")) return SINFO_BAND_J ;
2177  if (!strcmp(f, "NB_1.19")) return SINFO_BAND_J ;
2178  if (!strcmp(f, "NB_1.21")) return SINFO_BAND_J ;
2179  if (!strcmp(f, "NB_1.26")) return SINFO_BAND_J ;
2180  if (!strcmp(f, "NB_1.28")) return SINFO_BAND_J ;
2181  if (!strcmp(f, "NB_1.64")) return SINFO_BAND_H ;
2182  if (!strcmp(f, "NB_1.71")) return SINFO_BAND_H ;
2183  if (!strcmp(f, "NB_2.07")) return SINFO_BAND_KS ;
2184  if (!strcmp(f, "NB_2.09")) return SINFO_BAND_KS ;
2185  if (!strcmp(f, "NB_2.13")) return SINFO_BAND_KS ;
2186  if (!strcmp(f, "NB_2.17")) return SINFO_BAND_KS ;
2187  if (!strcmp(f, "NB_2.19")) return SINFO_BAND_KS ;
2188  if (!strcmp(f, "NB_2.25")) return SINFO_BAND_KS ;
2189  if (!strcmp(f, "NB_2.29")) return SINFO_BAND_KS ;
2190  if (!strcmp(f, "NB_2.34")) return SINFO_BAND_KS ;
2191  if (!strcmp(f, "NB_3.21")) return SINFO_BAND_L ;
2192  if (!strcmp(f, "NB_3.28")) return SINFO_BAND_L ;
2193  if (!strcmp(f, "NB_3.80")) return SINFO_BAND_L ;
2194  if (!strcmp(f, "NB_4.07")) return SINFO_BAND_L ;
2195  return SINFO_BAND_UNKNOWN ;
2196 }
2197 
2198 
2199 
2200 /*----------------------------------------------------------------------------*/
2206 /*----------------------------------------------------------------------------*/
2207 /* TODO: not used */
2208 sinfo_band sinfo_get_bbfilter(const char * f)
2209 {
2210  if (!strcmp(f, "J")) return SINFO_BAND_J ;
2211  if (!strcmp(f, "J+Block")) return SINFO_BAND_J ;
2212  if (!strcmp(f, "Js")) return SINFO_BAND_J ;
2213  if (!strcmp(f, "Z")) return SINFO_BAND_J ;
2214  if (!strcmp(f, "SZ")) return SINFO_BAND_J ;
2215  if (!strcmp(f, "SH")) return SINFO_BAND_H ;
2216  if (!strcmp(f, "H")) return SINFO_BAND_H ;
2217  if (!strcmp(f, "Ks")) return SINFO_BAND_KS ;
2218  if (!strcmp(f, "K")) return SINFO_BAND_K ;
2219  if (!strcmp(f, "SK")) return SINFO_BAND_K ;
2220  if (!strcmp(f, "L")) return SINFO_BAND_L ;
2221  if (!strcmp(f, "SL")) return SINFO_BAND_L ;
2222  if (!strcmp(f, "M")) return SINFO_BAND_M ;
2223  if (!strcmp(f, "M_NB")) return SINFO_BAND_M ;
2224  if (!strcmp(f, "NB_1.06")) return SINFO_BAND_J ;
2225  if (!strcmp(f, "NB_1.08")) return SINFO_BAND_J ;
2226  if (!strcmp(f, "NB_1.19")) return SINFO_BAND_J ;
2227  if (!strcmp(f, "NB_1.21")) return SINFO_BAND_J ;
2228  if (!strcmp(f, "NB_1.26")) return SINFO_BAND_J ;
2229  if (!strcmp(f, "NB_1.28")) return SINFO_BAND_J ;
2230  if (!strcmp(f, "NB_1.64")) return SINFO_BAND_H ;
2231  if (!strcmp(f, "NB_1.71")) return SINFO_BAND_H ;
2232  if (!strcmp(f, "NB_2.07")) return SINFO_BAND_KS ;
2233  if (!strcmp(f, "NB_2.09")) return SINFO_BAND_KS ;
2234  if (!strcmp(f, "NB_2.13")) return SINFO_BAND_KS ;
2235  if (!strcmp(f, "NB_2.17")) return SINFO_BAND_KS ;
2236  if (!strcmp(f, "NB_2.19")) return SINFO_BAND_KS ;
2237  if (!strcmp(f, "NB_2.25")) return SINFO_BAND_KS ;
2238  if (!strcmp(f, "NB_2.29")) return SINFO_BAND_KS ;
2239  if (!strcmp(f, "NB_2.34")) return SINFO_BAND_KS ;
2240  if (!strcmp(f, "NB_3.21")) return SINFO_BAND_L ;
2241  if (!strcmp(f, "NB_3.28")) return SINFO_BAND_L ;
2242  if (!strcmp(f, "NB_3.80")) return SINFO_BAND_L ;
2243  if (!strcmp(f, "NB_4.07")) return SINFO_BAND_L ;
2244  return SINFO_BAND_UNKNOWN ;
2245 }
2246 
2247 
#define sinfo_msg_debug(...)
Print a debug message.
Definition: sinfo_msg.h:103
#define sinfo_msg_error(...)
Print an error message.
Definition: sinfo_msg.h:69
#define sinfo_msg_warning(...)
Print an warning message.
Definition: sinfo_msg.h:93