OMEGA Pipeline Reference Manual  1.0.5
omega_pfits.c
1 /* $Id: omega_pfits.c,v 1.11 2012-03-30 11:13:41 agabasch Exp $
2  *
3  * This file is part of the oc_ Pipeline
4  * Copyright (C) 2002,2003 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: agabasch $
23  * $Date: 2012-03-30 11:13:41 $
24  * $Revision: 1.11 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 #include <string.h>
33 
34 #include "omega_pfits.h"
35 #include "omega_stats.h"
36 #include "omega_utils.h"
37 
38 static int omega_get_quadrant(const char * extname, int filtno);
39 
55 /* Static Functions */
56 static void omega_property_dump(cpl_property *property)
57 {
58 
59  const char *name = cpl_property_get_name(property);
60  const char *comment = cpl_property_get_comment(property);
61 
62  char c;
63 
64  long size = cpl_property_get_size(property);
65 
66  cpl_type type = cpl_property_get_type(property);
67 
68 
69  cpl_msg_info(cpl_func, "Property at address %p", property);
70  cpl_msg_info(cpl_func, "\tname : %p '%s'", name, name);
71  cpl_msg_info(cpl_func, "\tcomment: %p '%s'", comment, comment);
72  cpl_msg_info(cpl_func, "\ttype : %#09x", type);
73  cpl_msg_info(cpl_func, "\tsize : %ld", size);
74  cpl_msg_info(cpl_func, "\tvalue : ");
75 
76 
77  switch (type) {
78  case CPL_TYPE_CHAR:
79  c = cpl_property_get_char(property);
80  if (!c)
81  fprintf(stderr, "''");
82  else
83  fprintf(stderr, "'%c'", c);
84  break;
85 
86  case CPL_TYPE_BOOL:
87  fprintf(stderr, "%d", cpl_property_get_bool(property));
88  break;
89 
90  case CPL_TYPE_INT:
91  fprintf(stderr, "%d", cpl_property_get_int(property));
92  break;
93 
94  case CPL_TYPE_LONG:
95  fprintf(stderr, "%ld", cpl_property_get_long(property));
96  break;
97 
98  case CPL_TYPE_FLOAT:
99  fprintf(stderr, "%.7g", cpl_property_get_float(property));
100  break;
101 
102  case CPL_TYPE_DOUBLE:
103  fprintf(stderr, "%.15g", cpl_property_get_double(property));
104  break;
105 
106  case CPL_TYPE_STRING:
107  fprintf(stderr, "'%s'", cpl_property_get_string(property));
108  break;
109 
110  default:
111  fprintf(stderr, "unknown.");
112  break;
113 
114  }
115 
116  fprintf(stderr, "\n");
117 
118  return;
119 
120 }
121 
122 /*----------------------------------------------------------------------------
123  *@brief find out the date of observation
124  *@param plist property list to read from
125  *@return pointer to statically allocated character string
126  *
127  *----------------------------------------------------------------------------*/
128 
129 const char * omega_pfits_get_date_obs(const cpl_propertylist * plist)
130 {
131  return (const char *) cpl_propertylist_get_string(plist, "DATE-OBS") ;
132 }
133 
134 /*----------------------------------------------------------------------------*/
141 /*----------------------------------------------------------------------------*/
142 const char * omega_pfits_get_arcfile(const cpl_propertylist * plist)
143 {
144  return (const char *) cpl_propertylist_get_string(plist, "ARCFILE");
145 }
146 
147 /*----------------------------------------------------------------------------*/
153 /*----------------------------------------------------------------------------*/
154 double omega_pfits_get_dit(const cpl_propertylist * plist)
155 {
156  if (cpl_propertylist_has(plist, "ESO DET DIT") == 1)
157  return cpl_propertylist_get_double(plist, "ESO DET DIT");
158  else
159  return 0.0;
160 }
161 
162 /*----------------------------------------------------------------------------*/
168 /*----------------------------------------------------------------------------*/
169 const char * omega_pfits_get_templateid(const cpl_propertylist * plist)
170 {
171  return (const char *) cpl_propertylist_get_string(plist, "ESO TPL ID") ;
172 }
173 
174 /*----------------------------------------------------------------------------*/
180 /*----------------------------------------------------------------------------*/
181 double omega_pfits_get_mjdobs(const cpl_propertylist * plist)
182 {
183  return cpl_propertylist_get_double(plist, "MJD-OBS") ;
184 }
185 
186 /*----------------------------------------------------------------------------*/
192 /*----------------------------------------------------------------------------*/
193 double omega_pfits_get_exptime(const cpl_propertylist * plist)
194 {
195 
196  if(cpl_propertylist_has(plist, "EXPTIME")){
197  return cpl_propertylist_get_double(plist, "EXPTIME") ;
198  }
199  else{
200  return 0.0;
201  }
202 }
203 
204 
205 /*---------------------------------------------------------------------------*/
212 /*---------------------------------------------------------------------------*/
213 
214 extern int omega_pfits_get_detlive(const cpl_propertylist *plist,
215  int *detlive)
216 {
217  int val;
218 
219  if(cpl_propertylist_has(plist, "ESO DET CHIP LIVE") == 0){
220  cpl_error_reset();
221  *detlive = 1;
222  return 0;
223  }
224 
225  val = cpl_propertylist_get_bool(plist,"ESO DET CHIP LIVE");
226  if (cpl_error_get_code() == CPL_ERROR_NONE) {
227  *detlive = val;
228  return 0;
229  } else {
230  cpl_error_reset();
231  *detlive = 1;
232  return -1;
233  }
234 }
235 
236 /*----------------------------------------------------------------------------*/
244 /*----------------------------------------------------------------------------*/
245 int omega_pfits_get_orientation(const char *chip)
246 {
247 
248  int orient = 0;
249 
250  /*
251  For WFI with EXTNAME < 5
252  if( (strcmp(chip, "ccd50")==0)||(strcmp(chip, "ccd51")==0)||
253  (strcmp(chip, "ccd52")==0)||(strcmp(chip, "ccd53")==0) ) {
254 
255  orient = 2;
256  }
257  else { For all OmegaCAM EXTNAME
258  orient = 1;
259  }
260  */
261  if(strcmp(chip, "ESO_CCD_#65" )==0 ||
262  strcmp(chip, "ESO_CCD_#66" )==0 ||
263  strcmp(chip, "ESO_CCD_#67" )==0 ||
264  strcmp(chip, "ESO_CCD_#68" )==0 ||
265  strcmp(chip, "ESO_CCD_#69" )==0 ||
266  strcmp(chip, "ESO_CCD_#70" )==0 ||
267  strcmp(chip, "ESO_CCD_#71" )==0 ||
268  strcmp(chip, "ESO_CCD_#72" )==0 ||
269  strcmp(chip, "ESO_CCD_#73" )==0 ||
270  strcmp(chip, "ESO_CCD_#74" )==0 ||
271  strcmp(chip, "ESO_CCD_#75" )==0 ||
272  strcmp(chip, "ESO_CCD_#76" )==0 ||
273  strcmp(chip, "ESO_CCD_#77" )==0 ||
274  strcmp(chip, "ESO_CCD_#78" )==0 ||
275  strcmp(chip, "ESO_CCD_#79" )==0 ||
276  strcmp(chip, "ESO_CCD_#80" )==0){
277  /*The readout port is located in the lower left of the ccd*/
278  orient = 1;
279  }
280  else if (strcmp(chip, "ESO_CCD_#81" )==0 ||
281  strcmp(chip, "ESO_CCD_#82" )==0 ||
282  strcmp(chip, "ESO_CCD_#83" )==0 ||
283  strcmp(chip, "ESO_CCD_#84" )==0 ||
284  strcmp(chip, "ESO_CCD_#85" )==0 ||
285  strcmp(chip, "ESO_CCD_#86" )==0 ||
286  strcmp(chip, "ESO_CCD_#87" )==0 ||
287  strcmp(chip, "ESO_CCD_#88" )==0 ||
288  strcmp(chip, "ESO_CCD_#89" )==0 ||
289  strcmp(chip, "ESO_CCD_#90" )==0 ||
290  strcmp(chip, "ESO_CCD_#91" )==0 ||
291  strcmp(chip, "ESO_CCD_#92" )==0 ||
292  strcmp(chip, "ESO_CCD_#93" )==0 ||
293  strcmp(chip, "ESO_CCD_#94" )==0 ||
294  strcmp(chip, "ESO_CCD_#95" )==0 ||
295  strcmp(chip, "ESO_CCD_#96" )==0){
296  /*The readout port is located in the upper right of the ccd*/
297  orient = 2;
298  }
299  else {
300  orient = 0;
301  }
302 
303 
304  return orient;
305 }
306 
307 /*----------------------------------------------------------------------------*/
317 /*----------------------------------------------------------------------------*/
318 
319 void omega_pfits_get_xysize(const char *chip, int *xs, int *ys)
320 {
321 
322  int orientation = 0;
323  int prscx = 48; /*FIXME: these 4 values are default in Python code. Is this real??*/
324  int prscy = 0;
325  int ovscx = 48;
326  int ovscy = 30;
327  int naxis1 = 2142;
328  int naxis2 = 4128;
329  int x0 = 1;
330  int x1 = 1;
331  int y0 = 1;
332  int y1 = 1;
333 
334  orientation = omega_pfits_get_orientation(chip);
335 
336 /* Get trim coordinates based on orientation keyword */
337  switch (orientation) {
338  case 1:
339  x0 = prscx + 1;
340  y0 = prscy + 1;
341  x1 = naxis1 - ovscx;
342  y1 = naxis2 - ovscy;
343  break;
344  case 2:
345  x0 = prscx + 1;
346  y0 = ovscy + 1;
347  x1 = naxis1 - ovscx;
348  y1 = naxis2 - prscy;
349  break;
350  case 3:
351  x0 = ovscx + 1;
352  y0 = prscy+ 1;
353  x1 = naxis1 - prscx;
354  y1 = naxis2 - ovscy;
355  break;
356  case 4:
357  x0 = ovscx + 1;
358  y0 = ovscy + 1;
359  x1 = naxis1 - prscx;
360  y1 = naxis2 - prscy;
361  break;
362  default:
363  x0 = prscx + 1;
364  y0 = prscy + 1;
365  x1 = naxis1 - ovscx;
366  y1 = naxis2 - ovscy;
367  break;
368  }
369 
370  *xs = x1 - x0+1;
371  *ys = y1 - y0+1;
372 
373 }
374 
375 
376 /*
377 ----------------------------------------------------------------------------
378 *
379  @brief Gets filter information from header
380  @param main Main property list
381  @param ext Extension property list
382  @return 1 newly allocated property list or NULL in error case
383 
384  This function gets the following information from the main and extension headers.
385  HIERARCH ESO INS FILT1 ID
386  HIERARCH ESO INS FILT1 NAME
387  HIERARCH ESO DET CHIP* ID
388 
389  and associate these values to other information, to return a new
390  propertylist with the following format:
391 
392  const char *FILT_ID
393  const char *FILT_NAME
394  float CWL
395  int HAS_FRINGES
396  const char *CHIP_ID
397 
398 
399 ----------------------------------------------------------------------------
400 cpl_propertylist * omega_pfits_get_filter(const cpl_propertylist *main, const cpl_propertylist *ext)
401 {
402 
403  int has_fringes = 0;
404  int i = 0;
405  int n = 4; change here for correct number of filters
406  int check =0 ;
407  int check1 = 0;
408 
409  double wave_central = 0.0f;
410 
411  char name[80] = "";
412  const char *chipid = NULL;
413  const char *filtid = NULL;
414  const char *filtname = NULL;
415 
416  cpl_propertylist *list;
417 
418  if (main == NULL) {
419  cpl_msg_error(cpl_func,"Main header is empty");
420  return NULL;
421  }
422  if (ext == NULL) {
423  cpl_msg_error(cpl_func,"Extension header is empty");
424  return NULL;
425  }
426 
427  list = cpl_propertylist_new();
428 
429  if (cpl_propertylist_has(main,"ESO INS FILT ID") == 1) {
430  filtid = cpl_propertylist_get_string(main, "ESO INS FILT ID");
431  }
432  else if (cpl_propertylist_has(main,"ESO INS FILT1 ID") == 1) {
433  filtid = cpl_propertylist_get_string(main, "ESO INS FILT1 ID");
434  }
435  else if (cpl_propertylist_has(main,"FILT_ID") == 1) {
436  filtid = cpl_propertylist_get_string(main, "FILT_ID");
437  }
438  else {
439  filtid = "";
440  cpl_msg_warning(cpl_func,"Cannot find FILT_ID information on main header");
441  return NULL;
442  }
443 
444  cpl_propertylist_append_string(list,"FILT_ID", filtid);
445 
446 Get filter name from header
447  if (cpl_propertylist_has(main,"ESO INS FILT1 NAME") == 1){
448  filtname = cpl_propertylist_get_string(main, "ESO INS FILT1 NAME");
449  }
450 
451 
452 FIXME: Modify this once the names of filters are correct
453  for(i=0; i<n; i++) {
454  check = strcmp("842", filtid);
455  check1 = strcmp("#842", filtid);
456  if(check == 0 || check1 == 0) {
457  filtname = "JohnsonB";
458  wave_central = 4562.52;
459  has_fringes = 0; has no fringing
460  break;
461  }
462  check = strcmp("843", filtid);
463  check1 = strcmp("#843", filtid);
464  if(check == 0 || check1 == 0) {
465  filtname = "JohnsonV";
466  wave_central = 5395.62;
467  has_fringes = 0; has no fringing
468  break;
469  }
470  check = strcmp("844", filtid);
471  check1 = strcmp("#844", filtid);
472  if(check == 0 || check1 == 0) {
473  filtname = "CousinsR";
474  wave_central = 6517.25;
475  has_fringes = 0; has no fringing
476  break;
477  }
478  check = strcmp("845", filtid);
479  check1 = strcmp("#845", filtid);
480  if(check == 0 || check1 == 0) {
481  filtname = "CousinsI";
482  wave_central = 7838.45;
483  wave_central = 7900.00;
484  has_fringes = 1; has fringing
485  cpl_msg_info("","%s This filter %s has fringes",_id,filtname);
486  break;
487  }
488  check = strcmp("846", filtid);
489  check1 = strcmp("#846", filtid);
490  if(check == 0 || check1 == 0) {
491  filtname = "CousinsI";
492  wave_central = 9648.19;
493  has_fringes = 1; has fringing
494  cpl_msg_info("","%s This filter %s has fringes",_id,filtname);
495  break;
496  }
497  check = strcmp("879", filtid);
498  check1 = strcmp("#879", filtid);
499  if(check == 0 || check1 == 0) {
500  filtname = "CousinsI";
501  wave_central = 8269.00;
502  has_fringes = 1; has fringing
503  cpl_msg_info("","%s This filter %s has fringes",_id,filtname);
504  break;
505  }
506 Filter names and IDs from Bernard Muschielok
507 FIXME: standard catalog columns must have filter names like these ones
508 FIXME: correct values of wave_central for each filter and the has_fringes too.
509  check = strcmp("PS1", filtid);
510  check1 = strcmp("u_SDSS", filtname);
511  if(check == 0 && check1 == 0) {
512  wave_central = 6517.25;
513  has_fringes = 0; has no fringing
514  break;
515  }
516  check = strcmp("PS2", filtid);
517  check1 = strcmp("g_SDSS", filtname);
518  if(check == 0 && check1 == 0) {
519  wave_central = 6517.25;
520  has_fringes = 0; has no fringing
521  break;
522  }
523  check = strcmp("PS3", filtid);
524  check1 = strcmp("r_SDSS", filtname);
525  if(check == 0 && check1 == 0) {
526  wave_central = 6517.25;
527  has_fringes = 0; has no fringing
528  break;
529  }
530  check = strcmp("PS4", filtid);
531  check1 = strcmp("i_SDSS", filtname);
532  if(check == 0 && check1 == 0) {
533  wave_central = 6517.25;
534  has_fringes = 0; has no fringing
535  break;
536  }
537  check = strcmp("PS5", filtid);
538  check1 = strcmp("z_SDSS", filtname);
539  if(check == 0 && check1 == 0) {
540  wave_central = 6517.25;
541  has_fringes = 0; has no fringing
542  break;
543  }
544  check = strcmp("PS6", filtid);
545  check1 = strcmp("B_JOHN", filtname);
546  if(check == 0 && check1 == 0) {
547  wave_central = 6517.25;
548  has_fringes = 0; has no fringing
549  break;
550  }
551  check = strcmp("PS7", filtid);
552  check1 = strcmp("V_JOHN", filtname);
553  if(check == 0 && check1 == 0) {
554  wave_central = 6517.25;
555  has_fringes = 0; has no fringing
556  break;
557  }
558  check = strcmp("PS8", filtid);
559  check1 = strcmp("V_STRM", filtname);
560  if(check == 0 && check1 == 0) {
561  wave_central = 6517.25;
562  has_fringes = 0; has no fringing
563  break;
564  }
565  check = strcmp("PS9", filtid);
566  check1 = strcmp("H_ALPHA", filtname);
567  if(check == 0 && check1 == 0) {
568  wave_central = 6517.25;
569  has_fringes = 0; has no fringing
570  break;
571  }
572  check = strcmp("PS10", filtid);
573  check1 = strcmp("H_ALPHA", filtname);
574  if(check == 0 && check1 == 0) {
575  wave_central = 6517.25;
576  has_fringes = 0; has no fringing
577  break;
578  }
579  check = strcmp("PS11", filtid);
580  check1 = strcmp("NB_852_861_869_878", filtname);
581  if(check == 0 && check1 == 0) {
582  wave_central = 6517.25;
583  has_fringes = 0; has no fringing
584  break;
585  }
586  check = strcmp("PS12", filtid);
587  check1 = strcmp("NB_453_494_535_575", filtname);
588  if(check == 0 && check1 == 0) {
589  wave_central = 6517.25;
590  has_fringes = 0; has no fringing
591  break;
592  }
593  check = strcmp("PS13", filtid);
594  check1 = strcmp("NB_615_710_755_815", filtname);
595  if(check == 0 && check1 == 0) {
596  wave_central = 6517.25;
597  has_fringes = 0; has no fringing
598  break;
599  }
600  check = strcmp("P53", filtid);
601  check1 = strcmp("SCAT_AUX_CCD", filtname);
602  if(check == 0 && check1 == 0) {
603  wave_central = 6517.25;
604  has_fringes = 0; has no fringing
605  break;
606  }
607  check = strcmp("P54", filtid);
608  check1 = strcmp("PINHOLE", filtname);
609  if(check == 0 && check1 == 0) {
610  wave_central = 6517.25;
611  has_fringes = 0; has no fringing
612  break;
613  }
614  check = strcmp("P56", filtid);
615  check1 = strcmp("frame", filtname);
616  if(check == 0 && check1 == 0) {
617  wave_central = 6517.25;
618  has_fringes = 0; has no fringing
619  break;
620  }
621  check = strcmp("PS59", filtid);
622  check1 = strcmp("test2", filtname);
623  if(check == 0 && check1 == 0) {
624  wave_central = 6517.25;
625  has_fringes = 0; has no fringing
626  break;
627  }
628  check = strcmp("PS60", filtid);
629  check1 = strcmp("test1", filtname);
630  if(check == 0 && check1 == 0) {
631  wave_central = 6517.25;
632  has_fringes = 0; has no fringing
633  break;
634  }
635  check = strcmp("calib", filtid);
636  check1 = strcmp("u_g_r_i_SDSS", filtname);
637  if(check == 0 && check1 == 0) {
638  wave_central = 6517.25;
639  has_fringes = 0; has no fringing
640  break;
641  }
642  check = strcmp("opaque", filtid);
643  check1 = strcmp("opaque", filtname);
644  if(check == 0 && check1 == 0) {
645  wave_central = 6517.25;
646  has_fringes = 0; has no fringing
647  break;
648  }
649  }
650 
651  cpl_propertylist_append_string(list,"FILT_NAME", filtname);
652  cpl_propertylist_append_double(list,"CWL", wave_central);
653  cpl_propertylist_append_int(list,"HAS_FRINGES", has_fringes);
654 
655  Get chip information and include in same plist
656 FIXME: 32 or 16 ccd? Depends on if 1 or 2 files in paranal workstation
657  for(i=1; i<= 32; i++) {
658 
659  if (cpl_propertylist_has(ext, "ESO DET CHIP ID") == 1) {
660  chipid = cpl_propertylist_get_string(ext, "ESO DET CHIP ID");
661  break;
662  }
663  else if (cpl_propertylist_has(ext, "CHIP_ID") == 1) {
664  chipid = cpl_propertylist_get_string(ext, "CHIP_ID");
665  break;
666  }
667  else {
668  char name[80] = "";
669  sprintf(name,"ESO DET CHIP%d ID", i);
670 
671  if (cpl_propertylist_has(ext, name) == 1) {
672  chipid = cpl_propertylist_get_string(ext, name);
673  break;
674  }
675  }
676  }
677 
678  cpl_propertylist_append_string(list,"CHIP_ID", chipid);
679 
680  It returns a plist with the following fields FILT_ID,FILT_NAME,CWL,HAS_FRINGES,CHIP_ID)
681  return list;
682 }
683 */
684 
685 /*----------------------------------------------------------------------------*/
695 /*----------------------------------------------------------------------------*/
696 
697 void omega_pfits_get_mean_airmass(const cpl_propertylist *plist, double *airm)
698 {
699 
700  double airm0 = 1.0;
701  double airm1 = 1.0;
702 
703 
704  if( (cpl_propertylist_has(plist, "ESO TEL AIRM START") == 1) &&
705  (cpl_propertylist_has(plist, "ESO TEL AIRM END") == 1 ) ) {
706  airm0 = cpl_propertylist_get_double(plist, "ESO TEL AIRM START");
707  airm1 = cpl_propertylist_get_double(plist, "ESO TEL AIRM END");
708 
709  *airm = (airm0 + airm1)/2;
710  }
711  else if ( (cpl_propertylist_has(plist, "AIRMSTRT") == 1) &&
712  (cpl_propertylist_has(plist, "AIRMEND")) == 1 ){
713  airm0 = cpl_propertylist_get_double(plist, "AIRMSTRT");
714  airm1 = cpl_propertylist_get_double(plist, "AIRMEND");
715 
716  *airm = (airm0 + airm1)/2;
717  }
718  else if (cpl_propertylist_has(plist, "AIRMASS") == 1){
719  *airm = cpl_propertylist_get_double(plist, "AIRMASS");
720  }
721  else {
722  *airm = 1.0;
723  }
724 
725  if (*airm == 0.0){
726  *airm = 1.0;
727  }
728 
729  return;
730 
731 }
732 
733 /*----------------------------------------------------------------------------*/
744 /*----------------------------------------------------------------------------*/
745 void omega_pfits_get_airmass(const cpl_propertylist *plist1, double *start, double *end)
746 {
747 
748 
749 /*This needs to be the main header of the image*/
750 
751  if (plist1 == NULL) {
752  cpl_msg_error(cpl_func,"Main header is empty");
753  }
754 
755  if( (cpl_propertylist_has(plist1, "ESO TEL AIRM START") == 1) &&
756  (cpl_propertylist_has(plist1, "ESO TEL AIRM END") == 1 ) ){
757  *start = cpl_propertylist_get_double(plist1, "ESO TEL AIRM START");
758  *end = cpl_propertylist_get_double(plist1, "ESO TEL AIRM END");
759  }
760  else if ( (cpl_propertylist_has(plist1, "AIRMSTRT") == 1) &&
761  (cpl_propertylist_has(plist1, "AIRMEND")) == 1 ){
762  *start = cpl_propertylist_get_double(plist1, "AIRMSTRT");
763  *end = cpl_propertylist_get_double(plist1, "AIRMEND");
764  }
765  else if (cpl_propertylist_has(plist1, "AIRMASS") == 1) {
766  *start = cpl_propertylist_get_double(plist1, "AIRMASS");
767  *end = *start;
768  }
769  else {
770  *start = 1.0;
771  *end = 1.0;
772  }
773 
774 
775 }
776 
777 /*
778  * Check from which instrument is the frame (WFI or OMEGA)
779  */
785 int omega_pfits_check_instrume(const cpl_frame *fr)
786 {
787 
788  const char *INSTRUMENT = NULL;
789  cpl_propertylist *plist;
790 
791 
792  if (fr == NULL) {
793  cpl_msg_error(cpl_func,"NULL frame");
794  return -1;
795  }
796 
797  plist = cpl_propertylist_load_regexp(cpl_frame_get_filename(fr), 0,
798  "INSTRUME", 0);
799  if (plist == NULL) {
800  cpl_msg_error (cpl_func,"Cannot load main header for %s",cpl_frame_get_filename(fr));
801  return -1;
802  }
803 
804  INSTRUMENT = cpl_propertylist_get_string(plist, "INSTRUME");
805  if(!INSTRUMENT) {
806  cpl_msg_error(cpl_func,"Cannot find INSTRUME keyword in header");
807  cpl_propertylist_delete(plist);
808  return -1;
809  }
810 
811  if(strcmp("OMEGA", INSTRUMENT)==0){
812  cpl_propertylist_delete(plist);
813  return 0;
814  }
815  else if(strcmp("WFI", INSTRUMENT)==0){
816  cpl_propertylist_delete(plist);
817  return 1;
818  }
819  else{
820  cpl_propertylist_delete(plist);
821  return -1;
822  }
823 
824  return 0;
825 }
826 
834 int omega_pfits_get_instrume(const cpl_propertylist *plist)
835 {
836 
837  const char *INSTRUMENT = NULL;
838 
839 
840  if (plist == NULL) {
841  cpl_msg_error(cpl_func,"NULL property list");
842  return -1;
843  }
844 
845 
846  INSTRUMENT = cpl_propertylist_get_string(plist, "INSTRUME");
847  if(!INSTRUMENT) {
848  cpl_msg_warning(cpl_func,"Cannot find INSTRUME keyword in header");
849  return 0;
850  }
851 
852  if(strcmp("OMEGA", INSTRUMENT)==0){
853  return 0;
854  }
855  else if(strcmp("WFI", INSTRUMENT)==0){
856  return 1;
857  }
858 
859  return 0;
860 }
861 
869 /*--------------------------------------------------------------------------*/
870 void omega_pfits_get_readnoise(cpl_propertylist *plist, double *rn)
871 {
872 
873  int i = 0;
874 
875  const char *ronstring = "ESO DET OUT1 RON";
876 
877 
878 /* Start function algorithm */
879 /* This must be the extension header of the image*/
880  if (plist == NULL) {
881  cpl_msg_error(cpl_func,"Extension header is empty");
882  }
883 
884  if (cpl_propertylist_has(plist, ronstring) == 1) {
885  *rn = cpl_propertylist_get_double(plist, ronstring);
886  }
887  else if (cpl_propertylist_has(plist, "RON") == 1) {
888  *rn = cpl_propertylist_get_double(plist, "RON");
889  }
890  else{
891 
892  for(i=1; i<= 32; i++) {
893  char name[80] = "";
894  sprintf(name,"ESO DET OUT%d RON", i);
895 
896  if (cpl_propertylist_has(plist, name) == 1) {
897  *rn = cpl_propertylist_get_double(plist, name);
898  break;
899  }
900  }
901  }
902 
903 }
904 
912 int omega_pfits_get_overscan(const cpl_frame *frame, int xn)
913 {
914  int value;
915  cpl_propertylist *plist;
916 
917  if(frame == NULL){
918  cpl_msg_warning(cpl_func,"Frame is NULL");
919  return -1;
920  }
921 
922  plist = cpl_propertylist_load_regexp(cpl_frame_get_filename(frame), xn,
923  "ESO DRS", 0);
924 
925  if(plist == NULL){
926  cpl_msg_warning(cpl_func,"Cannot load property list");
927  return -1;
928  }
929 
930  if( cpl_propertylist_has(plist, "ESO DRS OVERSCAN METHOD") == 1 ){
931  value = cpl_propertylist_get_int(plist, "ESO DRS OVERSCAN METHOD");
932  }
933  else {
934  cpl_msg_warning(cpl_func,"Cannot find overscan method in header");
935  value = -1;
936  }
937 
938  freeplist(plist);
939 
940  return value;
941 }
942 
943 
951 /*--------------------------------------------------------------------------*/
952 void omega_pfits_get_gain(cpl_propertylist *plist, double *gain)
953 {
954 
955  int i = 0;
956  char name[80] = "";
957 
958  *gain = 0.0;
959 
960  if(plist == NULL)
961  return;
962 
963 /* Start function algorithm */
964  if (plist == NULL) {
965  cpl_msg_warning(cpl_func,"Header is NULL");
966  }
967  else if (cpl_propertylist_has(plist, "ESO DET OUT GAIN") == 1) {
968  *gain = cpl_propertylist_get_double(plist, "ESO DET OUT GAIN");
969  }
970  else if (cpl_propertylist_has(plist, "GAIN") == 1) {
971  *gain = cpl_propertylist_get_double(plist, "GAIN");
972  }
973  else {
974 
975  for(i=1; i<= 32; i++){
976 /* char name[80] = ""; */
977  sprintf(name,"ESO DET OUT%d GAIN", i);
978 
979  if (cpl_propertylist_has(plist, name) == 1) {
980  *gain = cpl_propertylist_get_double(plist, name);
981  break;
982  }
983  }
984  }
985 
986  return;
987 }
988 
995 void omega_pfits_get_conad(cpl_propertylist *plist, double *conad)
996 {
997 
998  int i = 0;
999  char name[80] = "";
1000 
1001  *conad = 0.0;
1002 
1003  if(plist == NULL)
1004  return;
1005 
1006 /* Start function algorithm */
1007  if (plist == NULL) {
1008  cpl_msg_error(cpl_func,"Header is empty");
1009  }
1010  else if (cpl_propertylist_has(plist, "ESO DET OUT CONAD") == 1) {
1011  *conad = cpl_propertylist_get_double(plist, "ESO DET OUT CONAD");
1012  }
1013  else if (cpl_propertylist_has(plist, "CONAD") == 1) {
1014  *conad = cpl_propertylist_get_double(plist, "CONAD");
1015  }
1016  else {
1017 
1018  for(i=1; i<= 32; i++){
1019 /* char name[80] = ""; */
1020  sprintf(name,"ESO DET OUT%d CONAD", i);
1021 
1022  if (cpl_propertylist_has(plist, name) == 1) {
1023  *conad = cpl_propertylist_get_double(plist, name);
1024  break;
1025  }
1026  }
1027  }
1028 
1029  return;
1030 }
1031 
1038 /*--------------------------------------------------------------------------*/
1044 const char *omega_pfits_get_chipid(const cpl_propertylist *plist)
1045 {
1046  int i = 0;
1047  int nextensions = 32; /*FIXME: check if OMEGA has 1 or 2 controllers*/
1048  const char *chipid = NULL;
1049  char name[80] = "";
1050 
1051  if (plist == NULL) {
1052  cpl_msg_error(cpl_func,"NULL input property list");
1053  return NULL;
1054  }
1055 
1056  /*Check if instrument is WFI*/
1057 // if (omega_pfits_get_instrume(plist) == 1)
1058 // nextensoins = 8;
1059 
1060  for(i=1; i<= nextensions; i++) {
1061 
1062  if (cpl_propertylist_has(plist, "ESO DET CHIP ID") == 1) {
1063  chipid = cpl_propertylist_get_string(plist, "ESO DET CHIP ID");
1064  break;
1065  }
1066  else {
1067  sprintf(name,"ESO DET CHIP%d ID", i);
1068 
1069  if (cpl_propertylist_has(plist, name) == 1) {
1070  chipid = cpl_propertylist_get_string(plist, name);
1071  break;
1072  }
1073  }
1074  }
1075 
1076  return chipid;
1077 }
1078 
1085 /*--------------------------------------------------------------------------*/
1086 
1087 const char * omega_pfits_get_extname(const cpl_propertylist *plist)
1088 {
1089 
1090  if (cpl_propertylist_has(plist, "EXTNAME") == 0){
1091  return NULL;
1092  }
1093 
1094  return cpl_propertylist_get_string(plist, "EXTNAME");
1095 
1096 }
1097 
1107 /*--------------------------------------------------------------------------*/
1108 
1109 int omega_compare_extname(cpl_propertylist *plist1, cpl_propertylist *plist2)
1110 {
1111  const char *extn1 = NULL;
1112  const char *extn2 = NULL;
1113 
1114  if(plist1 == NULL || plist2 == NULL){
1115  cpl_msg_error(cpl_func,"NULL input property list(s)");
1116  return -1;
1117  }
1118 
1119  if((cpl_propertylist_has(plist1, "EXTNAME") == 1)
1120  && (cpl_propertylist_has(plist2, "EXTNAME") == 1)) {
1121 
1122  extn1 = cpl_propertylist_get_string(plist1, "EXTNAME");
1123  extn2 = cpl_propertylist_get_string(plist2, "EXTNAME");
1124  return strcmp(extn1, extn2);
1125  }
1126  else{
1127  return -1;
1128  }
1129 
1130 }
1131 
1132 /*----------------------------------------------------------------------------*/
1153 /*----------------------------------------------------------------------------*/
1154 cpl_propertylist * omega_pfits_get_filter_info(const cpl_propertylist *main)
1155 {
1156 
1157  int has_fringes = 0;
1158  int i = 0;
1159  int n = 4; /*change here for correct number of filters*/
1160  int check =0 ;
1161  int check1 = 0;
1162  int filtno = 0;
1163 
1164  double wave_central = 0.0f;
1165 
1166  const char *filtid = "none";
1167  const char *filtname = "none";
1168  const char *reffiltname = "none";
1169  const char *referr = "none";
1170  const char *extname = "none";
1171 
1172 
1173  cpl_propertylist *list;
1174 
1175  if (main == NULL) {
1176  cpl_msg_error(cpl_func,"Main header is empty");
1177  return NULL;
1178  }
1179 
1180  list = cpl_propertylist_new();
1181 
1182  if (cpl_propertylist_has(main,"ESO INS FILT ID") == 1) {
1183  filtid = cpl_propertylist_get_string(main, "ESO INS FILT ID");
1184  filtname = cpl_propertylist_get_string(main, "ESO INS FILT NAME");
1185  }
1186  else if (cpl_propertylist_has(main,"ESO INS FILT1 ID") == 1) {
1187  filtid = cpl_propertylist_get_string(main, "ESO INS FILT1 ID");
1188  filtname = cpl_propertylist_get_string(main, "ESO INS FILT1 NAME");
1189  }
1190  else if (cpl_propertylist_has(main,"FILT_ID") == 1) {
1191  filtid = cpl_propertylist_get_string(main, "FILT_ID");
1192  filtname = cpl_propertylist_get_string(main, "FILT_NAME");
1193  }
1194  else {
1195  filtid = "";
1196  filtname = "";
1197  cpl_msg_warning(cpl_func,"Cannot find filter information in header");
1198 /* return NULL;*/
1199  }
1200 
1201  if (cpl_propertylist_has(main,"EXTNAME") == 1) {
1202  extname= cpl_propertylist_get_string(main, "EXTNAME");
1203  }
1204  else {
1205  extname = "";
1206  cpl_msg_debug(cpl_func,"Cannot find extension name in header");
1207  }
1208 
1209  if (cpl_propertylist_has(main,"ESO INS FILT1 NO") == 1) {
1210  filtno= cpl_propertylist_get_int(main, "ESO INS FILT1 NO");
1211  }
1212  else {
1213  filtno=0;
1214  }
1215 
1216 
1217 
1218  cpl_propertylist_append_string(list,"FILT_ID", filtid);
1219 
1220 
1221 
1222  for(i=0; i<n; i++) {
1223 /*Filter names and IDs from Bernard Muschielok*/
1224 /*FIXME: correct values of wave_central for each filter and the has_fringes too.*/
1225 /* FIXME: check reffiltname for filters */
1226 
1227  /* From VST manual v 2.5 page 16 .*/
1228  check = strcmp("PS7", filtid);
1229  check1 = strcmp("u_SDSS", filtname);
1230  if(check == 0 || check1 == 0) {
1231  reffiltname = "SloanU";
1232  referr = "SloanU_err";
1233  wave_central = 3540.;
1234  has_fringes = 0; /*has no fringing*/
1235  break;
1236  }
1237  /* From VST manual v 2.5 page 16 .*/
1238  check = strcmp("PS2", filtid);
1239  check1 = strcmp("g_SDSS", filtname);
1240  if(check == 0 || check1 == 0) {
1241  reffiltname = "SloanG";
1242  referr = "SloanG_err";
1243  wave_central = 4750.;
1244  has_fringes = 0; /*has no fringing*/
1245  break;
1246  }
1247  /* From VST manual v 2.5 page 16 .*/
1248  check = strcmp("PS4", filtid);
1249  check1 = strcmp("r_SDSS", filtname);
1250  if(check == 0 || check1 == 0) {
1251  reffiltname = "SloanR";
1252  referr = "SloanR_err";
1253  wave_central = 6250.;
1254  has_fringes = 0; /*has no fringing*/
1255  break;
1256  }
1257  /* From VST manual v 2.5 page 16 .*/
1258  check = strcmp("PS3", filtid);
1259  check1 = strcmp("i_SDSS", filtname);
1260  if(check == 0 || check1 == 0) {
1261  reffiltname = "SloanI";
1262  referr = "SloanI_err";
1263  wave_central = 7560.;
1264  has_fringes = 1; /*has no fringing*/
1265  break;
1266  }
1267  /* From VST manual v 2.5 page 16 .*/
1268  check = strcmp("PS1", filtid);
1269  check1 = strcmp("z_SDSS", filtname);
1270  if(check == 0 || check1 == 0) {
1271  reffiltname = "SloanZ";
1272  referr = "SloanZ_err";
1273  wave_central = 8800.;
1274  has_fringes = 1; /*has no fringing*/
1275  break;
1276  }
1277  /* From VST manual v 2.5 page 16 .*/
1278  check = strcmp("PS9", filtid);
1279  check1 = strcmp("B_JOHN", filtname);
1280  if(check == 0 || check1 == 0) {
1281  reffiltname = "JohnsonB";
1282  referr = "JohnsonB_err";
1283  wave_central = 4390;
1284  has_fringes = 0; /*has no fringing*/
1285  break;
1286  }
1287  /* From VST manual v 2.5 page 16 .*/
1288  check = strcmp("PS10", filtid);
1289  check1 = strcmp("V_JOHN", filtname);
1290  if(check == 0 || check1 == 0) {
1291  reffiltname = "JohnsonV";
1292  referr = "JohnsonV_err";
1293  wave_central = 5510;
1294  has_fringes = 0; /*has no fringing*/
1295  break;
1296  }
1297  /* From VST manual v 2.5 page 16 .*/
1298  check = strcmp("PS5", filtid);
1299  check1 = strcmp("v_STRM", filtname);
1300  if(check == 0 || check1 == 0) {
1301  wave_central = 4120.;
1302  has_fringes = 0; /*has no fringing*/
1303  break;
1304  }
1305 
1306 /*
1307  From VST manual v 2.5 page 16 .
1308  check = strcmp("PS11", filtid);
1309  check1 = strcmp("H_ALPHA", filtname);
1310  if(check == 0 || check1 == 0) {
1311  wave_central = 0.;
1312  has_fringes = 0; has no fringing
1313  break;
1314  }
1315 */
1316 
1317 
1318  /* From VST manual v 2.5 page 16 .*/
1319  check = strcmp("PS6", filtid);
1320  check1 = strcmp("NB_852_861_869_878", filtname);
1321  if(check == 0 || check1 == 0) {
1322  wave_central = 0.;
1323  has_fringes = 0; /*has no fringing*/
1324  break;
1325  }
1326  /* From VST manual v 2.5 page 16 .*/
1327  check = strcmp("PS14", filtid);
1328  check1 = strcmp("NB_454_494_533_575", filtname);
1329  if(check == 0 || check1 == 0) {
1330  wave_central = 0.;
1331  has_fringes = 0; /*has no fringing*/
1332  break;
1333  }
1334  /* From VST manual v 2.5 page 16 .*/
1335  check = strcmp("PS22", filtid);
1336  check1 = strcmp("NB_617_710_755_817", filtname);
1337  if(check == 0 || check1 == 0) {
1338  wave_central = 0.;
1339  has_fringes = 0; /*has no fringing*/
1340  break;
1341  }
1342  /* From VST manual v 2.5 page 16 .*/
1343  check = strcmp("PS59", filtid);
1344  check1 = strcmp("Dummy_2", filtname);
1345  if(check == 0 || check1 == 0) {
1346  wave_central = 0.;
1347  has_fringes = 0; /*has no fringing*/
1348  break;
1349  }
1350  /* From VST manual v 2.5 page 16 .*/
1351  check = strcmp("PS60", filtid);
1352  check1 = strcmp("Dummy_1", filtname);
1353  if(check == 0 || check1 == 0) {
1354  wave_central = 0.;
1355  has_fringes = 0; /*has no fringing*/
1356  break;
1357  }
1358  /* From VST manual v 2.5 page 16 .*/
1359  check = strcmp("opaque", filtid);
1360  check1 = strcmp("opaque", filtname);
1361  if(check == 0 || check1 == 0) {
1362  wave_central = 0.;
1363  has_fringes = 0; /*has no fringing*/
1364  break;
1365  }
1366 
1367  /* From VST manual v 2.5 page 16 .*/
1368  check = strcmp("calib", filtid);
1369  check1 = strcmp("u_g_r_i_SDSS", filtname);
1370  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 1) {
1371  reffiltname = "SloanU";
1372  referr = "SloanU_err";
1373  wave_central = 3540.;
1374  has_fringes = 0; /*has no fringing*/
1375  break;
1376  }
1377 
1378  /* From VST manual v 2.5 page 16 .*/
1379  check = strcmp("calib", filtid);
1380  check1 = strcmp("u_g_r_i_SDSS", filtname);
1381  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 4) {
1382  reffiltname = "SloanG";
1383  referr = "SloanG_err";
1384  wave_central = 4750.;
1385  has_fringes = 0; /*has no fringing*/
1386  break;
1387  }
1388 
1389  /* From VST manual v 2.5 page 16 .*/
1390  check = strcmp("calib", filtid);
1391  check1 = strcmp("u_g_r_i_SDSS", filtname);
1392  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 3) {
1393  reffiltname = "SloanR";
1394  referr = "SloanR_err";
1395  wave_central = 6250.;
1396  has_fringes = 0; /*has no fringing*/
1397  break;
1398  }
1399  /* From VST manual v 2.5 page 16 .*/
1400  check = strcmp("calib", filtid);
1401  check1 = strcmp("u_g_r_i_SDSS", filtname);
1402  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 2) {
1403  reffiltname = "SloanI";
1404  referr = "SloanI_err";
1405  wave_central = 7560.;
1406  has_fringes = 0; /*has no fringing*/
1407  break;
1408  }
1409 
1410 
1411 
1412  /* From VST manual v 2.5 page 16 .*/
1413  check = strcmp("PS11", filtid);
1414  check1 = strcmp("H_ALPHA", filtname);
1415  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 1) {
1416  reffiltname = "H_ALPHA";
1417  referr = "H_ALPHA_err";
1418  wave_central = 6791.;
1419  has_fringes = 0; /*has no fringing*/
1420  break;
1421  }
1422 
1423  /* From VST manual v 2.5 page 16 .*/
1424  check = strcmp("PS11", filtid);
1425  check1 = strcmp("H_ALPHA", filtname);
1426  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 4) {
1427  reffiltname = "H_ALPHA";
1428  referr = "H_ALPHA_err";
1429  wave_central = 6590.;
1430  has_fringes = 0; /*has no fringing*/
1431  break;
1432  }
1433 
1434  /* From VST manual v 2.5 page 16 .*/
1435  check = strcmp("PS11", filtid);
1436  check1 = strcmp("H_ALPHA", filtname);
1437  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 3) {
1438  reffiltname = "H_ALPHA";
1439  referr = "H_ALPHA_err";
1440  wave_central = 6660.;
1441  has_fringes = 0; /*has no fringing*/
1442  break;
1443  }
1444  /* From VST manual v 2.5 page 16 .*/
1445  check = strcmp("PS11", filtid);
1446  check1 = strcmp("H_ALPHA", filtname);
1447  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 2) {
1448  reffiltname = "H_ALPHA";
1449  referr = "H_ALPHA_err";
1450  wave_central = 6726.;
1451  has_fringes = 0; /*has no fringing*/
1452  break;
1453  }
1454 
1455 
1456  /* From VST manual v 2.5 page 16 .*/
1457  check = strcmp("PS30", filtid);
1458  check1 = strcmp("NB_659", filtname);
1459  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 1) {
1460  reffiltname = "NB_659";
1461  referr = "NB_659_err";
1462  wave_central = 6586.;
1463  has_fringes = 0; /*has no fringing*/
1464  break;
1465  }
1466 
1467  /* From VST manual v 2.5 page 16 .*/
1468  check = strcmp("PS30", filtid);
1469  check1 = strcmp("NB_659", filtname);
1470  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 4) {
1471  reffiltname = "NB_659";
1472  referr = "NB_659_err";
1473  wave_central = 6593.;
1474  has_fringes = 0; /*has no fringing*/
1475  break;
1476  }
1477 
1478  /* From VST manual v 2.5 page 16 .*/
1479  check = strcmp("PS30", filtid);
1480  check1 = strcmp("NB_659", filtname);
1481  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 3) {
1482  reffiltname = "NB_659";
1483  referr = "NB_659_err";
1484  wave_central = 6586.;
1485  has_fringes = 0; /*has no fringing*/
1486  break;
1487  }
1488  /* From VST manual v 2.5 page 16 .*/
1489  check = strcmp("PS30", filtid);
1490  check1 = strcmp("NB_659", filtname);
1491  if((check == 0 || check1 == 0) && omega_get_quadrant(extname, filtno) == 2) {
1492  reffiltname = "NB_659";
1493  referr = "NB_659_err";
1494  wave_central = 6586.;
1495  has_fringes = 0; /*has no fringing*/
1496  break;
1497  }
1498 
1499  }
1500 
1501  cpl_propertylist_append_string(list,"FILT_NAME", filtname);
1502  cpl_propertylist_append_string(list,"REF_MAG_ID", reffiltname);
1503  cpl_propertylist_append_string(list,"REF_MAG_ID_ERR", referr);
1504  cpl_propertylist_append_double(list,"CWL", wave_central);
1505  cpl_propertylist_append_int(list,"HAS_FRINGES", has_fringes);
1506 
1507 
1508 /* It returns a plist with the following fields FILT_ID,FILT_NAME,REF_FILT_NAME,CWL,HAS_FRINGES)*/
1509  return list;
1510 }
1511 
1512 
1521 /*--------------------------------------------------------------------------*/
1522 int omega_pfits_update_header(cpl_propertylist *to, const cpl_propertylist *from)
1523 {
1524 
1525  int i = 0;
1526  int n = 0;
1527 
1528  if(from == NULL)
1529  return -1;
1530 
1531  if(to == NULL) {
1532  to = cpl_propertylist_new();
1533  cpl_propertylist_append(to, from);
1534  return 0;
1535  }
1536 
1537  n = cpl_propertylist_get_size(from);
1538  for (i=0; i < n; i++){
1539  const cpl_property *pro = cpl_propertylist_get_const(from, i);
1540  const char *name = cpl_property_get_name(pro);
1541  if(cpl_propertylist_has(to, name) == 1)
1542  cpl_propertylist_erase(to, name);
1543 
1544  cpl_propertylist_copy_property(to, from, name);
1545  }
1546 
1547 // cpl_propertylist_append(*to, from);
1548 
1549  return 0;
1550 }
1551 
1552 
1563 /*--------------------------------------------------------------------------*/
1564 cpl_vector * omega_pfits_get_preovscan(const cpl_propertylist *plist)
1565 {
1566  int i = 0;
1567  int index = 0;
1568  int next = 32; /*FIXME: check if this is necessary for OMEGA */
1569  int prscx = 48;
1570  int prscy = 0;
1571  int ovscx = 48;
1572  int ovscy = 100;
1573  char name[80] = "";
1574  const char *readkeys = "|ESO DET OUT[0-9]|ESO DET OUT|";
1575  cpl_vector *sregion;
1576 
1577  if(plist == NULL)
1578  return NULL;
1579 
1580  /*
1581  * Pre and over scan keywords are written in
1582  * HIERARCH ESO DET OUT# * keywords. The # value is
1583  * the Output index given in keywords
1584  * HIERARCH ESO DET OUT# INDEX. Get the index first
1585  * then, use it to get pre and over scan keywords
1586  */
1587 
1588  /* Get HIERARCH ESO DET OUT# INDEX */
1589  for(i=1; i<= next; i++) {
1590  sprintf(name,"ESO DET OUT%d INDEX", i);
1591  if(cpl_propertylist_has(plist, name) == 1) {
1592  index = cpl_propertylist_get_int (plist, name);
1593  break;
1594  }
1595  }
1596 
1597  if(index == 0){
1598  cpl_msg_warning(cpl_func,"Cannot find HIERARCH ESO DET OUT# INDEX");
1599  /* try anyway */
1600  index = 1;
1601  }
1602 
1603  /*Get pre and overscan regions from header*/
1604  sprintf(name, "ESO DET OUT%d PRSCX", index);
1605  if(cpl_propertylist_has(plist, name) == 1){
1606  prscx = cpl_propertylist_get_int (plist, name);
1607  sprintf(name,"ESO DET OUT%d PRSCY", index);
1608  prscy = cpl_propertylist_get_int (plist, name);
1609  sprintf(name,"ESO DET OUT%d OVSCX", index);
1610  ovscx = cpl_propertylist_get_int (plist, name);
1611  sprintf(name,"ESO DET OUT%d OVSCY", index);
1612  ovscy = cpl_propertylist_get_int (plist, name);
1613  }
1614  else {
1615  return NULL;
1616  }
1617 
1618  sregion = cpl_vector_new(4);
1619  cpl_vector_set(sregion, 0, prscx);
1620  cpl_vector_set(sregion, 1, prscy);
1621  cpl_vector_set(sregion, 2, ovscx);
1622  cpl_vector_set(sregion, 3, ovscy);
1623 
1624 
1625  return sregion;
1626 
1627 }
1628 
1637 double omega_pfits_get_jitter_offset(cpl_propertylist *plist)
1638 {
1639 
1640  double offset = 0.0;
1641 
1642  if(cpl_propertylist_has(plist,"ESO TEL TARG OFFSETSIZE") == 0)
1643  return 0;
1644 
1645  offset = cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETSIZE");
1646 
1647  return offset;
1648 }
1649 
1658 double omega_pfits_get_dither_offsetx(cpl_propertylist *plist)
1659 {
1660 
1661  double offset = 0.0;
1662 
1663  if(cpl_propertylist_has(plist,"ESO TEL TARG OFFSETSIZEX") == 0)
1664  return 0;
1665 
1666  offset = cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETSIZEX");
1667 
1668  return offset;
1669 }
1670 
1679 double omega_pfits_get_dither_offsety(cpl_propertylist *plist)
1680 {
1681 
1682  double offset = 0.0;
1683 
1684  if(cpl_propertylist_has(plist,"ESO TEL TARG OFFSETSIZEY") == 0)
1685  return 0;
1686 
1687  offset = cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETSIZEY");
1688 
1689  return offset;
1690 }
1691 
1700 double omega_pfits_get_offset_alpha(cpl_propertylist *plist)
1701 {
1702 
1703  double offset = 0.0;
1704 
1705  if(cpl_propertylist_has(plist,"ESO TEL TARG OFFSETALPHA") == 0)
1706  return 0;
1707 
1708  offset = cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETALPHA");
1709 
1710  return offset;
1711 }
1712 
1721 double omega_pfits_get_offset_delta(cpl_propertylist *plist)
1722 {
1723 
1724  double offset = 0.0;
1725 
1726  if(cpl_propertylist_has(plist,"ESO TEL TARG OFFSETDELTA") == 0)
1727  return 0;
1728 
1729  offset = cpl_propertylist_get_double(plist,"ESO TEL TARG OFFSETDELTA");
1730 
1731  return offset;
1732 }
1733 
1734 /*---------------------------------------------------------------------------*/
1741 /*---------------------------------------------------------------------------*/
1742 
1743 double omega_pfits_get_cd11(const cpl_propertylist *plist)
1744 {
1745 
1746  if(cpl_propertylist_has(plist, "CD1_1") == 0)
1747  return 0;
1748 
1749  return(cpl_propertylist_get_double(plist,"CD1_1"));
1750 }
1751 
1752 /*---------------------------------------------------------------------------*/
1759 /*---------------------------------------------------------------------------*/
1760 
1761 double omega_pfits_get_cd12(const cpl_propertylist *plist)
1762 {
1763 
1764  if(cpl_propertylist_has(plist, "CD1_2") == 0)
1765  return 0;
1766 
1767  return(cpl_propertylist_get_double(plist,"CD1_2"));
1768 
1769 }
1770 
1771 /*---------------------------------------------------------------------------*/
1778 /*---------------------------------------------------------------------------*/
1779 
1780 double omega_pfits_get_cd21(const cpl_propertylist *plist)
1781 {
1782 
1783  if(cpl_propertylist_has(plist, "CD2_1") == 0)
1784  return 0;
1785 
1786  return(cpl_propertylist_get_double(plist,"CD2_1"));
1787 
1788 }
1789 
1790 /*---------------------------------------------------------------------------*/
1797 /*---------------------------------------------------------------------------*/
1798 
1799 double omega_pfits_get_cd22(const cpl_propertylist *plist)
1800 {
1801 
1802  if(cpl_propertylist_has(plist, "CD2_2") == 0)
1803  return 0;
1804 
1805  return(cpl_propertylist_get_double(plist,"CD2_2"));
1806 
1807 }
1808 
1809 /*---------------------------------------------------------------------------*/
1816 /*---------------------------------------------------------------------------*/
1817 
1818 double omega_pfits_get_cdelt2(const cpl_propertylist *plist)
1819 {
1820 
1821  if(cpl_propertylist_has(plist, "CDELT2") == 0)
1822  return 0;
1823 
1824  return(cpl_propertylist_get_double(plist,"CDELT2"));
1825 
1826 }
1827 
1838 void omega_pfits_get_chip_size(const cpl_propertylist *plist,int *xs, int *ys)
1839 {
1840  int prscx = 48;
1841  int prscy = 0;
1842  int ovscx = 48;
1843  int ovscy = 100;
1844  int naxis1 = 2144;
1845  int naxis2 = 4200;
1846  int x0 = 1;
1847  int x1 = 1;
1848  int y0 = 1;
1849  int y1 = 1;
1850  cpl_vector *vec;
1851 
1852  if(plist == NULL){
1853  /* Return default values of X,Y sizes */
1854  cpl_msg_info(cpl_func,"Using default chip sizes");
1855  x0 = prscx + 1;
1856  y0 = prscy + 1;
1857  x1 = naxis1 - ovscx;
1858  y1 = naxis2 - ovscy;
1859 
1860  *xs = x1 - x0+1;
1861  *ys = y1 - y0+1;
1862  return;
1863  }
1864 
1865  /* NAXIS */
1866  naxis1 = cpl_propertylist_get_int(plist, "NAXIS1");
1867  naxis2 = cpl_propertylist_get_int(plist, "NAXIS2");
1868 
1869  /* PRSCX, PRSCY, OVSCX, OVSCY */
1870  vec = omega_pfits_get_preovscan(plist);
1871  prscx = cpl_vector_get(vec,0);
1872  prscy = cpl_vector_get(vec,1);
1873  ovscx = cpl_vector_get(vec,2);
1874  ovscy = cpl_vector_get(vec,3);
1875 
1876  x0 = prscx + 1;
1877  y0 = prscy + 1;
1878  x1 = naxis1 - ovscx;
1879  y1 = naxis2 - ovscy;
1880 
1881  *xs = x1 - x0+1;
1882  *ys = y1 - y0+1;
1883 
1884  freevector(vec);
1885 
1886  return;
1887 }
1888 
1898 static int omega_get_quadrant(const char * extname, int filtno)
1899 {
1900 
1901  /*
1902  Quadrant layout following Cartesian coordinate system
1903  2 | 1
1904  ---------
1905  3 | 4
1906  */
1907  /*
1908 
1909  if filtno 1-6 | filter is in Magazin A
1910  if filtno 7-12| filter is in Magazin B
1911  magazine B is rotated by 180 degree compared to magazine A
1912  */
1913  if (extname == NULL){
1914  return 0;
1915  }
1916  else if((strcmp("ESO_CCD_#96", extname)== 0) ||
1917  (strcmp("ESO_CCD_#95", extname)== 0) ||
1918  (strcmp("ESO_CCD_#94", extname)== 0) ||
1919  (strcmp("ESO_CCD_#93", extname)== 0) ||
1920  (strcmp("ESO_CCD_#88", extname)== 0) ||
1921  (strcmp("ESO_CCD_#87", extname)== 0) ||
1922  (strcmp("ESO_CCD_#86", extname)== 0) ||
1923  (strcmp("ESO_CCD_#85", extname)== 0)) {
1924  if(filtno>=1 && filtno<=6){
1925  return 1;
1926  }
1927  else if (filtno>=7 && filtno<=12){
1928  return 3;
1929  }
1930  }
1931  else if((strcmp("ESO_CCD_#92", extname)== 0) ||
1932  (strcmp("ESO_CCD_#91", extname)== 0) ||
1933  (strcmp("ESO_CCD_#90", extname)== 0) ||
1934  (strcmp("ESO_CCD_#89", extname)== 0) ||
1935  (strcmp("ESO_CCD_#84", extname)== 0) ||
1936  (strcmp("ESO_CCD_#83", extname)== 0) ||
1937  (strcmp("ESO_CCD_#82", extname)== 0) ||
1938  (strcmp("ESO_CCD_#81", extname)== 0)) {
1939  if(filtno>=1 && filtno<=6){
1940  return 2;
1941  }
1942  else if (filtno>=7 && filtno<=12){
1943  return 4;
1944  }
1945  }
1946  else if((strcmp("ESO_CCD_#76", extname)== 0) ||
1947  (strcmp("ESO_CCD_#75", extname)== 0) ||
1948  (strcmp("ESO_CCD_#74", extname)== 0) ||
1949  (strcmp("ESO_CCD_#73", extname)== 0) ||
1950  (strcmp("ESO_CCD_#68", extname)== 0) ||
1951  (strcmp("ESO_CCD_#67", extname)== 0) ||
1952  (strcmp("ESO_CCD_#66", extname)== 0) ||
1953  (strcmp("ESO_CCD_#65", extname)== 0)) {
1954  if(filtno>=1 && filtno<=6){
1955  return 3;
1956  }
1957  else if (filtno>=7 && filtno<=12){
1958  return 1;
1959  }
1960  }
1961  else if((strcmp("ESO_CCD_#80", extname)== 0) ||
1962  (strcmp("ESO_CCD_#79", extname)== 0) ||
1963  (strcmp("ESO_CCD_#78", extname)== 0) ||
1964  (strcmp("ESO_CCD_#77", extname)== 0) ||
1965  (strcmp("ESO_CCD_#72", extname)== 0) ||
1966  (strcmp("ESO_CCD_#71", extname)== 0) ||
1967  (strcmp("ESO_CCD_#70", extname)== 0) ||
1968  (strcmp("ESO_CCD_#69", extname)== 0)){
1969  if(filtno>=1 && filtno<=6){
1970  return 4;
1971  }
1972  else if (filtno>=7 && filtno<=12){
1973  return 2;
1974  }
1975  }
1976 
1977  else {
1978  return 0;
1979  }
1980 
1981 
1982 }
1983