X-shooter Pipeline Reference Manual 3.8.15
xsh_subtract_sky_offset.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: 2012-03-19 13:43:18 $
23 * $Revision: 1.9 $
24 */
25
26#ifdef HAVE_CONFIG_H
27#include <config.h>
28#endif
29
30/*----------------------------------------------------------------------------*/
37/*----------------------------------------------------------------------------*/
40/*-----------------------------------------------------------------------------
41 Includes
42 -----------------------------------------------------------------------------*/
43
44#include <math.h>
45#include <xsh_drl.h>
46
47#include <xsh_badpixelmap.h>
48#include <xsh_data_pre.h>
49#include <xsh_data_order.h>
50#include <xsh_data_wavemap.h>
52#include <xsh_data_rec.h>
53#include <xsh_dfs.h>
54#include <xsh_pfits.h>
55#include <xsh_error.h>
56#include <xsh_msg.h>
57#include <xsh_fit.h>
58#include <xsh_badpixelmap.h>
59
60#include <cpl.h>
61
62/*-----------------------------------------------------------------------------
63 Functions prototypes
64 -----------------------------------------------------------------------------*/
65
66/*-----------------------------------------------------------------------------
67 Implementation
68 -----------------------------------------------------------------------------*/
69
81cpl_frameset * xsh_subtract_sky_offset( cpl_frameset * object_raws,
82 cpl_frameset * sky_raws,
83 int nraws,
85{
86 cpl_frameset *result = NULL;
87 char arm_name[16] ;
88 cpl_frameset * objects = NULL, * skys = NULL ;
89 int i ;
90
91 XSH_ASSURE_NOT_NULL( object_raws);
92 XSH_ASSURE_NOT_NULL( sky_raws);
94
95 /*Before anything else, order the frameset by date=obs */
96 check( objects = xsh_order_frameset_by_date( object_raws));
97 check( skys = xsh_order_frameset_by_date( sky_raws));
98
99 check( result = cpl_frameset_new());
100 sprintf( arm_name, "%s", xsh_instrument_arm_tostring( instrument));
101
102 /* For each pair OBJECT/SKY, subtract ==> OBJECT-SKY */
103 for( i = 0 ; i<nraws ; i ++ ) {
104 char a_b_name[256];
105 cpl_frame *a = NULL, *b = NULL;
106 cpl_frame *a_b = NULL ;
107
108 check(a = cpl_frameset_get_frame( objects, i));
109 check(b = cpl_frameset_get_frame( skys, i));
110
111 xsh_msg( "1-st pair: OBJECT='%s'", cpl_frame_get_filename( a));
112 xsh_msg( " SKY ='%s'", cpl_frame_get_filename( b));
113
114 sprintf( a_b_name ,"SKY_SUBTRACTED_OFFSET_%s_%d.fits",
115 arm_name, i);
116 /* The following function creates a new frame: as that is to be added
117 * on the newly created result frameset, there is no need to duplicate it
118 * when it will be inserted in it.
119 */
120 check( a_b = xsh_pre_frame_subtract( a, b, a_b_name, instrument,1));
121
122 // Why this ?
123 // save_pre_frame( a_b, instrument ) ;
124
125 check( cpl_frameset_insert( result, a_b));
126
127 }
128
129 xsh_msg_dbg_high( "Done OK" ) ;
130
131 cleanup:
132 xsh_free_frameset( &objects);
133 xsh_free_frameset( &skys);
134 return result ;
135
136}
137
138
static xsh_instrument * instrument
cpl_frame * xsh_pre_frame_subtract(cpl_frame *one, cpl_frame *two, const char *filename, xsh_instrument *instr, const int clean_tmp)
Subtract 2 frames (in XSH_PRE format) Just loads the 2 frames, subtract (xsh_pre_subtract) and save r...
#define check(COMMAND)
Definition: xsh_error.h:71
#define XSH_ASSURE_NOT_NULL(pointer)
Definition: xsh_error.h:99
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
#define xsh_msg(...)
Print a message on info level.
Definition: xsh_msg.h:121
#define xsh_msg_dbg_high(...)
Definition: xsh_msg.h:40
cpl_frameset * xsh_subtract_sky_offset(cpl_frameset *object_raws, cpl_frameset *sky_raws, int nraws, xsh_instrument *instrument)
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
Definition: xsh_utils.c:2254
cpl_frameset * xsh_order_frameset_by_date(cpl_frameset *frameset)
Order frameset by date.
Definition: xsh_utils.c:3306