HAWKI Pipeline Reference Manual  1.8.12
hawki_load.c
1 /* $Id: hawki_load.c,v 1.40 2009/12/04 10:39:14 cgarcia Exp $
2  *
3  * This file is part of the HAWKI 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: cgarcia $
23  * $Date: 2009/12/04 10:39:14 $
24  * $Revision: 1.40 $
25  * $Name: hawki-1_8_12 $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 /*-----------------------------------------------------------------------------
33  Includes
34  -----------------------------------------------------------------------------*/
35 
36 #include <string.h>
37 #include <cpl.h>
38 
39 #include "hawki_load.h"
40 #include "hawki_pfits.h"
41 #include "hawki_utils.h"
42 #include "hawki_dfs.h"
43 
44 /*----------------------------------------------------------------------------*/
49 /*----------------------------------------------------------------------------*/
50 
53 /*----------------------------------------------------------------------------*/
62 /*----------------------------------------------------------------------------*/
63 cpl_frameset * hawki_extract_frameset(
64  const cpl_frameset * in,
65  const char * tag)
66 {
67  cpl_frameset * out ;
68  const cpl_frame * cur_frame ;
69  cpl_frame * loc_frame ;
70  int nbframes, nbext ;
71  int i ;
72 
73  /* Test entries */
74  if (in == NULL) return NULL ;
75  if (tag == NULL) return NULL ;
76 
77  /* Initialise */
78  nbframes = cpl_frameset_get_size(in) ;
79 
80  /* Count the frames with the tag */
81  if ((nbext = cpl_frameset_count_tags(in, tag)) == 0) return NULL ;
82 
83  /* Create the output frameset */
84  out = cpl_frameset_new() ;
85 
86  /* Loop on the requested frames and store them in out */
87  nbext = 0 ;
88  for (i=0 ; i<nbframes ; i++) {
89  cur_frame = cpl_frameset_get_frame_const(in, i) ;
90  if (!strcmp(cpl_frame_get_tag(cur_frame), tag)) {
91  loc_frame = cpl_frame_duplicate(cur_frame) ;
92  cpl_frameset_insert(out, loc_frame) ;
93  nbext ++ ;
94  }
95  }
96  return out ;
97 }
98 
99 /*----------------------------------------------------------------------------*/
109 /*----------------------------------------------------------------------------*/
111  const cpl_frameset * fset,
112  int fnum,
113  int chip,
114  int quad,
115  cpl_type ptype)
116 {
117  const cpl_frame * frame ;
118  const char * fname ;
119  cpl_image * ima ;
120 
121  /* Test entries */
122  if (fset == NULL) return NULL ;
123  if (chip < 1 || chip > HAWKI_NB_DETECTORS) return NULL ;
124  if (quad < 1 || quad > 4) return NULL ;
125 
126  /* Load the fnum frame */
127  frame = cpl_frameset_get_frame_const(fset, fnum) ;
128  fname = cpl_frame_get_filename(frame) ;
129 
130  /* Load */
131  if ((ima=hawki_load_quadrant_from_file(fname, chip, quad, ptype)) == NULL) {
132  cpl_msg_error(__func__, "Cannot load %dth frame (chip %d quarter %d)",
133  fnum+1, chip, quad) ;
134  return NULL ;
135  }
136  return ima ;
137 }
138 
139 /*----------------------------------------------------------------------------*/
148 /*----------------------------------------------------------------------------*/
150  const char * fname,
151  int chip,
152  int quad,
153  cpl_type ptype)
154 {
155  cpl_image * ima ;
156  int ext_nb ;
157  int llx, lly, urx, ury ;
158 
159  /* Test entries */
160  if (fname == NULL) return NULL ;
161  if (chip < 1 || chip > HAWKI_NB_DETECTORS) return NULL ;
162  if (quad < 1 || quad > 4) return NULL ;
163 
164  /* Define the window */
165  if (quad == 1) {
166  llx = lly = 1 ;
167  urx = ury = 1024 ;
168  } else if (quad == 2) {
169  llx = 1025 ;
170  lly = 1 ;
171  urx = 2048 ;
172  ury = 1024 ;
173  } else if (quad == 3) {
174  llx = 1 ;
175  lly = 1025 ;
176  urx = 1024 ;
177  ury = 2048 ;
178  } else if (quad == 4) {
179  llx = lly = 1025 ;
180  urx = ury = 2048 ;
181  } else return NULL ;
182 
183  /* Get the extension with the wished chip */
184  if ((ext_nb = hawki_get_ext_from_detector(fname, chip)) == -1) {
185  cpl_msg_error(__func__, "Cannot get the extension with chip %d",
186  chip+1) ;
187  return NULL ;
188  }
189 
190  /* Load */
191  if ((ima=cpl_image_load_window(fname, ptype, 0, ext_nb, llx, lly, urx,
192  ury)) == NULL) {
193  cpl_msg_error(__func__, "Cannot load chip %d quarter %d from %s",
194  chip, quad, fname) ;
195  return NULL ;
196  }
197  return ima ;
198 }
199 
200 /*----------------------------------------------------------------------------*/
208 /*----------------------------------------------------------------------------*/
209 cpl_imagelist * hawki_load_detector(
210  const cpl_frameset * fset,
211  int chip,
212  cpl_type ptype)
213 {
214  int nframes ;
215  cpl_imagelist * out ;
216  const cpl_frame * frame ;
217  const char * fname ;
218  cpl_image * ima ;
219  int ext_nb ;
220  int i ;
221 
222  /* Test entries */
223  if (fset == NULL) return NULL ;
224  if (chip < 1 || chip > HAWKI_NB_DETECTORS) return NULL ;
225  nframes = cpl_frameset_get_size(fset) ;
226 
227  /* Create the output list */
228  out = cpl_imagelist_new() ;
229 
230  /* Loop on the frames */
231  for (i=0 ; i<nframes ; i++) {
232 
233  /* Load the ith frame */
234  frame = cpl_frameset_get_frame_const(fset, i) ;
235  fname = cpl_frame_get_filename(frame) ;
236 
237  /* Get the extension with the wished chip */
238  if ((ext_nb = hawki_get_ext_from_detector(fname, chip)) == -1) {
239  cpl_msg_error(__func__, "Cannot get the extension with chip %d",
240  chip) ;
241  cpl_imagelist_delete(out);
242  return NULL ;
243  }
244  /* Load */
245  if ((ima=cpl_image_load(fname, ptype, 0, ext_nb)) == NULL) {
246  cpl_msg_error(__func__, "Cannot load %dth frame (chip %d)",
247  i+1, chip) ;
248  cpl_imagelist_delete(out) ;
249  return NULL ;
250  }
251  cpl_imagelist_set(out, ima, i) ;
252  }
253  return out ;
254 }
255 
256 /*----------------------------------------------------------------------------*/
264 /*----------------------------------------------------------------------------*/
265 cpl_imagelist * hawki_load_extensions
266 (const cpl_frameset * fset,
267  int extension,
268  cpl_type ptype)
269 {
270  int nframes ;
271  cpl_imagelist * out ;
272  const cpl_frame * frame ;
273  const char * fname ;
274  cpl_image * ima ;
275  int iframe;
276 
277  /* Test entries */
278  if (fset == NULL) return NULL ;
279  nframes = cpl_frameset_get_size(fset) ;
280 
281  /* Create the output list */
282  out = cpl_imagelist_new() ;
283 
284  /* Loop on the frames */
285  for (iframe=0 ; iframe<nframes ; iframe++) {
286 
287  /* Load the ith frame */
288  frame = cpl_frameset_get_frame_const(fset, iframe) ;
289  fname = cpl_frame_get_filename(frame) ;
290 
291  /* Load */
292  if ((ima=cpl_image_load(fname, ptype, 0, extension)) == NULL) {
293  cpl_msg_error(__func__, "Cannot load %dth frame (extension %d)",
294  iframe+1, extension) ;
295  cpl_imagelist_delete(out) ;
296  return NULL ;
297  }
298  cpl_imagelist_set(out, ima, iframe) ;
299  }
300  return out ;
301 }
302 
303 /*----------------------------------------------------------------------------*/
312 /*----------------------------------------------------------------------------*/
313 cpl_image * hawki_load_image(
314  const cpl_frameset * fset,
315  int fnum,
316  int chip,
317  cpl_type ptype)
318 {
319  const cpl_frame * frame ;
320  const char * fname ;
321  cpl_image * ima ;
322  int ext_nb ;
323 
324  /* Test entries */
325  if (fset == NULL) return NULL ;
326  if (chip < 1 || chip > HAWKI_NB_DETECTORS) return NULL ;
327 
328  /* Load the fnum frame */
329  frame = cpl_frameset_get_frame_const(fset, fnum) ;
330  fname = cpl_frame_get_filename(frame) ;
331 
332  /* Check that the frame has the right number of extension */
333  if(cpl_frame_get_nextensions(frame) != HAWKI_NB_DETECTORS)
334  {
335  cpl_msg_error(__func__, "File %s contains less than %d extensions",
336  fname, HAWKI_NB_DETECTORS);
337  return NULL ;
338  }
339 
340  /* Get the extension with the wished chip */
341  if ((ext_nb = hawki_get_ext_from_detector(fname, chip)) == -1) {
342  cpl_msg_error(__func__, "Cannot get the extension with chip %d",
343  chip+1) ;
344  return NULL ;
345  }
346  /* Load */
347  if ((ima=cpl_image_load(fname, ptype, 0, ext_nb)) == NULL) {
348  cpl_msg_error(__func__, "Cannot load %dth frame (chip %d)",
349  fnum+1, chip) ;
350  return NULL ;
351  }
352  return ima ;
353 }
354 
355 /*----------------------------------------------------------------------------*/
364 /*----------------------------------------------------------------------------*/
365 cpl_imagelist * hawki_load_quadrants(
366  const cpl_frameset * fset,
367  int chip,
368  int quad,
369  cpl_type ptype)
370 {
371  cpl_imagelist * out ;
372  cpl_image * ima ;
373  int i ;
374 
375  /* Test entries */
376  if (fset == NULL) return NULL ;
377  if (chip < 1 || chip > HAWKI_NB_DETECTORS) return NULL ;
378  if (quad < 1 || quad > 4) return NULL ;
379 
380  /* Create the output imagelist */
381  out = cpl_imagelist_new() ;
382 
383  /* Loop on the frames */
384  for (i=0 ; i<cpl_frameset_get_size(fset) ; i++) {
385  ima = hawki_load_quadrant(fset, i, chip, quad, ptype) ;
386  if (ima == NULL) {
387  cpl_msg_error(__func__, "Cannot load %dth frame (chip %d, quad %d)",
388  i+1, chip, quad) ;
389  cpl_imagelist_delete(out) ;
390  return NULL ;
391  }
392  cpl_imagelist_set(out, ima, i) ;
393  }
394  return out ;
395 }
396 
397 /*----------------------------------------------------------------------------*/
406 /*----------------------------------------------------------------------------*/
407 cpl_imagelist * hawki_load_frameset(
408  const cpl_frameset * fset,
409  int chip,
410  cpl_type ptype)
411 {
412  cpl_imagelist * out ;
413  cpl_image * ima ;
414  int i ;
415 
416  /* Test entries */
417  if (fset == NULL) return NULL ;
418  if (chip < 1 || chip > HAWKI_NB_DETECTORS) return NULL ;
419 
420  /* Create the output imagelist */
421  out = cpl_imagelist_new() ;
422 
423  /* Loop on the frames */
424  for (i=0 ; i<cpl_frameset_get_size(fset) ; i++) {
425  ima = hawki_load_image(fset, i, chip, ptype) ;
426  if (ima == NULL) {
427  cpl_msg_error(__func__, "Cannot load %dth frame (chip %d)",
428  i+1, chip) ;
429  cpl_imagelist_delete(out) ;
430  return NULL ;
431  }
432  cpl_imagelist_set(out, ima, i) ;
433  }
434  return out ;
435 }
436 
444 /*----------------------------------------------------------------------------*/
445 cpl_imagelist * hawki_load_frame(
446  const cpl_frame * frame,
447  cpl_type ptype)
448 {
449  cpl_imagelist * out;
450  cpl_image * ima;
451  const char * fname;
452  int idet;
453  int ext_nb;
454  int * ext_chip_mapping;
455 
456  /* Test entries */
457  if (frame == NULL) return NULL ;
458 
459  /* Create the output imagelist */
460  out = cpl_imagelist_new() ;
461 
462  /* Get the filename */
463  fname = cpl_frame_get_filename(frame);
464 
465  /* Check that the frame has the right number of extension */
466  if(cpl_frame_get_nextensions(frame) != HAWKI_NB_DETECTORS)
467  {
468  cpl_msg_error(__func__, "File %s contains less than %d extensions",
469  fname, HAWKI_NB_DETECTORS);
470  cpl_imagelist_delete(out);
471  return NULL ;
472  }
473 
474  /* Get the extension-chip mapping */
475  ext_chip_mapping = hawki_get_ext_detector_mapping(fname);
476  if (ext_chip_mapping == NULL)
477  {
478  cpl_msg_error(__func__,"Cannot get mapping between extension and chip");
479  cpl_imagelist_delete(out);
480  return NULL;
481  }
482 
483  /* Loop on the chips */
484  for (idet=0 ; idet< HAWKI_NB_DETECTORS ; idet++)
485  {
486  /* Get the extension */
487  ext_nb = ext_chip_mapping[idet];
488 
489  /* Load */
490  if ((ima=cpl_image_load(fname, ptype, 0, ext_nb)) == NULL)
491  {
492  cpl_msg_error(__func__, "Cannot load frame (detector %d)",
493  idet);
494  cpl_imagelist_delete(out);
495  return NULL;
496  }
497  cpl_imagelist_set(out, ima, idet);
498  }
499 
500  /* Free */
501  cpl_free(ext_chip_mapping);
502  return out;
503 }
504 
512 /*----------------------------------------------------------------------------*/
514  const cpl_frame * frame,
515  int iextension,
516  cpl_type ptype)
517 {
518  cpl_image * ima;
519  const char * fname;
520 
521  /* Test entries */
522  if (frame == NULL) return NULL ;
523 
524  /* Get filename */
525  fname = cpl_frame_get_filename(frame);
526 
527  /* Load */
528  if ((ima=cpl_image_load(fname, ptype, 0, iextension)) == NULL)
529  {
530  cpl_msg_error(__func__, "Cannot load frame (extension %d)",
531  iextension) ;
532  return NULL ;
533  }
534 
535  /* Return */
536  return ima;
537 }
538 
546 /*----------------------------------------------------------------------------*/
548  const cpl_frame * frame,
549  int idet,
550  cpl_type ptype)
551 {
552  cpl_image * ima;
553  const char * fname;
554  int ext_nb;
555 
556  /* Test entries */
557  if (frame == NULL) return NULL ;
558 
559  /* Get filename */
560  fname = cpl_frame_get_filename(frame);
561 
562  /* Get the extension with the wished chip */
563  if ((ext_nb = hawki_get_ext_from_detector(fname, idet)) == -1)
564  {
565  cpl_msg_error(__func__, "Cannot get the extension with chip %d",
566  idet) ;
567  return NULL ;
568  }
569  /* Load */
570  if ((ima=cpl_image_load(fname, ptype, 0, ext_nb)) == NULL)
571  {
572  cpl_msg_error(__func__, "Cannot load frame (chip %d)",
573  idet) ;
574  return NULL ;
575  }
576 
577  /* Return */
578  return ima;
579 }
580 
588 /*----------------------------------------------------------------------------*/
589 cpl_table ** hawki_load_tables(const cpl_frame * frame)
590 {
591  cpl_table ** tables;
592  const char * filename;
593  int idet;
594  int j;
595  int ext_nb;
596 
597  /* Allocate the set of tables */
598  tables = cpl_malloc(HAWKI_NB_DETECTORS * sizeof(cpl_table *));
599 
600  /* Get the filename */
601  filename = cpl_frame_get_filename(frame);
602  for (idet=0 ; idet< HAWKI_NB_DETECTORS ; idet++)
603  {
604  /* Get the extension with the wished chip */
605  if ((ext_nb = hawki_get_ext_from_detector(filename, idet+1)) == -1)
606  {
607  cpl_msg_error(__func__, "Cannot get the extension with detector %d",
608  idet+1) ;
609  return NULL ;
610  }
611  /* Load the table */
612  if((tables[idet] = cpl_table_load(filename, ext_nb, 0) ) == NULL)
613  {
614  for (j=0 ; j< idet ; j++)
615  {
616  cpl_table_delete(tables[j]);
617  }
618  cpl_free(tables);
619  return NULL;
620  }
621  }
622 
623  return tables;
624 }
625 
632 /*----------------------------------------------------------------------------*/
633 cpl_bivector ** hawki_load_refined_offsets(const cpl_frame * offsets_frame)
634 {
635  cpl_errorstate previous_state;
636  cpl_table ** offsets_tables;
637  cpl_bivector ** offsets;
638  int idet;
639 
640  /* Get the error state */
641  previous_state = cpl_errorstate_get();
642 
643  /* Read the offsets table */
644  if((offsets_tables = hawki_load_tables(offsets_frame)) == NULL)
645  return NULL;
646 
647  /* Convert the table to offsets bivectors */
648  offsets = cpl_malloc(HAWKI_NB_DETECTORS * sizeof(cpl_bivector *));
649  if(offsets == NULL)
650  {
651  for(idet = 0; idet < HAWKI_NB_DETECTORS; ++idet)
652  cpl_table_delete(offsets_tables[idet]);
653  return NULL;
654  }
655  for(idet = 0; idet < HAWKI_NB_DETECTORS; ++idet)
656  {
657  cpl_vector * off_x;
658  cpl_vector * off_y;
659  int noff;
660  int ioff;
661  int jdet;
662 
663  noff = cpl_table_get_nrow(offsets_tables[idet]);
664  offsets[idet] = cpl_bivector_new(noff);
665  if(offsets[idet] == NULL)
666  {
667  for(idet = 0; idet < HAWKI_NB_DETECTORS; ++idet)
668  cpl_table_delete(offsets_tables[idet]);
669  for(jdet = 0; jdet < idet; ++jdet)
670  cpl_bivector_delete(offsets[jdet]);
671  cpl_free(offsets[jdet]);
672  return NULL;
673  }
674  off_x = cpl_bivector_get_x(offsets[idet]);
675  off_y = cpl_bivector_get_y(offsets[idet]);
676  for(ioff = 0; ioff < noff; ++ioff)
677  {
678  double xoffset, yoffset;
679  xoffset = cpl_table_get
680  (offsets_tables[idet], HAWKI_COL_OFFSET_X, ioff, NULL);
681  yoffset = cpl_table_get
682  (offsets_tables[idet], HAWKI_COL_OFFSET_Y, ioff, NULL);
683  cpl_vector_set(off_x, ioff, xoffset);
684  cpl_vector_set(off_y, ioff, yoffset);
685  }
686  }
687 
688  /* Check error state */
689  if(cpl_errorstate_get() != previous_state)
690  {
691  for(idet = 0; idet < HAWKI_NB_DETECTORS; ++idet)
692  {
693  cpl_table_delete(offsets_tables[idet]);
694  cpl_bivector_delete(offsets[idet]);
695  }
696  cpl_free(offsets);
697  return NULL;
698  }
699 
700  /* Free and exit */
701  for(idet = 0; idet < HAWKI_NB_DETECTORS; ++idet)
702  cpl_table_delete(offsets_tables[idet]);
703  cpl_free(offsets_tables);
704 
705  return offsets;
706 }
707 
708 /*----------------------------------------------------------------------------*/
717 /*----------------------------------------------------------------------------*/
719  const cpl_image * ima1,
720  const cpl_image * ima2,
721  const cpl_image * ima3,
722  const cpl_image * ima4)
723 {
724  cpl_image * ima ;
725 
726  /* Test entries */
727  if (ima1 == NULL) return NULL ;
728  if (ima2 == NULL) return NULL ;
729  if (ima3 == NULL) return NULL ;
730  if (ima4 == NULL) return NULL ;
731  if (cpl_image_get_type(ima1)!=cpl_image_get_type(ima2)) return NULL ;
732  if (cpl_image_get_type(ima1)!=cpl_image_get_type(ima3)) return NULL ;
733  if (cpl_image_get_type(ima1)!=cpl_image_get_type(ima4)) return NULL ;
734 
735  /* Create the image */
736  ima = cpl_image_new(4096, 4096, cpl_image_get_type(ima1)) ;
737 
738  /* Paste the input images */
739  if (cpl_image_copy(ima, ima1, 1, 1) != CPL_ERROR_NONE) {
740  cpl_image_delete(ima) ;
741  return NULL ;
742  }
743  if (cpl_image_copy(ima, ima2, 2049, 1) != CPL_ERROR_NONE) {
744  cpl_image_delete(ima) ;
745  return NULL ;
746  }
747  if (cpl_image_copy(ima, ima3, 2049, 2049) != CPL_ERROR_NONE) {
748  cpl_image_delete(ima) ;
749  return NULL ;
750  }
751  if (cpl_image_copy(ima, ima4, 1, 2049) != CPL_ERROR_NONE) {
752  cpl_image_delete(ima) ;
753  return NULL ;
754  }
755  return ima ;
756 }
757 
758 
759 /*----------------------------------------------------------------------------*/
768 /*----------------------------------------------------------------------------*/
770  const cpl_image * ima1,
771  const cpl_image * ima2,
772  const cpl_image * ima3,
773  const cpl_image * ima4)
774 {
775  cpl_image * ima ;
776 
777  /* Test entries */
778  if (ima1 == NULL) return NULL ;
779  if (ima2 == NULL) return NULL ;
780  if (ima3 == NULL) return NULL ;
781  if (ima4 == NULL) return NULL ;
782  if (cpl_image_get_type(ima1)!=cpl_image_get_type(ima2)) return NULL ;
783  if (cpl_image_get_type(ima1)!=cpl_image_get_type(ima3)) return NULL ;
784  if (cpl_image_get_type(ima1)!=cpl_image_get_type(ima4)) return NULL ;
785 
786  /* Create the image */
787  ima = cpl_image_new(2048, 2048, cpl_image_get_type(ima1)) ;
788 
789  /* Paste the input images */
790  if (cpl_image_copy(ima, ima1, 1, 1) != CPL_ERROR_NONE) {
791  cpl_image_delete(ima) ;
792  return NULL ;
793  }
794  if (cpl_image_copy(ima, ima2, 1025, 1) != CPL_ERROR_NONE) {
795  cpl_image_delete(ima) ;
796  return NULL ;
797  }
798  if (cpl_image_copy(ima, ima3, 1, 1025) != CPL_ERROR_NONE) {
799  cpl_image_delete(ima) ;
800  return NULL ;
801  }
802  if (cpl_image_copy(ima, ima4, 1025, 1025) != CPL_ERROR_NONE) {
803  cpl_image_delete(ima) ;
804  return NULL ;
805  }
806  return ima ;
807 }
808 
809 /*----------------------------------------------------------------------------*/
816 /*----------------------------------------------------------------------------*/
818  const char * fname,
819  int ext)
820 {
821  cpl_propertylist * plist ;
822  const char * sval ;
823  int chip ;
824 
825  /* Test entries */
826  if (ext <= 0 || ext > HAWKI_NB_DETECTORS) return -1 ;
827 
828  /* Load the extension */
829  plist=cpl_propertylist_load(fname, ext) ;
830  if (plist == NULL) return -1 ;
831  sval = hawki_pfits_get_extname(plist) ;
832  if (sscanf(sval, "CHIP%d.INT1", &chip) != 1) chip = -1 ;
833  cpl_propertylist_delete(plist) ;
834 
835  return chip ;
836 }
837 
838 /*----------------------------------------------------------------------------*/
845 /*----------------------------------------------------------------------------*/
847  const char * fname,
848  int chip)
849 {
850  cpl_propertylist * plist ;
851  const char * sval ;
852  char chipval[512] ;
853  int ext_nb ;
854  int iext;
855 
856  /* Test entries */
857  if (fname == NULL) return -1;
858  if (chip <= 0 || chip > HAWKI_NB_DETECTORS) return -1 ;
859 
860  /* Initialise */
861  ext_nb = -1 ;
862 
863  /* Create the wished chipval */
864  snprintf(chipval, 512, "CHIP%d.INT1", chip) ;
865 
866  /* Loop on the HAWKI_NB_DETECTORS extensions */
867  for (iext=0 ; iext<HAWKI_NB_DETECTORS ; iext++) {
868  /* Load the propertylist of the current extension */
869  if ((plist = cpl_propertylist_load(fname, iext+1)) == NULL) {
870  cpl_msg_error(__func__, "Cannot read the Extname keyword") ;
871  return -1 ;
872  }
873  if ((sval = hawki_pfits_get_extname(plist)) == NULL) {
874  cpl_msg_error(__func__, "Cannot read the Extname keyword") ;
875  cpl_propertylist_delete(plist) ;
876  return -1 ;
877  }
878  /* Check if the chip is found */
879  if (!strcmp(chipval, sval)) {
880  ext_nb = iext+1 ;
881  cpl_propertylist_delete(plist) ;
882  break;
883  }
884  cpl_propertylist_delete(plist) ;
885  }
886  return ext_nb ;
887 }
888 
889 /*----------------------------------------------------------------------------*/
895 /*----------------------------------------------------------------------------*/
897 (const char * fname)
898 {
899  int iext;
900  int * ext_chip_mapping;
901 
902 
903  /* Test entries */
904  if (fname == NULL) return NULL;
905 
906  /* Initialise */
907  ext_chip_mapping = cpl_malloc(sizeof(int) * HAWKI_NB_DETECTORS);
908 
909  /* Loop on the HAWKI_NB_DETECTORS extensions */
910  for (iext=0 ; iext<HAWKI_NB_DETECTORS ; iext++) {
911  int ichip = hawki_get_detector_from_ext(fname, iext + 1);
912  ext_chip_mapping[ichip-1] = iext + 1;
913  }
914  return ext_chip_mapping;
915 }