X-shooter Pipeline Reference Manual 3.8.15
xsh_data_linetilt.c
Go to the documentation of this file.
1/* *
2 * This file is part of the ESO X-shooter Pipeline *
3 * Copyright (C) 2006 European Southern Observatory *
4 * *
5 * This library 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
20/*
21 * $Author: amodigli $
22 * $Date: 2013-03-18 15:15:17 $
23 * $Revision: 1.33 $
24 * $Name: not supported by cvs2svn $
25 */
26
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30#include <math.h>
31
32/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
42/*-----------------------------------------------------------------------------
43 Includes
44 ----------------------------------------------------------------------------*/
45#include <xsh_data_instrument.h>
46#include <xsh_data_arclist.h>
47#include <xsh_data_linetilt.h>
48#include <xsh_utils.h>
49#include <xsh_error.h>
50#include <xsh_msg.h>
51#include <xsh_pfits.h>
52#include <xsh_dfs.h>
53#include <cpl.h>
54#include <xsh_utils_table.h>
55
56
57#define XSH_MAX_SHIFT_Y 10.
58/*----------------------------------------------------------------------------
59 Function implementation
60 ----------------------------------------------------------------------------*/
61
63 cpl_propertylist * header )
64{
65 xsh_linetilt_list * result = NULL ;
66
67 XSH_ASSURE_NOT_NULL( header ) ;
68
69 /* Create an empty list */
70 check( result = cpl_malloc( sizeof( xsh_linetilt_list ) ) ) ;
71 memset( result, 0, sizeof( xsh_linetilt_list ) ) ;
72
73 check( result->list = cpl_malloc( sizeof( xsh_linetilt * ) * size ) ) ;
74 memset( result->list, 0, sizeof( xsh_linetilt * )*size ) ;
75 result->full_size = size ;
76 result->header = header ;
77
78 cleanup:
79 return result ;
80}
85/*---------------------------------------------------------------------------*/
87{
88 int i;
89
90 if (list && *list) {
91 if ((*list)->list) {
92 for (i=0; i< (*list)->size; i++) {
93 xsh_linetilt * tilt = (*list)->list[i];
94 xsh_linetilt_free( &tilt );
95 }
96 cpl_free((*list)->list);
97 xsh_free_propertylist(&((*list)->header));
98 }
99 cpl_free(*list);
100 *list = NULL;
101 }
102}
103/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
110{
111 if (tilt && (*tilt) ){
112 if ((*tilt)->name != NULL) {
113 cpl_free(( *tilt)->name );
114 }
115 cpl_free( *tilt );
116 *tilt = NULL;
117 }
118}
119
121{
122 xsh_linetilt * result = NULL ;
123
124 XSH_CALLOC( result, xsh_linetilt, 1) ;
125
126 cleanup:
127 return result ;
128}
129
138 xsh_linetilt * line, int idx )
139{
140 XSH_ASSURE_NOT_NULL( list ) ;
141 XSH_ASSURE_NOT_NULL( line ) ;
142 list->list[idx] = line ;
143 list->size++ ;
144 cleanup:
145 return ;
146}
147/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
161 xsh_instrument * instr,
162 const char* filename,
163 const char* tag,
164 const double kappa,
165 const int niter,
166 float exptime)
167{
168 cpl_table* table = NULL;
169 cpl_table* ext = NULL;
170 cpl_frame * result = NULL ;
171 int i=0;
172 //int j=0;
173 //double med=0;
174 //double rms=0;
175 //double* pres=0;
176 //int nrow=0;
178 XSH_ASSURE_NOT_NULL(filename);
179
180 /* create a table */
181 check( table = cpl_table_new( XSH_LINETILT_TABLE_NB_COL));
182
183 /* create column names */
184 check(
185 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_WAVELENGTH,
186 CPL_TYPE_FLOAT));
187 check(
188 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_WAVELENGTH,
190
191 check(
192 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_NAME,
193 CPL_TYPE_STRING));
194 check(
195 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_NAME,
197
198 check(
199 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_ORDER,
200 CPL_TYPE_INT));
201 check(
202 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_ORDER,
204
205 check(
206 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_FLUX,
207 CPL_TYPE_DOUBLE));
208 check(
209 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_FLUX,
211
212 check(
213 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_INTENSITY,
214 CPL_TYPE_DOUBLE));
215 check(
216 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_INTENSITY,
218
219 check(
220 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_CENPOSX,
221 CPL_TYPE_DOUBLE));
222 check(
223 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_CENPOSX,
225
226 check(
227 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_CENPOSY,
228 CPL_TYPE_DOUBLE));
229 check(
230 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_CENPOSY,
232
233
234 check(
235 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_GAUSSY,
236 CPL_TYPE_DOUBLE));
237 check(
238 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_GAUSSY,
240
241 check(
242 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_TILTY,
243 CPL_TYPE_DOUBLE));
244 check(
245 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_TILTY,
247
248 check(
249 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_FWHM,
250 CPL_TYPE_DOUBLE));
251 check(
252 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_FWHM,
254
255 check(
256 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_SHIFTY,
257 CPL_TYPE_DOUBLE));
258 check(
259 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_SHIFTY,
261
262 check(
263 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_TILT,
264 CPL_TYPE_DOUBLE));
265 check(
266 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_TILT,
268
269 check(
270 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_CHISQ,
271 CPL_TYPE_DOUBLE));
272 check(
273 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_CHISQ,
275
276 check(
277 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_SPECRES,
278 CPL_TYPE_DOUBLE));
279 check(
280 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_SPECRES,
282 check(
283 cpl_table_new_column(table,XSH_LINETILT_TABLE_COLNAME_FLAG,
284 CPL_TYPE_INT));
285 check(
286 cpl_table_set_column_unit ( table, XSH_LINETILT_TABLE_COLNAME_FLAG,
288
289
290
291
292 check(cpl_table_set_size(table,list->size));
293
294 /* insert data */
295 for(i=0;i<list->size;i++){
296 check(cpl_table_set_float(table,XSH_LINETILT_TABLE_COLNAME_WAVELENGTH,
297 i,list->list[i]->wavelength));
298 check(cpl_table_set_string(table,XSH_LINETILT_TABLE_COLNAME_NAME,
299 i,list->list[i]->name));
300 check(cpl_table_set_int(table,XSH_LINETILT_TABLE_COLNAME_ORDER,
301 i,list->list[i]->order));
302 check(cpl_table_set_double(table,XSH_LINETILT_TABLE_COLNAME_FLUX,
303 i,list->list[i]->area));
304 check(cpl_table_set_double(table,XSH_LINETILT_TABLE_COLNAME_INTENSITY,
305 i,list->list[i]->intensity));
306 check(cpl_table_set_double(table,XSH_LINETILT_TABLE_COLNAME_CENPOSX,
307 i,list->list[i]->cenposx));
308 check(cpl_table_set_double(table,XSH_LINETILT_TABLE_COLNAME_CENPOSY,
309 i,list->list[i]->pre_pos_y));
310 check(cpl_table_set_double(table,XSH_LINETILT_TABLE_COLNAME_GAUSSY,
311 i,list->list[i]->cenposy));
312 check(cpl_table_set_double(table,XSH_LINETILT_TABLE_COLNAME_TILTY,
313 i,list->list[i]->tilt_y));
314 check(cpl_table_set_double(table,XSH_LINETILT_TABLE_COLNAME_FWHM,
315 i,list->list[i]->deltay));
316 check(cpl_table_set_double(table,XSH_LINETILT_TABLE_COLNAME_SHIFTY,
317 i,list->list[i]->shift_y));
318 check(cpl_table_set_double(table,XSH_LINETILT_TABLE_COLNAME_TILT,
319 i,list->list[i]->tilt));
320 check(cpl_table_set_double(table,XSH_LINETILT_TABLE_COLNAME_CHISQ,
321 i,list->list[i]->chisq));
322
323 check(cpl_table_set_double(table,XSH_LINETILT_TABLE_COLNAME_SPECRES,
324 i,list->list[i]->specres));
325
326 if( fabs(list->list[i]->shift_y)> XSH_MAX_SHIFT_Y ) {
327 list->list[i]->flag=3;
328 check(cpl_table_set_int(table,XSH_LINETILT_TABLE_COLNAME_FLAG,
329 i,3));
330
331 }
332
333 if(list->list[i]->flag>0) {
334 cpl_table_set_invalid(table,XSH_LINETILT_TABLE_COLNAME_SHIFTY, i);
335 cpl_table_set_invalid(table,XSH_LINETILT_TABLE_COLNAME_FWHM, i);
336 cpl_table_set_invalid(table,XSH_LINETILT_TABLE_COLNAME_INTENSITY, i);
337 }
338 check(cpl_table_set_int(table,XSH_LINETILT_TABLE_COLNAME_FLAG,
339 i,list->list[i]->flag));
340 }
341
342
343 int k=0;
344 double yshift_std=0;
345 double yshift_avg=0;
346 double* pshift=NULL;
347 pshift=cpl_table_get_data_double(table,XSH_LINETILT_TABLE_COLNAME_SHIFTY);
348 //PIPPO
349 for(k=0;k<niter;k++) {
350 yshift_std=cpl_table_get_column_stdev(table,XSH_LINETILT_TABLE_COLNAME_SHIFTY);
351 yshift_avg=cpl_table_get_column_mean(table,XSH_LINETILT_TABLE_COLNAME_SHIFTY);
352 for(i=0;i<list->size;i++){
353 if( fabs(pshift[i]-yshift_avg) > kappa*yshift_std ) {
354 list->list[i]->flag=4;
355 cpl_table_set_invalid(table,XSH_LINETILT_TABLE_COLNAME_SHIFTY, i);
356 cpl_table_set_invalid(table,XSH_LINETILT_TABLE_COLNAME_FWHM, i);
357 cpl_table_set_invalid(table,XSH_LINETILT_TABLE_COLNAME_INTENSITY, i);
358 check(cpl_table_set_int(table,XSH_LINETILT_TABLE_COLNAME_FLAG,
359 i,4));
360 }
361 }
362 }
363 double avg;
364 double med;
365 double std;
366 double wavg;
367 double wstd;
368 double iavg;
369 double iavg_norm;
370
371 avg = cpl_table_get_column_mean(table,XSH_LINETILT_TABLE_COLNAME_SHIFTY );
372 med = cpl_table_get_column_median(table,XSH_LINETILT_TABLE_COLNAME_SHIFTY );
373 std = cpl_table_get_column_stdev(table,XSH_LINETILT_TABLE_COLNAME_SHIFTY );
374
375 wstd = cpl_table_get_column_stdev(table, XSH_LINETILT_TABLE_COLNAME_FWHM);
376 wavg = cpl_table_get_column_mean(table, XSH_LINETILT_TABLE_COLNAME_FWHM);
377
378 iavg = cpl_table_get_column_mean(table, XSH_LINETILT_TABLE_COLNAME_INTENSITY);
379
380 xsh_pfits_set_qc( list->header, &avg, QC_WAVECAL_DIFFYAVG,instr );
381 xsh_pfits_set_qc( list->header, &med, QC_WAVECAL_DIFFYMED,instr );
382 xsh_pfits_set_qc( list->header, &std, QC_WAVECAL_DIFFYSTD,instr );
383 xsh_pfits_set_qc( list->header, &iavg, QC_WAVECAL_NLININT,instr );
384 if(exptime > 0){
385 iavg_norm = iavg/exptime;
386 xsh_pfits_set_qc( list->header, &iavg_norm,QC_WAVECAL_LININT_NORM,instr);
387 }
388 xsh_pfits_set_qc( list->header, &wavg, QC_WAVECAL_FWHMAVG,instr );
389 xsh_pfits_set_qc( list->header, &wstd, QC_WAVECAL_FWHMRMS,instr );
390
391 /* create fits file */
392 check( xsh_pfits_set_pcatg(list->header,tag));
393 check(cpl_table_save(table, list->header, NULL, filename, CPL_IO_DEFAULT));
394
395 /* Create the frame */
396 check(result=xsh_frame_product(filename,
398 CPL_FRAME_TYPE_TABLE,
399 CPL_FRAME_GROUP_PRODUCT,
400 CPL_FRAME_LEVEL_TEMPORARY));
401 xsh_add_temporary_file( filename ) ;
402
403 cleanup:
404 xsh_free_table(&ext);
405 XSH_TABLE_FREE( table);
406 return result ;
407}
408
409
417/*---------------------------------------------------------------------------*/
419{
420 double* res = NULL, *p ;
421 int i, size ;
422
423 XSH_ASSURE_NOT_NULL( list );
424 size = list->size ;
425 check( res = cpl_malloc( list->size * sizeof(double) ) ) ;
426 for( p = res, i = 0 ; i<size ; i++, p++ )
427 *p = list->list[i]->cenposx ;
428
429 cleanup:
430 return res;
431}
432
440/*---------------------------------------------------------------------------*/
442{
443 double* res = NULL, *p ;
444 int i, size ;
445
446 XSH_ASSURE_NOT_NULL( list );
447 size = list->size ;
448 check( res = cpl_malloc( list->size * sizeof(double) ) ) ;
449 for( p = res, i = 0 ; i<size ; i++, p++ )
450 *p = list->list[i]->cenposy ;
451
452 cleanup:
453 return res;
454}
455
463/*---------------------------------------------------------------------------*/
465{
466 double* res = NULL, *p ;
467 int i, size ;
468
469 XSH_ASSURE_NOT_NULL( list );
470 size = list->size ;
471
472 check( res = cpl_malloc( list->size * sizeof(double) ) ) ;
473 for( p = res, i = 0 ; i<size ; i++, p++ )
474 *p = list->list[i]->deltay ;
475
476
477 cleanup:
478 return res;
479}
480
488/*---------------------------------------------------------------------------*/
490{
491 double* res = NULL, *p ;
492 int i, size ;
493
494 XSH_ASSURE_NOT_NULL( list );
495 size = list->size ;
496
497 check( res = cpl_malloc( list->size * sizeof(double) ) ) ;
498 for( p = res, i = 0 ; i<size ; i++, p++ )
499 *p = list->list[i]->chisq ;
500
501
502 cleanup:
503 return res;
504}
505
513/*---------------------------------------------------------------------------*/
515{
516 double* res = NULL, *p ;
517 int i, size ;
518
519 XSH_ASSURE_NOT_NULL( list );
520 size = list->size ;
521
522 check( res = cpl_malloc( list->size * sizeof(double) ) ) ;
523 for( p = res, i = 0 ; i<size ; i++, p++ )
524 *p = list->list[i]->pre_pos_y ;
525
526
527 cleanup:
528 return res;
529}
530
538/*---------------------------------------------------------------------------*/
540{
541 double* res = NULL, *p ;
542 int i, size ;
543
544 XSH_ASSURE_NOT_NULL( list );
545 size = list->size ;
546 check( res = cpl_malloc( list->size * sizeof(double) ) ) ;
547 for( p = res, i = 0 ; i<size ; i++, p++ )
548 *p = list->list[i]->order ;
549
550 cleanup:
551 return res;
552}
553
561/*---------------------------------------------------------------------------*/
563{
564 double* res = NULL, *p ;
565 int i, size ;
566
567 XSH_ASSURE_NOT_NULL( list );
568 size = list->size ;
569 check( res = cpl_malloc( list->size * sizeof(double) ) ) ;
570 for( p = res, i = 0 ; i<size ; i++, p++ )
571 *p = list->list[i]->wavelength ;
572
573 cleanup:
574 return res;
575}
576
584/*---------------------------------------------------------------------------*/
586{
587 double* res = NULL, *p ;
588 int i, size ;
589
590 XSH_ASSURE_NOT_NULL( list );
591 size = list->size ;
592 check( res = cpl_malloc( list->size * sizeof(double) ) ) ;
593 for( p = res, i = 0 ; i<size ; i++, p++ )
594 *p = list->list[i]->slit ;
595
596 cleanup:
597 return res;
598}
599
607/*---------------------------------------------------------------------------*/
609{
610 int * res = NULL, *p ;
611 int i, size ;
612
613 XSH_ASSURE_NOT_NULL( list );
614 size = list->size ;
615 check( res = cpl_malloc( list->size * sizeof(int) ) ) ;
616 for( p = res, i = 0 ; i<size ; i++, p++ )
617 *p = list->list[i]->slit_index ;
618
619 cleanup:
620 return res;
621}
622
632{
633 cpl_propertylist * res = NULL ;
634
635 XSH_ASSURE_NOT_NULL( list );
636
637 res = list->header ;
638
639 cleanup:
640 return res;
641}
642
653 int order )
654{
655 int i, res = 0 ;
656 XSH_ASSURE_NOT_NULL( list );
657
658 for( i = 0 ; i<list->size ; i++ ) {
659 if ( list->list[i]->wavelength == lambda &&
660 list->list[i]->order == order ) {
661 res = 1 ;
662 break ;
663 }
664 }
665
666 cleanup:
667 return res ;
668}
669
670#if 0
671static int xsh_arclist_lambda_compare(const void* one, const void* two){
672 xsh_arcline** a = NULL;
673 xsh_arcline** b = NULL;
674 float la, lb;
675
676 a = (xsh_arcline**) one;
677 b = (xsh_arcline**) two;
678
679 la = (*a)->wavelength;
680 lb = (*b)->wavelength;
681
682 if (la <= lb)
683 return -1;
684 else
685 return 1;
686
687
688}
689
690
691/*---------------------------------------------------------------------------*/
698/*---------------------------------------------------------------------------*/
700 qsort(list->list,list->size,sizeof(xsh_arcline*),
702}
703
704/*---------------------------------------------------------------------------*/
711/*---------------------------------------------------------------------------*/
713 int i=0;
714
716 i = list->size;
717
718 cleanup:
719 return i;
720}
721
722
723/*---------------------------------------------------------------------------*/
730/*---------------------------------------------------------------------------*/
732 int i=0;
733
735 i = list->nbrejected;
736
737 cleanup:
738 return i;
739}
740
741/*---------------------------------------------------------------------------*/
749/*---------------------------------------------------------------------------*/
750float xsh_arclist_get_wavelength(xsh_arclist* list, int index)
751{
752 float f = 0.0;
753
755 XSH_ASSURE_NOT_ILLEGAL(index >= 0 && index < list->size);
756 f = list->list[index]->wavelength;
757
758 cleanup:
759 return f;
760}
761
762/*---------------------------------------------------------------------------*/
769/*---------------------------------------------------------------------------*/
770void xsh_arclist_reject(xsh_arclist* list, int index)
771{
773 XSH_ASSURE_NOT_ILLEGAL(index >= 0 && index < list->size);
774
775 list->rejected[index] = 1;
776 list->nbrejected++;
777
778 cleanup:
779 return;
780
781}
782
783/*---------------------------------------------------------------------------*/
790/*---------------------------------------------------------------------------*/
791void xsh_arclist_restore(xsh_arclist* list, int index)
792{
794 XSH_ASSURE_NOT_ILLEGAL(index >= 0 && index < list->size);
795
796 list->rejected[index] = 0;
797 list->nbrejected--;
798
799 cleanup:
800 return;
801
802}
803/*---------------------------------------------------------------------------*/
810/*---------------------------------------------------------------------------*/
811int xsh_arclist_is_rejected(xsh_arclist* list, int index)
812{
813 int res = 0;
814
816 XSH_ASSURE_NOT_ILLEGAL(index >= 0 && index < list->size);
817
818 res = list->rejected[index];
819 cleanup:
820 return res;
821}
822
823/*---------------------------------------------------------------------------*/
829/*---------------------------------------------------------------------------*/
830cpl_propertylist* xsh_arclist_get_header(xsh_arclist* list)
831{
832 cpl_propertylist * res = NULL;
833
835 res = list->header;
836 cleanup:
837 return res;
838}
839
840/*---------------------------------------------------------------------------*/
846/*---------------------------------------------------------------------------*/
847void xsh_dump_arclist( xsh_arclist* list)
848{
849 int i = 0;
850
852
853 xsh_msg( "ARCLINE_LIST Dump %d lines",list->size);
854
855 for(i=0; i< list->size; i++) {
856 const char* name = list->list[i]->name;
857 const char* comment = list->list[i]->comment;
858 if (name == NULL) name ="";
859 if (comment == NULL) comment ="";
860 xsh_msg(" Wavelength %f name %s flux %d comment %s",
861 list->list[i]->wavelength, name,
862 list->list[i]->flux, comment);
863 }
864 xsh_msg( "END ARCLINE_LIST");
865
866 cleanup:
867 return;
868}
869
870/*---------------------------------------------------------------------------*/
877/*---------------------------------------------------------------------------*/
878xsh_arclist* xsh_arclist_load(cpl_frame* frame){
879 cpl_table* table = NULL;
880 const char* tablename = NULL;
881 xsh_arclist* result = NULL;
882 int i = 0;
883
884 /* verify input */
885 XSH_ASSURE_NOT_NULL(frame);
886
887 /* get table filename */
888 check( tablename = cpl_frame_get_filename(frame));
889
890 XSH_TABLE_LOAD( table, tablename);
891
892 /* allocate memory */
893 XSH_CALLOC(result,xsh_arclist,1);
894
895 /* init structure */
896 check(result->size = cpl_table_get_nrow(table));
897 XSH_CALLOC(result->list, xsh_arcline*, result->size);
898 XSH_CALLOC(result->rejected, int, result->size);
899 result->nbrejected = 0;
900
901 check(result->header = cpl_propertylist_load(tablename, 0));
902
903 /* load table data */
904 for(i=0;i<result->size;i++){
905 const char* name ="";
906 const char* comment ="";
907 xsh_arcline* arc = (xsh_arcline*)cpl_malloc(sizeof(xsh_arcline));
908
910 CPL_TYPE_FLOAT, i, &(arc->wavelength)));
912 CPL_TYPE_STRING, i, &name));
914 CPL_TYPE_INT, i, &(arc->flux)));
916 CPL_TYPE_STRING, i, &comment));
917 if (name != NULL) {
918 arc->name = xsh_stringdup(name);
919 }
920 else {
921 arc->name = NULL;
922 }
923 if (comment != NULL) {
924 arc->comment = xsh_stringdup(comment);
925 }
926 else {
927 arc->comment = NULL;
928 }
929 result->list[i] = arc;
930 }
931
932 cleanup:
933 if (cpl_error_get_code () != CPL_ERROR_NONE) {
934 xsh_error_msg("can't load frame %s",cpl_frame_get_filename(frame));
935 xsh_arclist_free(&result);
936 }
937 XSH_TABLE_FREE( table);
938 return result;
939}
940
941/*---------------------------------------------------------------------------*/
946/*---------------------------------------------------------------------------*/
948{
949 if (arc && (*arc)){
950 if ((*arc)->name != NULL) {
951 cpl_free((*arc)->name);
952 }
953 if ((*arc)->comment != NULL) {
954 cpl_free((*arc)->comment);
955 }
956 cpl_free(*arc);
957 *arc = NULL;
958 }
959}
960
961/*---------------------------------------------------------------------------*/
966/*---------------------------------------------------------------------------*/
967void xsh_arclist_free(xsh_arclist** list)
968{
969 int i;
970
971 if (list && *list) {
972 if ((*list)->list) {
973 for (i=0; i< (*list)->size; i++) {
974 xsh_arcline* arc = (*list)->list[i];
975 xsh_arcline_free(&arc);
976 }
977 cpl_free((*list)->list);
978 xsh_free_propertylist(&((*list)->header));
979 }
980 XSH_FREE((*list)->rejected);
981 cpl_free(*list);
982 *list = NULL;
983 }
984}
985
987{
988 int i, j;
989
991
992 j = 0;
993 for(i=0;i<list->size;i++)
994 {
995 if(xsh_arclist_is_rejected(list,i)){
996 xsh_arcline_free(&list->list[i]);
997 }
998 else{
999 j++;
1000 list->list[j-1] = list->list[i];
1001 list->rejected[j] = 0;
1002 }
1003 }
1004 list->size = j;
1005 list->nbrejected = 0;
1006
1007 cleanup:
1008 return;
1009}
1010/*---------------------------------------------------------------------------*/
1019/*---------------------------------------------------------------------------*/
1020cpl_frame*
1021xsh_arclist_save(xsh_arclist* list,const char* filename,const char* tag)
1022{
1023 cpl_table* table = NULL;
1024 cpl_frame * result = NULL ;
1025 int i=0;
1026
1027 XSH_ASSURE_NOT_NULL(list);
1028 XSH_ASSURE_NOT_NULL(filename);
1029
1030 /* create a table */
1031 check(table = cpl_table_new(XSH_ARCLIST_TABLE_NB_COL));
1032
1033 /* create column names */
1034 check(
1035 cpl_table_new_column(table,XSH_ARCLIST_TABLE_COLNAME_WAVELENGTH,
1036 CPL_TYPE_FLOAT));
1037 check(
1038 cpl_table_set_column_unit ( table, XSH_ARCLIST_TABLE_COLNAME_WAVELENGTH,
1040 check(
1041 cpl_table_new_column(table,XSH_ARCLIST_TABLE_COLNAME_NAME,
1042 CPL_TYPE_STRING));
1043 check(
1044 cpl_table_set_column_unit ( table, XSH_ARCLIST_TABLE_COLNAME_NAME,
1046
1047 check(
1048 cpl_table_new_column(table,XSH_ARCLIST_TABLE_COLNAME_FLUX,
1049 CPL_TYPE_INT));
1050 check(
1051 cpl_table_set_column_unit ( table, XSH_ARCLIST_TABLE_COLNAME_FLUX,
1053
1054 check(
1055 cpl_table_new_column(table,XSH_ARCLIST_TABLE_COLNAME_COMMENT,
1056 CPL_TYPE_STRING));
1057 check(
1058 cpl_table_set_column_unit ( table, XSH_ARCLIST_TABLE_COLNAME_COMMENT,
1060
1061 check(cpl_table_set_size(table,list->size));
1062
1063 /* insert data */
1064 for(i=0;i<list->size;i++){
1065 check(cpl_table_set_float(table,XSH_ARCLIST_TABLE_COLNAME_WAVELENGTH,
1066 i,list->list[i]->wavelength));
1067 check(cpl_table_set_string(table,XSH_ARCLIST_TABLE_COLNAME_NAME,
1068 i,list->list[i]->name));
1069 check(cpl_table_set_int(table,XSH_ARCLIST_TABLE_COLNAME_FLUX,
1070 i,list->list[i]->flux));
1071 check(cpl_table_set_string(table,XSH_ARCLIST_TABLE_COLNAME_COMMENT,
1072 i,list->list[i]->comment));
1073 }
1074
1075 /* create fits file */
1076 check(cpl_table_save(table, list->header, NULL, filename, CPL_IO_DEFAULT));
1077
1078 /* Create the frame */
1079 check(result=xsh_frame_product(filename,
1080 tag,
1081 CPL_FRAME_TYPE_TABLE,
1082 CPL_FRAME_GROUP_PRODUCT,
1083 CPL_FRAME_LEVEL_TEMPORARY));
1084
1085
1086 cleanup:
1087 XSH_TABLE_FREE( table);
1088 return result ;
1089}
1090#endif
1091
static double exptime
void xsh_arclist_lambda_sort(xsh_arclist *list)
sort arcline list by increasing lambda
void xsh_dump_arclist(xsh_arclist *list)
Dump main info about an arcline_list.
static int xsh_arclist_lambda_compare(const void *one, const void *two)
float xsh_arclist_get_wavelength(xsh_arclist *list, int idx)
get wavelength of a line in the arcline list
void xsh_arclist_clean(xsh_arclist *list)
int xsh_arclist_get_nbrejected(xsh_arclist *list)
get nb lines rejected in arcline list
void xsh_arclist_free(xsh_arclist **list)
free memory associated to a arclist
void xsh_arclist_restore(xsh_arclist *list, int idx)
restore a line from the list
int xsh_arclist_get_size(xsh_arclist *list)
get size of arcline list
void xsh_arclist_reject(xsh_arclist *list, int idx)
reject a line from the list
xsh_arclist * xsh_arclist_load(cpl_frame *frame)
load an arcline list frame in arclist structure
void xsh_arcline_free(xsh_arcline **arc)
free memory associated to a arcline
int xsh_arclist_is_rejected(xsh_arclist *list, int idx)
give if a line is rejected
cpl_propertylist * xsh_arclist_get_header(xsh_arclist *list)
get header of the table
cpl_frame * xsh_arclist_save(xsh_arclist *list, const char *filename, const char *tag)
save a arclist to a frame
double * xsh_linetilt_list_get_sigma_y(xsh_linetilt_list *list)
get the Y sigma. The returned array must be deallocated by the caller.
double * xsh_linetilt_list_get_slits(xsh_linetilt_list *list)
get the slits . The returned array must be deallocated by the caller.
void xsh_linetilt_list_free(xsh_linetilt_list **list)
free memory associated to a arclist
int xsh_linetilt_is_duplicate(xsh_linetilt_list *list, float lambda, int order)
double * xsh_linetilt_list_get_wavelengths(xsh_linetilt_list *list)
get the wavelength . The returned array must be deallocated by the caller.
xsh_linetilt * xsh_linetilt_new(void)
void xsh_linetilt_list_add(xsh_linetilt_list *list, xsh_linetilt *line, int idx)
int * xsh_linetilt_list_get_slit_index(xsh_linetilt_list *list)
get the slit_index array . The returned array must be deallocated by the caller.
cpl_propertylist * xsh_linetilt_list_get_header(xsh_linetilt_list *list)
double * xsh_linetilt_list_get_posx(xsh_linetilt_list *list)
get the X central positions. The returned array must be deallocated by the caller.
xsh_linetilt_list * xsh_linetilt_list_new(int size, cpl_propertylist *header)
cpl_frame * xsh_linetilt_list_save(xsh_linetilt_list *list, xsh_instrument *instr, const char *filename, const char *tag, const double kappa, const int niter, float exptime)
save a (ks clip clean) linetilt list to a frame
void xsh_linetilt_free(xsh_linetilt **tilt)
free memory associated to a linetilt
double * xsh_linetilt_list_get_orders(xsh_linetilt_list *list)
get the orders . The returned array must be deallocated by the caller.
double * xsh_linetilt_list_get_deltay(xsh_linetilt_list *list)
get the Y Delta. The returned array must be deallocated by the caller.
double * xsh_linetilt_list_get_pre_posy(xsh_linetilt_list *list)
get the previous Y positions. The returned array must be deallocated by the caller.
#define XSH_MAX_SHIFT_Y
double * xsh_linetilt_list_get_posy(xsh_linetilt_list *list)
get the Y central positions. The returned array must be deallocated by the caller.
#define XSH_ASSURE_NOT_ILLEGAL(cond)
Definition: xsh_error.h:107
#define check(COMMAND)
Definition: xsh_error.h:71
#define xsh_error_msg(...)
Definition: xsh_error.h:94
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
int size
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
Definition: xsh_pfits.c:1008
void xsh_pfits_set_qc(cpl_propertylist *plist, void *value, const char *kw, xsh_instrument *instrument)
char * xsh_stringdup(const char *s)
String duplication.
Definition: xsh_utils.c:1658
void xsh_free_table(cpl_table **t)
Deallocate a table and set the pointer to NULL.
Definition: xsh_utils.c:2133
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
Definition: xsh_utils.c:2179
cpl_error_code xsh_get_table_value(const cpl_table *table, const char *colname, cpl_type coltype, int i, void *result)
Read a table value from a fits table.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
Definition: xsh_utils.c:1432
cpl_propertylist * header
xsh_arcline ** list
xsh_linetilt ** list
cpl_propertylist * header
#define XSH_ARCLIST_TABLE_COLNAME_WAVELENGTH
#define XSH_ARCLIST_TABLE_UNIT_WAVELENGTH
#define XSH_ARCLIST_TABLE_COLNAME_NAME
#define XSH_ARCLIST_TABLE_UNIT_NAME
#define XSH_ARCLIST_TABLE_COLNAME_FLUX
#define XSH_ARCLIST_TABLE_UNIT_FLUX
#define XSH_ARCLIST_TABLE_NB_COL
#define XSH_ARCLIST_TABLE_COLNAME_COMMENT
#define XSH_ARCLIST_TABLE_UNIT_COMMENT
#define XSH_LINETILT_TABLE_COLNAME_CHISQ
#define XSH_LINETILT_TABLE_COLNAME_SHIFTY
#define XSH_LINETILT_TABLE_COLNAME_GAUSSY
#define XSH_LINETILT_TABLE_UNIT_FWHM
#define XSH_LINETILT_TABLE_COLNAME_FLUX
#define XSH_LINETILT_TABLE_UNIT_GAUSSY
#define XSH_LINETILT_TABLE_COLNAME_TILT
#define XSH_LINETILT_TABLE_COLNAME_FLAG
#define XSH_LINETILT_TABLE_UNIT_CENPOSX
#define XSH_LINETILT_TABLE_UNIT_CENPOSY
#define XSH_LINETILT_TABLE_NB_COL
#define XSH_LINETILT_TABLE_COLNAME_WAVELENGTH
#define XSH_LINETILT_TABLE_UNIT_NAME
#define XSH_LINETILT_TABLE_COLNAME_CENPOSY
#define XSH_LINETILT_TABLE_COLNAME_NAME
#define XSH_LINETILT_TABLE_UNIT_SPECRES
#define XSH_LINETILT_TABLE_COLNAME_CENPOSX
#define XSH_LINETILT_TABLE_COLNAME_SPECRES
#define XSH_LINETILT_TABLE_UNIT_CHISQ
#define XSH_LINETILT_TABLE_UNIT_ORDER
#define XSH_LINETILT_TABLE_UNIT_INTENSITY
#define XSH_LINETILT_TABLE_UNIT_TILT
#define XSH_LINETILT_TABLE_UNIT_WAVELENGTH
#define XSH_LINETILT_TABLE_COLNAME_ORDER
#define XSH_LINETILT_TABLE_UNIT_FLUX
#define XSH_LINETILT_TABLE_COLNAME_FWHM
#define XSH_LINETILT_TABLE_UNIT_FLAG
#define XSH_LINETILT_TABLE_UNIT_SHIFTY
#define XSH_LINETILT_TABLE_COLNAME_INTENSITY
#define XSH_LINETILT_TABLE_COLNAME_TILTY
#define XSH_LINETILT_TABLE_UNIT_TILTY
double kappa
Definition: xsh_detmon_lg.c:81
int niter
Definition: xsh_detmon_lg.c:82
int order
Definition: xsh_detmon_lg.c:80
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
Definition: xsh_dfs.c:930
#define XSH_TILT_TAB
Definition: xsh_dfs.h:571
#define XSH_GET_TAG_FROM_MODE(TAG, instr)
Definition: xsh_dfs.h:1594
#define QC_WAVECAL_NLININT
Definition: xsh_pfits_qc.h:198
#define QC_WAVECAL_DIFFYSTD
Definition: xsh_pfits_qc.h:193
#define QC_WAVECAL_DIFFYMED
Definition: xsh_pfits_qc.h:192
#define QC_WAVECAL_FWHMAVG
Definition: xsh_pfits_qc.h:197
#define QC_WAVECAL_FWHMRMS
Definition: xsh_pfits_qc.h:196
#define QC_WAVECAL_LININT_NORM
Definition: xsh_pfits_qc.h:200
#define QC_WAVECAL_DIFFYAVG
Definition: xsh_pfits_qc.h:191
#define XSH_FREE(POINTER)
Definition: xsh_utils.h:92
#define XSH_CALLOC(POINTER, TYPE, SIZE)
Definition: xsh_utils.h:56
#define XSH_TABLE_LOAD(TABLE, NAME)
#define XSH_TABLE_FREE(TABLE)