SINFONI Pipeline Reference Manual  2.5.2
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 sinfo_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 static void
59 sinfo_set_coord2(cpl_propertylist** plist,
60  const double crpix2,
61  const double crval2,
62  const double cdelt2);
63 static void
64 sinfo_set_coord3(cpl_propertylist** plist,
65  const int crpix3,
66  const double crval3,
67  const double cdelt3);
68 
69 
70 static void
71 sinfo_set_cd_matrix2(cpl_propertylist** plist,
72  const double cd1_1,
73  const double cd1_2,
74  const double cd2_1,
75  const double cd2_2);
76 
77 
78 static void
79 sinfo_set_cd_matrix3(cpl_propertylist** plist,
80  const double cd1_3,
81  const double cd2_3,
82  const double cd3_1,
83  const double cd3_2,
84  const double cd3_3);
85 
86 
87 static void
88 sinfo_new_change_plist_cube (cpl_propertylist * plist,
89  float cenLambda,
90  float dispersion,
91  int center_z,
92  float center_x,
93  float center_y );
94 
95 
96 static void
97 sinfo_new_change_plist_image (cpl_propertylist * plist,
98  float center_x,
99  float center_y );
100 
101 
102 static void
103 sinfo_new_change_plist_spectrum (cpl_propertylist * plist,
104  double cenLambda,
105  double dispersion,
106  int cenpix);
107 
108 static cpl_image *
109 sinfo_new_image_getvig(
110  cpl_image * image_in,
111  int loleft_x,
112  int loleft_y,
113  int upright_x,
114  int upright_y);
115 
116 
117 
130 int
131 sinfo_check_input_data(object_config* cfg)
132 {
133 
134 
135  if (cfg == NULL)
136  {
137  sinfo_msg_error (" could not parse cpl input!\n") ;
138  return -1 ;
139  }
140 
141 
142  if(sinfo_is_fits_file(cfg->wavemap) != 1) {
143  sinfo_msg_error("Input file wavemap %s is not FITS",cfg->wavemap);
144  return -1;
145  }
146 
147 
148  if (cfg->halocorrectInd == 1)
149  {
150  if(sinfo_is_fits_file(cfg->halospectrum) != 1) {
151  sinfo_msg_error("Input file %s is not FITS",cfg->halospectrum);
152  return -1;
153  }
154 
155  }
156 
157  if (cfg->northsouthInd == 0) {
158  if (sinfo_is_fits_file(cfg->poslist) != 1)
159  {
160  sinfo_msg_error("File %s with tag %s is not FITS!",
161  cfg->poslist,PRO_SLIT_POS);
162  return -1 ;
163  }
164  } else {
165 
166  if (sinfo_is_fits_file(cfg->distlist) != 1)
167  {
168  sinfo_msg_error("File %s with tag %s is not FITS!",
169  cfg->distlist,PRO_SLITLETS_DISTANCE);
170  return -1;
171  }
172  }
173 
174 
175  return 0;
176 
177 
178 }
186 static double
187 sinfo_hms2deg(const double hms)
188 {
189  int hrs=0;
190  int min=0;
191  double sec=0;
192  double deg=0;
193  double rest=hms;
194  int sign=1;
195 
196  //sinfo_msg("hms=%f",hms);
197 
198  if(hms<0) {
199  sign=-1;
200  rest=-hms;
201  }
202  //sinfo_msg("rest=%f",rest);
203  //sinfo_msg("sign=%d",sign);
204 
205  hrs=(int)(rest/10000.);
206  //sinfo_msg("hrs=%d",hrs);
207 
208  rest=rest-(double)(hrs*10000.);
209  min=(int)(rest/100.);
210  //sinfo_msg("min=%d",min);
211 
212  sec=rest-(double)(min*100.);
213  //sinfo_msg("sec=%f",sec);
214 
215  deg=hrs*15+(double)(min/4.)+(double)(sec/240.);
216  //sinfo_msg("deg=%f",deg);
217 
218  deg=sign*deg;
219  //sinfo_msg("deg=%f",deg);
220 
221  return deg;
222 
223 }
224 
232 static double
233 sinfo_sess2deg(const double sess)
234 {
235  int grad=0;
236  int min=0;
237  double sec=0;
238  double deg=0;
239  double rest=sess;
240  int sign=1;
241 
242  //sinfo_msg("sess=%f",sess);
243 
244  if(sess<0) {
245  sign=-1;
246  rest=-sess;
247  }
248  //sinfo_msg("rest=%f",rest);
249  //sinfo_msg("sign=%d",sign);
250 
251  grad=(int)(rest/10000.);
252  //sinfo_msg("grad=%d",grad);
253 
254  rest=rest-(double)(grad*10000.);
255  min=(int)(rest/100.);
256  //sinfo_msg("min=%d",min);
257 
258  sec=rest-(double)(min*100.);
259  //sinfo_msg("sec=%f",sec);
260 
261  deg=grad+(double)(min/60.)+(double)(sec/3600.);
262  //sinfo_msg("deg=%f",deg);
263 
264  deg=sign*deg;
265  //sinfo_msg("deg=%f",deg);
266 
267  return deg;
268 
269 }
270 
271 
284 int
285 sinfo_auto_size_cube(float* offsetx,
286  float* offsety,
287  const int nframes,
288  float* ref_offx,
289  float* ref_offy,
290  int* size_x,
291  int* size_y)
292 {
293 
294  int n=0;
295  float offx=0;
296  float offy=0;
297  float min_offx=0;
298  float max_offx=0;
299  float min_offy=0;
300  float max_offy=0;
301 
302  sinfo_msg ("Computation of output cube size") ;
303  for ( n = 0 ; n < nframes ; n++ ) {
304  offx = offsetx[n]; /* was - */
305  offy = offsety[n]; /* was - */
306  /* sinfo_msg("frame %d offx=%f offy=%f",n,offx,offy); */
307  if(n==0) {
308  min_offx=offx;
309  min_offy=offy;
310  max_offx=offx;
311  max_offy=offy;
312  } else {
313  if(offx > max_offx) max_offx=offx;
314  if(offy > max_offy) max_offy=offy;
315  if(offx < min_offx) min_offx=offx;
316  if(offy < min_offy) min_offy=offy;
317  }
318  }
319  /*
320  sinfo_msg("max_offx=%f max_offy=%f",max_offx,max_offy);
321  sinfo_msg("min_offx=%f min_offy=%f",min_offx,min_offy);
322  */
323  *ref_offx=(min_offx+max_offx)/2;
324  *ref_offy=(min_offy+max_offy)/2;
325  *size_x+=2*floor(max_offx-min_offx+0.5);
326  *size_y+=2*floor(max_offy-min_offy+0.5);
327  sinfo_msg("Output cube size: %d x %d",*size_x,*size_y);
328  sinfo_msg("Ref offset. x: %f y: %f",*ref_offx,*ref_offy);
329  sinfo_msg_debug("Max offset. x: %f y: %f",max_offx,max_offy);
330  sinfo_msg_debug("Min offset. x: %f y: %f",min_offx,min_offy);
331  return 0;
332 
333 }
334 
342 int
343 sinfo_auto_size_cube5(object_config * cfg,
344  float* ref_offx, float* ref_offy,
345  float* min_offx, float* min_offy,
346  float* max_offx, float* max_offy)
347 {
348 
349  char* name =NULL;
350  int n=0;
351  float offx=0;
352  float offy=0;
353 
354  cpl_propertylist * plist=NULL;
355  sinfo_msg ("Automatic computation of output cube size") ;
356  for ( n = 0 ; n < cfg->nframes ; n++ ) {
357  name = cfg->framelist[n] ;
358  plist=cpl_propertylist_load(name,0);
359  offx = sinfo_pfits_get_cumoffsetx(plist); /* was - */
360  if(cpl_error_get_code() != CPL_ERROR_NONE) {
361  sinfo_msg_warning(" could not read fits header keyword cummoffsetx!");
362  sinfo_msg_warning(" set it to 0");
363  offx = 0;
364  cpl_error_reset();
365  /* return -1 ; */
366  }
367 
368  offy = sinfo_pfits_get_cumoffsety(plist); /* was - */
369  sinfo_free_propertylist(&plist);
370  if(cpl_error_get_code() != CPL_ERROR_NONE) {
371  sinfo_msg_warning(" could not read fits header keyword! cumoffsety") ;
372  sinfo_msg_warning(" set it to 0");
373  offy = 0;
374  cpl_error_reset();
375  /* return -1 ; */
376  }
377  //sinfo_msg("n=%d offx=%f offy=%f",n,offx,offy);
378 
379  if(n==0) {
380  *min_offx=offx;
381  *min_offy=offy;
382  *max_offx=offx;
383  *max_offy=offy;
384  } else {
385  if(offx > *max_offx) *max_offx=offx;
386  if(offy > *max_offy) *max_offy=offy;
387  if(offx < *min_offx) *min_offx=offx;
388  if(offy < *min_offy) *min_offy=offy;
389  }
390  }
391  *ref_offx=(*min_offx+*max_offx)/2;
392  *ref_offy=(*min_offy+*max_offy)/2;
393 
394  if(cfg->size_x == 0) cfg->size_x=2*floor(*max_offx-*min_offx+0.5)+64 ;
395 /* The formula above doesn't give always the right result (DSF07663)
396  * for example, if diff in offset is 35.5, the formula gives 72 but 71 would be
397  * enough, the following candidate is working fine:
398  * if(cfg->size_x == 0)
399  cfg->size_x=floor(2.0*(*max_offx-*min_offx + 0.5 - 0.00001))+64 ;
400  Currently the ticket is suspended, because the formula above
401  would change the scientific results for the previous data.
402  The same is actual for Y axis.
403 */
404  if(cfg->size_y == 0) cfg->size_y=2*floor(*max_offy-*min_offy+0.5)+64 ;
405 
406  sinfo_msg("Output cube size: %d x %d",cfg->size_x,cfg->size_y);
407  sinfo_msg("Ref offset. x: %f y: %f",*ref_offx,*ref_offy);
408  sinfo_msg("Max offset. x: %f y: %f",*max_offx,*max_offy);
409  sinfo_msg("Min offset. x: %f y: %f",*min_offx,*min_offy);
410  return 0;
411 
412 
413 }
414 
424 float*
425 sinfo_read_distances(const int nslits, const char* distlist)
426 {
427  int i=0;
428  int* status=NULL;
429  float * distances = NULL;
430  float tmp_float=0;
431  char tbl_distances_name[FILE_NAME_SZ];
432  cpl_table* tbl_distances = NULL;
433 
434  sinfo_msg("Read distances");
435  distances = (float*) cpl_calloc (nslits - 1, sizeof (float));
436 
437  if ( NULL == distances )
438  {
439  sinfo_msg_error ("could allocate memory!") ;
440  return NULL ;
441  }
442 
443  /*READ TFITS TABLE*/
444  if(cpl_error_get_code() != CPL_ERROR_NONE) {
445  sinfo_msg_error("Before loading input table");
446  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
447  return NULL;
448  }
449  strcpy(tbl_distances_name,distlist);
450  tbl_distances = cpl_table_load(tbl_distances_name,1,0);
451  if(cpl_error_get_code() != CPL_ERROR_NONE) {
452  sinfo_msg_error("loading input table %s",tbl_distances_name);
453  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
454  return NULL;
455  }
456 
457  for (i =0 ; i< nslits-1; i++){
458  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  float edge_x=0;
492  float edge_y=0;
493  float ** slit_edges = NULL;
494 
495  slit_edges = sinfo_new_2Dfloatarray(nslits, 2) ;
496 
497  strcpy(tbl_slitpos_name,poslist);
498  tbl_slitpos = cpl_table_load(tbl_slitpos_name,1,0);
499  if(cpl_error_get_code() != CPL_ERROR_NONE) {
500  sinfo_msg_error("error loading tbl %s",tbl_slitpos_name);
501  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
502  return NULL;
503  }
504  n = cpl_table_get_nrow(tbl_slitpos);
505  if (n != nslits) {
506  sinfo_msg_error("No of slitlets in table is n = %d != %d !",n,nslits);
507  return NULL;
508  }
509 
510  for (i =0 ; i< nslits; i++){
511  edge_x=cpl_table_get_double(tbl_slitpos,"pos1",i,status);
512  edge_y=cpl_table_get_double(tbl_slitpos,"pos2",i,status);
513  if(cpl_error_get_code() != CPL_ERROR_NONE) {
514  sinfo_msg_error("error reading tbl %s row %d",tbl_slitpos_name,i);
515  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
516  return NULL;
517  }
518  sinfo_new_array2D_set_value(slit_edges,edge_x,i,0);
519  sinfo_new_array2D_set_value(slit_edges,edge_y,i,1);
520  }
521  cpl_table_delete(tbl_slitpos);
522  if(cpl_error_get_code() != CPL_ERROR_NONE) {
523  sinfo_msg_error("error reading tbl %s",tbl_slitpos_name);
524  sinfo_msg_error("%s", (char* ) cpl_error_get_message());
525  return NULL;
526  }
527 
528  return slit_edges;
529 
530 }
531 
532 
533 /*---------------------------------------------------------------------------*/
556 /*---------------------------------------------------------------------------*/
557 cpl_imagelist * sinfo_new_cube_getvig(
558  cpl_imagelist * cube_in,
559  int loleft_x,
560  int loleft_y,
561  int upright_x,
562  int upright_y)
563 {
564  cpl_imagelist * cube_out ;
565  int i ;
566  /*
567  int outlx,
568  outly ;
569 
570  int ilx=0;
571  int ily=0;
572  int inp=0;
573  */
574  cpl_image* i_img=NULL;
575  cpl_image* o_img=NULL;
576 
577  if (cube_in==NULL) return NULL ;
578 /*
579  ilx=cpl_image_get_size_x(cpl_imagelist_get(cube_in,0));
580  ily=cpl_image_get_size_y(cpl_imagelist_get(cube_in,0));
581  inp=cpl_imagelist_get_size(cube_in);
582 */
583  if ((loleft_x>upright_x) ||
584  (loleft_y>upright_y)) {
585  sinfo_msg_error("ill-defined slit for extraction: aborting");
586  return NULL ;
587  }
588 
589  /* Extraction coordinates include rectangular zone */
590  /*
591  outlx = upright_x - loleft_x + 1 ;
592  outly = upright_y - loleft_y + 1 ;
593  */
594  /*
595  cube_out = sinfo_new_cube(outlx, outly, cube_in->np) ;
596  */
597  cube_out = cpl_imagelist_new() ;
598  /* Loop on all input planes */
599  for (i=0 ; i<cpl_imagelist_get_size(cube_in) ; i++) {
600 
601  i_img=cpl_imagelist_get(cube_in,i);
602  /* Extract a slit from this plane */
603  o_img = sinfo_new_image_getvig(i_img,
604  loleft_x, loleft_y,
605  upright_x, upright_y) ;
606  cpl_imagelist_set(cube_out,o_img,i);
607  }
608  return cube_out ;
609 }
610 /*---------------------------------------------------------------------------*/
627 /*---------------------------------------------------------------------------*/
628 
629 static cpl_image *
630 sinfo_new_image_getvig(
631  cpl_image * image_in,
632  int loleft_x,
633  int loleft_y,
634  int upright_x,
635  int upright_y)
636 {
637  cpl_image * slit_img ;
638  int i, j ;
639  register
640  pixelvalue * inpt,
641  * outpt ;
642  int outlx, outly ;
643  int ilx=0;
644  int ily=0;
645 
646  float* pidata=NULL;
647  float* podata=NULL;
648 
649  if (image_in==NULL) return NULL ;
650 
651  ilx=cpl_image_get_size_x(image_in);
652  ily=cpl_image_get_size_y(image_in);
653  pidata=cpl_image_get_data_float(image_in);
654 
655  if ((loleft_x<1) || (loleft_x>ilx) ||
656  (loleft_y<1) || (loleft_y>ily) ||
657  (upright_x<1) || (upright_x>ilx) ||
658  (upright_y<1) || (upright_y>ily) ||
659  (loleft_x>upright_x) || (loleft_y>upright_y)) {
660  sinfo_msg_error("extraction zone is [%d %d] [%d %d]\n"
661  "cannot extract such zone: aborting slit extraction",
662  loleft_x, loleft_y, upright_x, upright_y) ;
663  return NULL ;
664  }
665 
666  outlx = upright_x - loleft_x + 1 ;
667  outly = upright_y - loleft_y + 1 ;
668  slit_img = cpl_image_new(outlx, outly,CPL_TYPE_FLOAT) ;
669  podata=cpl_image_get_data_float(slit_img);
670 
671  for (j=0 ; j<outly ; j++) {
672  inpt = pidata+loleft_x-1 + (j+loleft_y-1)*ilx ;
673  outpt = podata + j*outlx ;
674  for (i=0 ; i<outlx ; i++) {
675  *outpt++ = *inpt++ ;
676  }
677  }
678  return slit_img ;
679 }
680 
692 int
693 sinfo_new_set_wcs_cube(cpl_imagelist* cub, const char* name, double clambda,
694  double dis, double cpix, double cx, double cy)
695 {
696  cpl_propertylist* plist=NULL;
697 
698  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
699  sinfo_msg_error( "getting header from frame %s",name);
700  cpl_propertylist_delete(plist) ;
701  return -1 ;
702  }
703 
704  sinfo_new_change_plist_cube(plist, clambda, dis, cpix, cx, cy) ;
705  sinfo_plist_set_extra_keys(plist,"IMAGE","DATA","RMSE",
706  "DATA","ERRS","QUAL",0);
707  if (cpl_imagelist_save(cub, name, CPL_BPP_IEEE_FLOAT,
708  plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
709  sinfo_msg_error( "Cannot save the product %s",name);
710  cpl_propertylist_delete(plist) ;
711  return -1 ;
712  }
713  cpl_propertylist_delete(plist) ;
714  return 0;
715 
716 }
725 int
726 sinfo_new_set_wcs_image(cpl_image* img,
727  const char* name,
728  double cx,
729  double cy)
730 {
731  cpl_propertylist* plist=NULL;
732 
733  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
734  sinfo_msg_error( "getting header from frame %s",name);
735  cpl_propertylist_delete(plist) ;
736  return -1 ;
737  }
738  sinfo_new_change_plist_image(plist, cx, cy) ;
739 
740  if (cpl_image_save(img, name, CPL_BPP_IEEE_FLOAT,
741  plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
742  sinfo_msg_error( "Cannot save the product %s",name);
743  cpl_propertylist_delete(plist) ;
744  return -1 ;
745  }
746  cpl_propertylist_delete(plist) ;
747  return 0;
748 
749 }
750 
751 
761 int
762 sinfo_new_set_wcs_spectrum(cpl_image* img, const char* name, double clambda,
763  double dis, double cpix)
764 {
765  cpl_propertylist* plist=NULL;
766 
767  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
768  sinfo_msg_error( "getting header from frame %s",name);
769  cpl_propertylist_delete(plist) ;
770  return -1 ;
771  }
772  sinfo_new_change_plist_spectrum(plist, clambda, dis,cpix) ;
773 
774  if (cpl_image_save(img, name, CPL_BPP_IEEE_FLOAT,
775  plist,CPL_IO_DEFAULT)!=CPL_ERROR_NONE) {
776  sinfo_msg_error( "Cannot save the product %s",name);
777  cpl_propertylist_delete(plist) ;
778  return -1 ;
779  }
780  cpl_propertylist_delete(plist) ;
781  return 0;
782 
783 }
795 static void
796 sinfo_new_change_plist_cube (cpl_propertylist * plist,
797  float cenLambda,
798  float dispersion,
799  int center_z,
800  float center_x,
801  float center_y )
802 {
803 
804  float pixelscale ;
805  double ra ;
806  double dec ;
807  double angle ;
808  float radangle ;
809  double cd1_1, cd1_2, cd2_1, cd2_2 ;
810  int sign_swap = -1;
811  char firsttext[2*FILE_NAME_SZ] ;
812 
813  double cdelt1=0;
814  double cdelt2=0;
815  double cdelt3=dispersion;
816 
817  double crpix1=center_x;
818  double crpix2=center_y;
819  int crpix3=center_z;
820 
821  double crval1=0;
822  double crval2=0;
823  double crval3=cenLambda;
824 
825 
826  strcpy(firsttext, "sinfo_rec_objnod -f \0") ;
827 
828  pixelscale = sinfo_pfits_get_pixscale(plist)/2. ;
829  ra = sinfo_pfits_get_ra(plist) ;
830  dec = sinfo_pfits_get_DEC(plist) ;
831 
832  //get better coordinate values
833  ra=sinfo_pfits_get_targ_alpha(plist);
834  dec=sinfo_pfits_get_targ_delta(plist);
835  //sinfo_msg("ra=%f",ra);
836  //sinfo_msg("dec=%f",dec);
837  ra=sinfo_hms2deg(ra);
838  dec=sinfo_sess2deg(dec);
839  //sinfo_msg("ra=%f",ra);
840  //sinfo_msg("dec=%f",dec);
841 
842  crval1=ra;
843  crval2=dec;
844 
845  angle = sinfo_pfits_get_posangle(plist) ;
846  /* in PUPIL data there is not posangle info: we reset the error */
847  if(cpl_error_get_code() != CPL_ERROR_NONE) {
848  cpl_error_reset();
849  }
850  cdelt1=sign_swap*pixelscale / 3600.;
851  cdelt2= +pixelscale / 3600.;
852 
853 
854  radangle = angle * PI_NUMB / 180. ;
855  cd1_1 = +cdelt1*cos(radangle);
856  cd1_2 = -cdelt2*sin(radangle);
857  cd2_1 = +cdelt1*sin(radangle);
858  cd2_2 = +cdelt2*cos(radangle);
859 
860 
861  sinfo_set_coord1(&plist,crpix1,crval1,cdelt1);
862  sinfo_set_coord2(&plist,crpix2,crval2,cdelt2);
863  sinfo_set_coord3(&plist,crpix3,crval3,cdelt3);
864  sinfo_set_cd_matrix2(&plist,cd1_1,cd1_2,cd2_1,cd2_2);
865  sinfo_set_cd_matrix3(&plist,0,0,0,0,dispersion);
866 
867 
868  }
869 
870 
871 
872 
881 static void
882 sinfo_set_coord1(cpl_propertylist** plist,
883  const double crpix1,
884  const double crval1,
885  const double cdelt1)
886 {
887  cpl_propertylist_erase_regexp(*plist, "^CTYPE1",0);
888  cpl_propertylist_insert_after_string(*plist,"EXPTIME","CTYPE1","RA---TAN");
889  cpl_propertylist_set_comment(*plist, "CTYPE1", "Projected Rectascension");
890  cpl_propertylist_erase_regexp(*plist, "^CRPIX1",0);
891  cpl_propertylist_insert_after_double(*plist,"CTYPE1","CRPIX1", crpix1) ;
892  cpl_propertylist_set_comment(*plist, "CRPIX1","Reference pixel in RA" ) ;
893 
894  cpl_propertylist_erase_regexp(*plist, "^CRVAL1",0);
895  cpl_propertylist_insert_after_double(*plist, "CRPIX1", "CRVAL1", crval1 ) ;
896  cpl_propertylist_set_comment(*plist, "CRVAL1","Reference RA" ) ;
897 
898  cpl_propertylist_erase_regexp(*plist, "^CDELT1",0);
899  cpl_propertylist_insert_after_double(*plist,"CRVAL1","CDELT1",cdelt1 ) ;
900  cpl_propertylist_set_comment(*plist, "CDELT1","pixel scale" ) ;
901 
902  cpl_propertylist_erase_regexp(*plist, "^CUNIT1",0);
903  cpl_propertylist_insert_after_string(*plist, "CDELT1", "CUNIT1", "deg" ) ;
904  cpl_propertylist_set_comment(*plist, "CUNIT1","RA-UNIT" ) ;
905 
906  return;
907 }
908 
909 
918 static void
919 sinfo_set_coord2(cpl_propertylist** plist,
920  const double crpix2,
921  const double crval2,
922  const double cdelt2)
923 {
924  cpl_propertylist_erase_regexp(*plist, "^CTYPE2",0);
925  cpl_propertylist_insert_after_string(*plist,"CUNIT1","CTYPE2","DEC--TAN");
926  cpl_propertylist_set_comment(*plist, "CTYPE2", "Projected Declination") ;
927 
928  cpl_propertylist_erase_regexp(*plist, "^CRPIX2",0);
929  cpl_propertylist_insert_after_double(*plist,"CTYPE2","CRPIX2",crpix2 ) ;
930  cpl_propertylist_set_comment(*plist, "CRPIX2", "Reference pixel in DEC") ;
931 
932  cpl_propertylist_erase_regexp(*plist,"^CRVAL2",0);
933  cpl_propertylist_insert_after_double(*plist,"CRPIX2","CRVAL2",crval2) ;
934  cpl_propertylist_set_comment(*plist,"CRVAL2","Reference DEC") ;
935 
936  cpl_propertylist_erase_regexp(*plist,"^CDELT2",0);
937  cpl_propertylist_insert_after_double(*plist,"CRVAL2","CDELT2",cdelt2 ) ;
938  cpl_propertylist_set_comment(*plist,"CDELT2","pixel scale") ;
939 
940  cpl_propertylist_erase_regexp(*plist,"^CUNIT2",0);
941  cpl_propertylist_insert_after_string(*plist,"CDELT2","CUNIT2", "deg" ) ;
942  cpl_propertylist_set_comment(*plist,"CUNIT2","DEC-UNIT") ;
943 
944 
945 }
946 
947 
948 
957 static void
958 sinfo_set_coord3(cpl_propertylist** plist,
959  const int crpix3,
960  const double crval3,
961  const double cdelt3)
962 {
963  cpl_propertylist_erase_regexp(*plist, "^CTYPE3",0);
964  cpl_propertylist_insert_after_string(*plist,"EXPTIME", "CTYPE3", "WAVE" ) ;
965  cpl_propertylist_set_comment(*plist,"CTYPE3","wavelength axis in microns") ;
966 
967  cpl_propertylist_erase_regexp(*plist, "^CRPIX3",0);
968  cpl_propertylist_insert_after_double(*plist,"CTYPE3","CRPIX3", (double)crpix3 ) ;
969  cpl_propertylist_set_comment(*plist, "CRPIX3", "Reference pixel in z") ;
970 
971  cpl_propertylist_erase_regexp(*plist, "^CRVAL3",0);
972  cpl_propertylist_insert_after_double(*plist,"CRPIX3", "CRVAL3", crval3) ;
973  cpl_propertylist_set_comment(*plist, "CRVAL3", "central wavelength") ;
974 
975  cpl_propertylist_erase_regexp(*plist, "^CDELT3",0);
976 
977  cpl_propertylist_insert_after_double(*plist,"CRVAL3","CDELT3",cdelt3) ;
978  cpl_propertylist_set_comment(*plist, "CDELT3", "microns per pixel") ;
979 
980  cpl_propertylist_erase_regexp(*plist, "^CUNIT3",0);
981  cpl_propertylist_insert_after_string(*plist,"CDELT3", "CUNIT3", "um" ) ;
982  cpl_propertylist_set_comment(*plist, "CUNIT3", "spectral unit" ) ;
983 
984  cpl_propertylist_erase_regexp(*plist, "^SPECSYS",0);
985  cpl_propertylist_insert_after_string(*plist,"CUNIT3", "SPECSYS", "TOPOCENT" ) ;
986  cpl_propertylist_set_comment(*plist, "SPECSYS", "Coordinate reference frame" ) ;
987 }
988 
989 
1000 static void
1001 sinfo_set_cd_matrix2(cpl_propertylist** plist,
1002  const double cd1_1,
1003  const double cd1_2,
1004  const double cd2_1,
1005  const double cd2_2)
1006 {
1007 
1008  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD1_1",0));
1009  check_nomsg(cpl_propertylist_insert_after_double(*plist,"EXPTIME",
1010  "CD1_1", cd1_1 )) ;
1011  check_nomsg(cpl_propertylist_set_comment(*plist, "CD1_1",
1012  "CD rotation matrix" )) ;
1013 
1014  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD1_2",0));
1015  check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD1_1",
1016  "CD1_2", cd1_2 )) ;
1017  check_nomsg(cpl_propertylist_set_comment(*plist, "CD1_2",
1018  "CD rotation matrix" )) ;
1019 
1020  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD2_1",0));
1021  check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD1_2",
1022  "CD2_1", cd2_1 )) ;
1023  check_nomsg(cpl_propertylist_set_comment(*plist, "CD2_1",
1024  "CD rotation matrix" )) ;
1025 
1026  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD2_2",0));
1027  check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD2_1",
1028  "CD2_2", cd2_2 )) ;
1029  check_nomsg(cpl_propertylist_set_comment(*plist, "CD2_2",
1030  "CD rotation matrix" )) ;
1031 
1032  cleanup:
1033  return;
1034 
1035 
1036 }
1037 
1038 
1051 static void
1052 sinfo_set_cd_matrix3(cpl_propertylist** plist,
1053  const double cd1_3,
1054  const double cd2_3,
1055  const double cd3_1,
1056  const double cd3_2,
1057  const double cd3_3)
1058 {
1059 
1060 
1061  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD1_3",0));
1062  check_nomsg(cpl_propertylist_insert_after_double(*plist,"EXPTIME",
1063  "CD1_3", cd1_3 )) ;
1064  check_nomsg(cpl_propertylist_set_comment(*plist, "CD1_3",
1065  "CD rotation matrix" )) ;
1066 
1067 
1068  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD2_3",0));
1069  check_nomsg(cpl_propertylist_insert_after_double(*plist,"CD1_3",
1070  "CD2_3", cd2_3 )) ;
1071  check_nomsg(cpl_propertylist_set_comment(*plist, "CD2_3",
1072  "CD rotation matrix" )) ;
1073 
1074 
1075 
1076  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD3_1",0));
1077  check_nomsg(cpl_propertylist_insert_after_double(*plist,"CD2_3",
1078  "CD3_1", cd3_1 )) ;
1079  check_nomsg(cpl_propertylist_set_comment(*plist, "CD3_1",
1080  "CD rotation matrix" )) ;
1081 
1082  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD3_2",0));
1083  check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD3_1",
1084  "CD3_2", cd3_2 )) ;
1085  check_nomsg(cpl_propertylist_set_comment(*plist, "CD3_2",
1086  "CD rotation matrix" )) ;
1087 
1088  check_nomsg(cpl_propertylist_erase_regexp(*plist, "^CD3_3",0));
1089  check_nomsg(cpl_propertylist_insert_after_double(*plist, "CD3_2",
1090  "CD3_3", cd3_3 )) ;
1091  check_nomsg(cpl_propertylist_set_comment(*plist, "CD3_3",
1092  "CD rotation matrix" )) ;
1093 
1094  cleanup:
1095  return;
1096 
1097 
1098 }
1099 
1100 
1109 static void
1110 sinfo_set_spect_coord1(cpl_propertylist** plist,
1111  const int crpix1,
1112  const double crval1,
1113  const double cdelt1)
1114 {
1115 
1116  cpl_propertylist_erase_regexp(*plist, "^CTYPE1",0);
1117  cpl_propertylist_insert_after_string(*plist,"EXPTIME", "CTYPE1", "PIXEL");
1118  cpl_propertylist_set_comment(*plist, "CTYPE1", "Pixel coordinate system.");
1119 
1120  cpl_propertylist_erase_regexp(*plist, "^CRPIX1",0);
1121  cpl_propertylist_insert_after_double(*plist, "CTYPE1", "CRPIX1", (double)crpix1 ) ;
1122  cpl_propertylist_set_comment(*plist, "CRPIX1", "Reference pixel in x") ;
1123 
1124  cpl_propertylist_erase_regexp(*plist, "^CRVAL1",0);
1125  cpl_propertylist_insert_after_double(*plist,"CRPIX1", "CRVAL1", crval1 ) ;
1126  cpl_propertylist_set_comment(*plist, "CRVAL1", "value of ref pixel.") ;
1127 
1128  cpl_propertylist_erase_regexp(*plist, "^CDELT1",0);
1129  cpl_propertylist_insert_after_double(*plist,"CRVAL1", "CDELT1", cdelt1 ) ;
1130  cpl_propertylist_set_comment(*plist,"CDELT1", "pixel scale") ;
1131 
1132 
1133  cpl_propertylist_erase_regexp(*plist, "^CUNIT1",0);
1134  cpl_propertylist_insert_after_string(*plist,"CDELT1", "CUNIT1", "Pixel" );
1135  cpl_propertylist_set_comment(*plist, "CUNIT1", "spectral unit" );
1136 
1137 }
1138 
1139 
1140 
1141 
1142 
1151 static void
1152 sinfo_set_spect_coord2(cpl_propertylist** plist,
1153  const int crpix2,
1154  const double crval2,
1155  const double cdelt2)
1156 {
1157 
1158  cpl_propertylist_erase_regexp(*plist, "^CTYPE2",0);
1159  cpl_propertylist_insert_after_string(*plist, "EXPTIME","CTYPE2","WAVE" );
1160  cpl_propertylist_set_comment(*plist,"CTYPE2","wavelength axis in microns");
1161 
1162  cpl_propertylist_erase_regexp(*plist, "^CRPIX2",0);
1163  cpl_propertylist_insert_after_double(*plist, "CTYPE2", "CRPIX2",(double)crpix2 ) ;
1164  cpl_propertylist_set_comment(*plist, "CRPIX2", "Reference pixel in x") ;
1165 
1166  cpl_propertylist_erase_regexp(*plist, "^CRVAL2",0);
1167  cpl_propertylist_insert_after_double(*plist, "CRPIX2","CRVAL2",crval2 ) ;
1168  cpl_propertylist_set_comment(*plist,"CRVAL2", "central wavelength") ;
1169 
1170  cpl_propertylist_erase_regexp(*plist, "^CDELT2",0);
1171  cpl_propertylist_insert_after_double(*plist, "CRVAL2", "CDELT2",cdelt2);
1172  cpl_propertylist_set_comment(*plist,"CDELT2", "microns per pixel");
1173 
1174  cpl_propertylist_erase_regexp(*plist, "^CUNIT2",0);
1175  cpl_propertylist_insert_after_string(*plist,"CDELT2", "CUNIT2", "um");
1176  cpl_propertylist_set_comment(*plist, "CUNIT2", "spectral unit" );
1177 
1178 
1179 }
1189 static void
1190 sinfo_new_change_plist_spectrum (cpl_propertylist * plist,
1191  double cenLambda,
1192  double dispersion,
1193  int cenpix)
1194 {
1195 
1196  int crpix1=1;
1197  double crval1=1;
1198  double cdelt1=1;
1199 
1200  int crpix2=cenpix;
1201  double crval2=cenLambda;
1202  double cdelt2=dispersion;
1203 
1204 
1205 
1206  cpl_propertylist_erase_regexp(plist, "^CTYPE3",0);
1207  cpl_propertylist_erase_regexp(plist, "^CRPIX3",0);
1208  cpl_propertylist_erase_regexp(plist, "^CRVAL3",0);
1209  cpl_propertylist_erase_regexp(plist, "^CDELT3",0);
1210  cpl_propertylist_erase_regexp(plist, "^CUNIT3",0);
1211 
1212  cpl_propertylist_erase_regexp(plist, "^CTYPE2",0);
1213  cpl_propertylist_erase_regexp(plist, "^CRPIX2",0);
1214  cpl_propertylist_erase_regexp(plist, "^CRVAL2",0);
1215  cpl_propertylist_erase_regexp(plist, "^CDELT2",0);
1216  cpl_propertylist_erase_regexp(plist, "^CUNIT2",0);
1217 
1218 
1219  cpl_propertylist_erase_regexp(plist, "^CD1_1",0);
1220  cpl_propertylist_erase_regexp(plist, "^CD1_2",0);
1221  cpl_propertylist_erase_regexp(plist, "^CD2_1",0);
1222  cpl_propertylist_erase_regexp(plist, "^CD2_2",0);
1223 
1224 
1225 
1226 
1227  sinfo_set_spect_coord1(&plist,crpix1,crval1,cdelt1);
1228  sinfo_set_spect_coord2(&plist,crpix2,crval2,cdelt2);
1229 
1230 
1231 
1232 }
1242 static void
1243 sinfo_new_change_plist_image (cpl_propertylist * plist,
1244  float center_x,
1245  float center_y )
1246 {
1247 
1248  float pixelscale ;
1249  double ra ;
1250  double dec ;
1251  double angle ;
1252  float radangle ;
1253  float cd1_1, cd1_2, cd2_1, cd2_2 ;
1254  char firsttext[2*FILE_NAME_SZ] ;
1255  int sign_swap = -1;
1256 
1257 
1258  double cdelt1=0;
1259  double cdelt2=0;
1260 
1261  double crpix1=center_x;
1262  double crpix2=center_y;
1263 
1264  double crval1=0;
1265  double crval2=0;
1266 
1267 
1268 
1269 
1270  strcpy(firsttext, "sinfo_rec_objnod -f \0") ;
1271 
1272  pixelscale = sinfo_pfits_get_pixscale(plist)/2. ;
1273  ra = sinfo_pfits_get_ra(plist) ;
1274  dec = sinfo_pfits_get_DEC(plist) ;
1275 
1276 
1277 
1278  //get better coordinate values
1279  ra=sinfo_pfits_get_targ_alpha(plist);
1280  dec=sinfo_pfits_get_targ_delta(plist);
1281  ra=sinfo_hms2deg(ra);
1282  dec=sinfo_sess2deg(dec);
1283 
1284 
1285 
1286  crval1=ra;
1287  crval2=dec;
1288 
1289  angle = sinfo_pfits_get_posangle(plist) ;
1290  /* in PUPIL data there is not posangle info: we reset the error */
1291  if(cpl_error_get_code() != CPL_ERROR_NONE) {
1292  cpl_error_reset();
1293  }
1294 
1295  radangle = angle * PI_NUMB / 180. ;
1296 
1297  cdelt1=sign_swap * pixelscale / 3600. ;
1298  cdelt2= pixelscale / 3600. ;
1299 
1300 
1301  cd1_1 = +cdelt1*cos(radangle) ;
1302  cd1_2 = -cdelt2*sin(radangle) ;
1303  cd2_1 = +cdelt1*sin(radangle) ;
1304  cd2_2 = +cdelt2*cos(radangle) ;
1305 
1306 
1307 
1308 
1309 
1310  check_nomsg(sinfo_set_coord1(&plist,crpix1,crval1,cdelt1));
1311  check_nomsg(sinfo_set_coord2(&plist,crpix2,crval2,cdelt2));
1312  check_nomsg(sinfo_set_cd_matrix2(&plist,cd1_1,cd1_2,cd2_1,cd2_2));
1313 
1314 
1315  cleanup:
1316  return;
1317 }
1318 
1326 cpl_imagelist**
1327 sinfo_new_sinfoni_correct_median(cpl_imagelist** cubes, const int n_cubes)
1328 {
1329  int i=0;
1330  cpl_imagelist** cubes_cor=NULL;
1331  double local_median=0;
1332  int z=0;
1333  cpl_image* i_img=NULL;
1334  cpl_image* o_img=NULL;
1335 
1336 
1337  if ( cubes == NULL ) {
1338  sinfo_msg_error ("no cube list given!") ;
1339  return NULL ;
1340  }
1341  if ( n_cubes <= 0 ) {
1342  sinfo_msg_error ("wrong number of data cubes in list!") ;
1343  return NULL ;
1344  }
1345 
1346  cubes_cor = (cpl_imagelist**) cpl_calloc (n_cubes, sizeof (cpl_imagelist*)) ;
1347 
1348  for ( i = 0 ; i < n_cubes ; i++ ) {
1349  cubes_cor[i] = cpl_imagelist_new();
1350  for(z=0;z< cpl_imagelist_get_size(cubes[i]); z++) {
1351  i_img=cpl_imagelist_get(cubes[i],z);
1352  local_median=cpl_image_get_median(i_img);;
1353  o_img=cpl_image_duplicate(i_img);
1354  if(!isnan(local_median)) {
1355  cpl_image_subtract_scalar(o_img,local_median);
1356  }
1357  cpl_imagelist_set(cubes_cor[i],o_img,z);
1358  }
1359  }
1360 
1361  return cubes_cor;
1362 }
1363 
1370 int sinfo_new_sinfoni_correct_median_it(cpl_imagelist** inp)
1371 {
1372 
1373  double local_median=0;
1374  int z=0;
1375  cpl_image* img=NULL;
1376 
1377  for(z=0;z< cpl_imagelist_get_size((*inp)); z++) {
1378  img=cpl_imagelist_get((*inp),z);
1379  local_median=sinfo_new_my_median_image(img);
1380  if(!isnan(local_median)) {
1381  cpl_image_subtract_scalar(img,local_median);
1382  } else {
1383  sinfo_msg_error("local_median is NAN");
1384  }
1385  cpl_imagelist_set((*inp),img,z);
1386  }
1387 
1388  return 0;
1389 }
1390 
1400 cpl_imagelist** sinfo_new_sinfoni_correct_sky(cpl_imagelist** cubes,
1401  const int nc,
1402  cpl_imagelist* sky_cube)
1403 
1404 {
1405  cpl_imagelist** cubes_sky=NULL;
1406  int x=0;
1407  int y=0;
1408  int z=0;
1409  int i=0;
1410  float k=0.5;
1411  int ovr=0;
1412  int ks=0;
1413  int nclip=0;
1414  double med=0;
1415  double avg=0;
1416  double sig=0;
1417  int msk_sum=0;
1418  double val_msk_sum=0;
1419  cpl_vector* val=NULL;
1420  cpl_vector* msk=NULL;
1421  int ilx=0;
1422  int ily=0;
1423  int inp=0;
1424 
1425 
1426  int sky_lx=0;
1427  /* int sky_ly=0; */
1428 
1429  float* pidata=NULL;
1430  float* p_sky_data=NULL;
1431  cpl_image* i_img=NULL;
1432  cpl_image* sky_img=NULL;
1433 
1434 
1435  if ( cubes == NULL ) {
1436  sinfo_msg_error ("no cube list given!") ;
1437  return NULL ;
1438  }
1439  ilx=cpl_image_get_size_x(cpl_imagelist_get(cubes[0],0));
1440  ily=cpl_image_get_size_y(cpl_imagelist_get(cubes[0],0));
1441  inp=cpl_imagelist_get_size(cubes[0]);
1442 
1443 
1444  sky_lx=cpl_image_get_size_x(cpl_imagelist_get(sky_cube,0));
1445  /* sky_ly=cpl_image_get_size_y(cpl_imagelist_get(sky_cube,0)); */
1446  if ( nc <= 0 ) {
1447  sinfo_msg_error ("wrong number of data cubes in list!") ;
1448  return NULL ;
1449  }
1450 
1451  cubes_sky = (cpl_imagelist**) cpl_calloc (nc, sizeof (cpl_imagelist*)) ;
1452  for(z=0;z< inp; z++) {
1453  sky_img=cpl_imagelist_get(sky_cube,z);
1454  p_sky_data=cpl_image_get_data_float(sky_img);
1455  for(y=0;y< ily; y++) {
1456  for(x=0;x< ilx; x++) {
1457  /* here we start to do a k-s clipping */
1458  msk=cpl_vector_new(nc);
1459  for (i=0;i<nc;i++) {
1460  cpl_vector_set(msk,i,1);
1461  }
1462  nclip=0;
1463  for (ks=0;ks<nc;ks++) {
1464  sig=0;
1465  med=0;
1466  ovr=0;
1467  val=cpl_vector_new(nc-nclip);
1468 
1469  for ( i = 0 ; i < nc ; i++ ) {
1470  i_img=cpl_imagelist_get(cubes[i],z);
1471  pidata=cpl_image_get_data_float(i_img);
1472  if ((!isnan(pidata[x+y*ilx])) &&
1473  (cpl_vector_get(msk,i) != 0) ) {
1474  cpl_vector_set(val,ovr,(double)pidata[x+y*ilx]);
1475  ovr++;
1476  }
1477  }
1478 
1479  if(ovr>0) {
1480  avg=cpl_vector_get_mean(val);
1481  med=cpl_vector_get_median_const(val);
1482  if(ovr>1) {
1483  sig=cpl_vector_get_stdev(val);
1484  } else {
1485  sig=0;
1486  }
1487  } else {
1488  avg=cpl_vector_get(val,0);
1489  med=avg;
1490  sig=0;
1491  }
1492 
1493  cpl_vector_delete(val);
1494  for ( i = 0 ; i < nc ; i++ ) {
1495  i_img=cpl_imagelist_get(cubes[i],z);
1496  pidata=cpl_image_get_data_float(i_img);
1497  /* Do k-s clipping at each pixel */
1498  if ((!isnan(pidata[x+y*ilx])) &&
1499  (cpl_vector_get(msk,i) != 0)) {
1500  if(abs((pidata[x+y*ilx]-med))> k*sig) {
1501  cpl_vector_set(msk,i,0);
1502  nclip++;
1503  }
1504  }
1505  }
1506  }/* end of k-s clipping */
1507  msk_sum=0;
1508  val_msk_sum=0;
1509  for ( i = 0 ; i < nc ; i++ ) {
1510  /* computes sky at each point */
1511  if (!isnan(pidata[x+y*ilx])) {
1512  msk_sum+=cpl_vector_get(msk,i);
1513  val_msk_sum+=pidata[x+y*ilx]*
1514  cpl_vector_get(msk,i);
1515  }
1516  }
1517  p_sky_data[x+y*sky_lx]=val_msk_sum/msk_sum;
1518  cpl_vector_delete(msk);
1519  } /* end loop over x */
1520  } /* end loop over y */
1521  } /* end loop over z */
1522  for ( i = 0 ; i < nc ; i++ ) {
1523  cubes_sky[i]=cpl_imagelist_duplicate(cubes[i]);
1524  /* subtract the variable clean sky */
1525  cpl_imagelist_subtract(cubes_sky[i],sky_cube);
1526 
1527  }
1528 
1529 
1530  return cubes_sky;
1531 }
1532 
1547 cpl_imagelist** sinfo_new_sinfoni_correct_sky2(cpl_imagelist** cubes,
1548  const int nc,
1549  cpl_imagelist* sky_cube,
1550  cpl_imagelist* med_cube,
1551  cpl_imagelist* msk_cube,
1552  cpl_imagelist* avg_cube,
1553  cpl_imagelist* sig_cube,
1554  cpl_imagelist* ovr_cube)
1555 {
1556  cpl_imagelist** cubes_sky=NULL;
1557  int x=0;
1558  int y=0;
1559  int z=0;
1560  int i=0;
1561  float k=0.5;
1562  int ovr=0;
1563  int ks=0;
1564  int nclip=0;
1565  double med=0;
1566  double avg=0;
1567  double sig=0;
1568  int msk_sum=0;
1569  double val_msk_sum=0;
1570  cpl_vector* val=NULL;
1571  cpl_vector* msk=NULL;
1572 
1573  int ilx=0;
1574  int ily=0;
1575  int inp=0;
1576 
1577  int ovr_lx=0;
1578  int msk_lx=0;
1579  int avg_lx=0;
1580  int sig_lx=0;
1581  int sky_lx=0;
1582  int med_lx=0;
1583 
1584 
1585  float* p_ovr_data=NULL;
1586  float* p_msk_data=NULL;
1587  float* p_avg_data=NULL;
1588  float* p_sig_data=NULL;
1589  float* p_sky_data=NULL;
1590  float* p_med_data=NULL;
1591 
1592  float* pidata=NULL;
1593 
1594  if ( cubes == NULL ) {
1595  sinfo_msg_error ("no cube list given!") ;
1596  return NULL ;
1597  }
1598 
1599  ilx=cpl_image_get_size_x(cpl_imagelist_get(cubes[0],0));
1600  ily=cpl_image_get_size_y(cpl_imagelist_get(cubes[0],0));
1601  inp=cpl_imagelist_get_size(cubes[0]);
1602 
1603  if ( nc <= 0 ) {
1604  sinfo_msg_error ("wrong number of data cubes in list!") ;
1605  return NULL ;
1606  }
1607 
1608  cubes_sky = (cpl_imagelist**) cpl_calloc (nc, sizeof (cpl_imagelist*)) ;
1609 
1610  ovr_lx=ilx;
1611  msk_lx=ilx;
1612  avg_lx=ilx;
1613  sig_lx=ilx;
1614  sky_lx=ilx;
1615  med_lx=ilx;
1616 
1617  for(z=0;z< inp; z++) {
1618  p_ovr_data=cpl_image_get_data_float(cpl_imagelist_get(ovr_cube,z));
1619  p_msk_data=cpl_image_get_data_float(cpl_imagelist_get(msk_cube,z));
1620  p_avg_data=cpl_image_get_data_float(cpl_imagelist_get(avg_cube,z));
1621  p_sig_data=cpl_image_get_data_float(cpl_imagelist_get(sig_cube,z));
1622  p_sky_data=cpl_image_get_data_float(cpl_imagelist_get(sky_cube,z));
1623  p_med_data=cpl_image_get_data_float(cpl_imagelist_get(med_cube,z));
1624 
1625 
1626  for(y=0;y< ily; y++) {
1627  for(x=0;x< ilx; x++) {
1628  /* here we start to do a k-s clipping */
1629  msk=cpl_vector_new(nc);
1630  for (i=0;i<nc;i++) {
1631  cpl_vector_set(msk,i,1);
1632  }
1633  p_ovr_data[x+y*ovr_lx]=nc;
1634  p_msk_data[x+y*msk_lx]=nc;
1635  nclip=0;
1636  for (ks=0;ks<nc;ks++) {
1637  sig=0;
1638  med=0;
1639  ovr=0;
1640  val=cpl_vector_new(nc-nclip);
1641 
1642  for ( i = 0 ; i < nc ; i++ ) {
1643  pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
1644  if ((!isnan(pidata[x+y*ilx])) &&
1645  (cpl_vector_get(msk,i) != 0) ) {
1646  cpl_vector_set(val,ovr,(double)pidata[x+y*ilx]);
1647  ovr++;
1648  }
1649  }
1650 
1651  if(ovr>1) {
1652  avg=cpl_vector_get_mean(val);
1653  med=cpl_vector_get_median_const(val);
1654  sig=cpl_vector_get_stdev(val);
1655  } else {
1656  avg=cpl_vector_get(val,0);
1657  med=avg;
1658  sig=0;
1659  }
1660 
1661  p_med_data[x+y*med_lx]=med;
1662  p_avg_data[x+y*avg_lx]=avg;
1663  p_sig_data[x+y*sig_lx]=sig;
1664  cpl_vector_delete(val);
1665  for ( i = 0 ; i < nc ; i++ ) {
1666  pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
1667  /* Do k-s clipping at each pixel */
1668  if ((!isnan(pidata[x+y*ilx])) &&
1669  (cpl_vector_get(msk,i) != 0)) {
1670  if(abs((pidata[x+y*ilx]-med))> k*sig) {
1671  /* pidata[x+y*ilx]=0; */
1672  p_msk_data[x+y*msk_lx]-=1;
1673  cpl_vector_set(msk,i,0);
1674  nclip++;
1675  }
1676  }
1677  }
1678  }/* end of k-s clipping */
1679  msk_sum=0;
1680  val_msk_sum=0;
1681  for ( i = 0 ; i < nc ; i++ ) {
1682  pidata=cpl_image_get_data_float(cpl_imagelist_get(cubes[i],z));
1683  /* computes sky at each point */
1684  if (!isnan(pidata[x+y*ilx])) {
1685  /*
1686  msk_sum+=p_msk_data[x+y*msk_lx];
1687  val_msk_sum+=pidata[x+y*cubes[i]->lx]*
1688  p_msk_data[x+y*msk_lx];
1689  */
1690  msk_sum+=cpl_vector_get(msk,i);
1691  val_msk_sum+=pidata[x+y*ilx]*
1692  cpl_vector_get(msk,i);
1693  }
1694  }
1695  p_sky_data[x+y*sky_lx]=val_msk_sum/msk_sum;
1696  cpl_vector_delete(msk);
1697  } /* end loop over x */
1698  } /* end loop over y */
1699  } /* end loop over z */
1700  for ( i = 0 ; i < nc ; i++ ) {
1701  cubes_sky[i]=cpl_imagelist_duplicate(cubes[i]);
1702  /* subtract the variable clean sky */
1703  cpl_imagelist_subtract(cubes_sky[i],sky_cube);
1704  }
1705 
1706 
1707  return cubes_sky;
1708 }
1709 
1710 
1723 int
1724 sinfo_new_assign_offset(const int n,
1725  const char* name,
1726  float* offsetx,
1727  float* offsety,
1728  const float ref_offx,
1729  const float ref_offy)
1730 {
1731 
1732  float offx=0;
1733  float offy=0;
1734  double mjd_obs=0;
1735  /*
1736  double pixelscale=0;
1737  double angle=0;
1738  double radangle=0;
1739  double cd1_1=0;
1740  double cd1_2=0;
1741  double cd2_1=0;
1742  double cd2_2=0;
1743  double ra=0;
1744  double dec=0;
1745  */
1746 
1747  cpl_propertylist * plist=NULL;
1748  sinfo_msg_debug("Assign offsets");
1749 
1750  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
1751  sinfo_msg_error( "getting header from reference frame %s",name);
1752  cpl_propertylist_delete(plist) ;
1753  return -1 ;
1754  }
1755 
1756  offx = sinfo_pfits_get_cumoffsetx(plist) - ref_offx ; /* was - */
1757  if(cpl_error_get_code() != CPL_ERROR_NONE) {
1758  sinfo_msg_warning(" could not read fits header keyword cummoffsetx!") ;
1759  sinfo_msg_warning(" Set relative offset to 0 - %f!",ref_offx) ;
1760  offx = - ref_offx;
1761  cpl_error_reset();
1762  /* return -1 ; */
1763  }
1764 
1765  offy = sinfo_pfits_get_cumoffsety(plist) - ref_offy ; /* was - */
1766  if(cpl_error_get_code() != CPL_ERROR_NONE) {
1767  sinfo_msg_warning(" could not read fits header keyword! cumoffsety") ;
1768  sinfo_msg_warning(" Set relative offset to 0 - %f!",ref_offx) ;
1769  offy = - ref_offy;
1770  cpl_error_reset();
1771  /* return -1 ; */
1772  }
1773  sinfo_msg_debug("offx=%f offy=%f",offx,offy);
1774 
1775  if (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
1776  mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
1777  } else {
1778  sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
1779  cpl_propertylist_delete(plist) ;
1780  return -1;
1781  }
1782 
1783  cpl_propertylist_delete(plist) ;
1784 
1785  if (mjd_obs > 53825. ) {
1786  /* April 1st 2006 */
1787  //sinfo_msg("New cumoffset setting convention");
1788  sinfo_new_array_set_value(offsetx,2*offx,n);
1789  sinfo_new_array_set_value(offsety,2*offy,n);
1790  } else if ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
1791  /* after detector's upgrade */
1792  /*
1793  sinfo_new_array_set_value(offsetx,-offx*2,n);
1794  sinfo_new_array_set_value(offsety,+offy*2,n);
1795  */
1796  sinfo_new_array_set_value(offsetx,-2*offx,n);
1797  sinfo_new_array_set_value(offsety,2*offy,n);
1798  } else {
1799  /* before detector's upgrade */
1800  /*
1801  sinfo_new_array_set_value(offsetx,+offx*2,n);
1802  sinfo_new_array_set_value(offsety,-offy*2,n);
1803  */
1804  sinfo_new_array_set_value(offsetx,2*offx,n);
1805  sinfo_new_array_set_value(offsety,-2*offy,n);
1806  }
1807 
1808  return 0;
1809 
1810 
1811 }
1812 
1813 
1814 
1815 
1816 
1829 int
1830 sinfo_new_assign_offset2(const int n,
1831  const char* name,
1832  float* offsetx,
1833  float* offsety,
1834  const float ref_offx,
1835  const float ref_offy)
1836 {
1837 
1838  float offx=0;
1839  float offy=0;
1840  double mjd_obs=0;
1841 
1842  cpl_propertylist * plist=NULL;
1843  sinfo_msg_debug("Assign offsets as set by user");
1844  offx = offsetx[n] - ref_offx ; /* was - */
1845  offy = offsety[n] - ref_offy ; /* was - */
1846  sinfo_msg_debug("offx=%f offy=%f",offx,offy);
1847 
1848  sinfo_msg_debug("Assign offsets");
1849 
1850  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
1851  sinfo_msg_error( "getting header from reference frame %s",name);
1852  cpl_propertylist_delete(plist) ;
1853  return -1 ;
1854  }
1855 
1856  if (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
1857  mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
1858  } else {
1859  sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
1860  cpl_propertylist_delete(plist) ;
1861  return -1;
1862  }
1863  cpl_propertylist_delete(plist) ;
1864 
1865  //sinfo_new_array_set_value(offsetx,-2*offx,n);
1866  //sinfo_new_array_set_value(offsety,2*offy,n);
1867 
1868  if (mjd_obs > 53825. ) {
1869  /* April 1st 2006 */
1870  //sinfo_msg("New cumoffset setting convention");
1871  sinfo_new_array_set_value(offsetx,2*offx,n);
1872  sinfo_new_array_set_value(offsety,2*offy,n);
1873  } else if ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
1874  /* after detector's upgrade */
1875  /*
1876  sinfo_new_array_set_value(offsetx,-offx*2,n);
1877  sinfo_new_array_set_value(offsety,+offy*2,n);
1878  */
1879  sinfo_new_array_set_value(offsetx,-2*offx,n);
1880  sinfo_new_array_set_value(offsety,2*offy,n);
1881  } else {
1882  /* before detector's upgrade */
1883  /*
1884  sinfo_new_array_set_value(offsetx,+offx*2,n);
1885  sinfo_new_array_set_value(offsety,-offy*2,n);
1886  */
1887  sinfo_new_array_set_value(offsetx,2*offx,n);
1888  sinfo_new_array_set_value(offsety,-2*offy,n);
1889  }
1890 
1891 
1892  return 0;
1893 
1894 
1895 }
1896 
1897 
1910 int
1911 sinfo_new_object_assign_offset(const char* name,
1912  const int n,
1913  double* ref_offx,
1914  double* ref_offy,
1915  float** offsetx,
1916  float** offsety)
1917 {
1918 
1919  float offx=0;
1920  float offy=0;
1921  double mjd_obs=0;
1922  cpl_propertylist * plist=NULL;
1923  sinfo_msg_debug("Assign offsets");
1924 
1925  if ((cpl_error_code)((plist = cpl_propertylist_load(name, 0)) == NULL)) {
1926  sinfo_msg_error( "getting header from reference frame %s",name);
1927  cpl_propertylist_delete(plist) ;
1928  return -1 ;
1929  }
1930  if ( n == 0 ) {
1931 
1932  *ref_offx = sinfo_pfits_get_cumoffsetx(plist) ;
1933  if(cpl_error_get_code() != CPL_ERROR_NONE) {
1934  sinfo_msg_error(" could not read fits header keyword cummoffsetx!") ;
1935  /* return -1 ; */
1936  cpl_error_reset();
1937  }
1938 
1939  *ref_offy = sinfo_pfits_get_cumoffsety(plist) ;
1940  if(cpl_error_get_code() != CPL_ERROR_NONE) {
1941  sinfo_msg_error(" could not read fits header keyword! cumoffsety") ;
1942  cpl_error_reset();
1943  /* return -1 ; */
1944  }
1945  sinfo_msg_debug("Reference offx=%f offy=%f",*ref_offx,*ref_offy);
1946 
1947  offx = 0. ;
1948  offy = 0. ;
1949 
1950  } else {
1951 
1952  offx = sinfo_pfits_get_cumoffsetx(plist) - *ref_offx ; /* was - */
1953  if(cpl_error_get_code() != CPL_ERROR_NONE) {
1954  sinfo_msg_error(" could not read fits header keyword cummoffsetx!") ;
1955  cpl_error_reset();
1956  /* return -1 ; */
1957  }
1958 
1959  offy = sinfo_pfits_get_cumoffsety(plist) - *ref_offy ; /* was - */
1960  if(cpl_error_get_code() != CPL_ERROR_NONE) {
1961  sinfo_msg_error(" could not read fits header keyword! cumoffsety") ;
1962  /* return -1 ; */
1963  cpl_error_reset();
1964  }
1965  sinfo_msg_debug("offx=%f offy=%f",offx,offy);
1966  }
1967 
1968 
1969  /* rotate the coordinates
1970  offx_rot = cd1_1 * offx + cd2_1 * offy ;
1971  offy_rot = cd1_2 * offx + cd2_2 * offy ;
1972  convert the coordinates to pixel units
1973  offx_rot_pix = offx_rot / pixelscale ;
1974  offy_rot_pix = offy_rot / pixelscale ;
1975  offsetx[i] = offx_rot_pix ;
1976  offsety[i] = offy_rot_pix ;
1977  */
1978 
1979 
1980  if (sinfo_propertylist_has(plist, KEY_NAME_MJD_OBS)) {
1981  mjd_obs=cpl_propertylist_get_double(plist, KEY_NAME_MJD_OBS);
1982  } else {
1983  sinfo_msg_error("keyword %s does not exist",KEY_NAME_MJD_OBS);
1984  cpl_propertylist_delete(plist) ;
1985  return -1;
1986  }
1987 
1988  cpl_propertylist_delete(plist) ;
1989 
1990  if (mjd_obs > 53825. ) {
1991  /* April 1st 2006 */
1992  //sinfo_msg("New cumoffset setting convention");
1993  sinfo_new_array_set_value(*offsetx,2*offx,n);
1994  sinfo_new_array_set_value(*offsety,2*offy,n);
1995  } else if ((mjd_obs > 53421.58210082 ) && (mjd_obs <= 53825.)){
1996  /* after detector's upgrade */
1997  sinfo_new_array_set_value(*offsetx,-offx*2,n);
1998  sinfo_new_array_set_value(*offsety,+offy*2,n);
1999  } else {
2000  /* before detector's upgrade */
2001  sinfo_new_array_set_value(*offsetx,+offx*2,n);
2002  sinfo_new_array_set_value(*offsety,-offy*2,n);
2003  }
2004 
2005  return 0;
2006 }
2007 
2019 cpl_imagelist*
2020 sinfo_new_fine_tune(cpl_imagelist* cube,
2021  float* correct_dist,
2022  const char* method,
2023  const int order,
2024  const int nslits) {
2025  int i =0;
2026  cpl_imagelist* outcube2=NULL;
2027  float* neg_dist=NULL;
2028  sinfo_msg("Finetuning, method=%s",method);
2029 
2030  if (strcmp(method,"P")==0)
2031  {
2032  outcube2 = sinfo_new_fine_tune_cube( cube, correct_dist, order ) ;
2033  if (outcube2 == NULL)
2034  {
2035  sinfo_msg_error (" could not fine tune the data cube\n") ;
2036  return NULL ;
2037  }
2038  }
2039  else if (strcmp(method,"F")==0)
2040  {
2041  neg_dist=cpl_calloc(nslits,sizeof(float));
2042  for ( i = 0 ; i < nslits ; i++ )
2043  {
2044  neg_dist[i] = -correct_dist[i] ;
2045  }
2046  outcube2 = sinfo_new_fine_tune_cube_by_FFT( cube, neg_dist ) ;
2047  cpl_free(neg_dist);
2048  if ( outcube2 == NULL )
2049  {
2050  sinfo_msg_error (" could not fine tune the data cube\n") ;
2051  return NULL ;
2052  }
2053  }
2054  else if (strcmp(method,"S")==0)
2055  {
2056  outcube2 = sinfo_new_fine_tune_cube_by_spline( cube, correct_dist ) ;
2057  if ( outcube2 == NULL )
2058  {
2059  sinfo_msg_error (" could not fine tune the data cube\n") ;
2060  return NULL ;
2061  }
2062  }
2063  else
2064  {
2065  sinfo_msg_error (" wrong method indicator given!") ;
2066  return NULL ;
2067  }
2068 
2069 
2070 
2071 return outcube2;
2072 
2073 }
2074 
2075 /*----------------------------------------------------------------------------*/
2081 /*----------------------------------------------------------------------------*/
2082 sinfo_band sinfo_get_associated_filter(const char * f)
2083 {
2084  if (!strcmp(f, "J")) return SINFO_BAND_J ;
2085  if (!strcmp(f, "Js")) return SINFO_BAND_JS ;
2086  if (!strcmp(f, "Z")) return SINFO_BAND_Z ;
2087  if (!strcmp(f, "SZ")) return SINFO_BAND_SZ ;
2088  if (!strcmp(f, "SH")) return SINFO_BAND_SH ;
2089  if (!strcmp(f, "H")) return SINFO_BAND_H ;
2090  if (!strcmp(f, "Ks")) return SINFO_BAND_KS ;
2091  if (!strcmp(f, "K")) return SINFO_BAND_K ;
2092  if (!strcmp(f, "SK")) return SINFO_BAND_SK ;
2093  if (!strcmp(f, "L")) return SINFO_BAND_L ;
2094  if (!strcmp(f, "SL")) return SINFO_BAND_SL ;
2095  if (!strcmp(f, "M")) return SINFO_BAND_M ;
2096  if (!strcmp(f, "M_NB")) return SINFO_BAND_M ;
2097  if (!strcmp(f, "NB_1.06")) return SINFO_BAND_J ;
2098  if (!strcmp(f, "NB_1.08")) return SINFO_BAND_J ;
2099  if (!strcmp(f, "NB_1.19")) return SINFO_BAND_J ;
2100  if (!strcmp(f, "NB_1.21")) return SINFO_BAND_J ;
2101  if (!strcmp(f, "NB_1.26")) return SINFO_BAND_J ;
2102  if (!strcmp(f, "NB_1.28")) return SINFO_BAND_J ;
2103  if (!strcmp(f, "NB_1.64")) return SINFO_BAND_H ;
2104  if (!strcmp(f, "NB_1.71")) return SINFO_BAND_H ;
2105  if (!strcmp(f, "NB_2.07")) return SINFO_BAND_KS ;
2106  if (!strcmp(f, "NB_2.09")) return SINFO_BAND_KS ;
2107  if (!strcmp(f, "NB_2.13")) return SINFO_BAND_KS ;
2108  if (!strcmp(f, "NB_2.17")) return SINFO_BAND_KS ;
2109  if (!strcmp(f, "NB_2.19")) return SINFO_BAND_KS ;
2110  if (!strcmp(f, "NB_2.25")) return SINFO_BAND_KS ;
2111  if (!strcmp(f, "NB_2.29")) return SINFO_BAND_KS ;
2112  if (!strcmp(f, "NB_2.34")) return SINFO_BAND_KS ;
2113  if (!strcmp(f, "NB_3.21")) return SINFO_BAND_L ;
2114  if (!strcmp(f, "NB_3.28")) return SINFO_BAND_L ;
2115  if (!strcmp(f, "NB_3.80")) return SINFO_BAND_L ;
2116  if (!strcmp(f, "NB_4.07")) return SINFO_BAND_L ;
2117  return SINFO_BAND_UNKNOWN ;
2118 }
2119 
2120 
2121 
2122 /*----------------------------------------------------------------------------*/
2128 /*----------------------------------------------------------------------------*/
2129 sinfo_band sinfo_get_bbfilter(const char * f)
2130 {
2131  if (!strcmp(f, "J")) return SINFO_BAND_J ;
2132  if (!strcmp(f, "J+Block")) return SINFO_BAND_J ;
2133  if (!strcmp(f, "Js")) return SINFO_BAND_J ;
2134  if (!strcmp(f, "Z")) return SINFO_BAND_J ;
2135  if (!strcmp(f, "SZ")) return SINFO_BAND_J ;
2136  if (!strcmp(f, "SH")) return SINFO_BAND_H ;
2137  if (!strcmp(f, "H")) return SINFO_BAND_H ;
2138  if (!strcmp(f, "Ks")) return SINFO_BAND_KS ;
2139  if (!strcmp(f, "K")) return SINFO_BAND_K ;
2140  if (!strcmp(f, "SK")) return SINFO_BAND_K ;
2141  if (!strcmp(f, "L")) return SINFO_BAND_L ;
2142  if (!strcmp(f, "SL")) return SINFO_BAND_L ;
2143  if (!strcmp(f, "M")) return SINFO_BAND_M ;
2144  if (!strcmp(f, "M_NB")) return SINFO_BAND_M ;
2145  if (!strcmp(f, "NB_1.06")) return SINFO_BAND_J ;
2146  if (!strcmp(f, "NB_1.08")) return SINFO_BAND_J ;
2147  if (!strcmp(f, "NB_1.19")) return SINFO_BAND_J ;
2148  if (!strcmp(f, "NB_1.21")) return SINFO_BAND_J ;
2149  if (!strcmp(f, "NB_1.26")) return SINFO_BAND_J ;
2150  if (!strcmp(f, "NB_1.28")) return SINFO_BAND_J ;
2151  if (!strcmp(f, "NB_1.64")) return SINFO_BAND_H ;
2152  if (!strcmp(f, "NB_1.71")) return SINFO_BAND_H ;
2153  if (!strcmp(f, "NB_2.07")) return SINFO_BAND_KS ;
2154  if (!strcmp(f, "NB_2.09")) return SINFO_BAND_KS ;
2155  if (!strcmp(f, "NB_2.13")) return SINFO_BAND_KS ;
2156  if (!strcmp(f, "NB_2.17")) return SINFO_BAND_KS ;
2157  if (!strcmp(f, "NB_2.19")) return SINFO_BAND_KS ;
2158  if (!strcmp(f, "NB_2.25")) return SINFO_BAND_KS ;
2159  if (!strcmp(f, "NB_2.29")) return SINFO_BAND_KS ;
2160  if (!strcmp(f, "NB_2.34")) return SINFO_BAND_KS ;
2161  if (!strcmp(f, "NB_3.21")) return SINFO_BAND_L ;
2162  if (!strcmp(f, "NB_3.28")) return SINFO_BAND_L ;
2163  if (!strcmp(f, "NB_3.80")) return SINFO_BAND_L ;
2164  if (!strcmp(f, "NB_4.07")) return SINFO_BAND_L ;
2165  return SINFO_BAND_UNKNOWN ;
2166 }
2167 
2168