00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00036
00037
00041
00042
00043
00044
00045 #include <xsh_data_shift_tab.h>
00046 #include <xsh_utils.h>
00047 #include <xsh_utils_table.h>
00048 #include <xsh_error.h>
00049 #include <xsh_msg.h>
00050 #include <xsh_pfits.h>
00051 #include <cpl.h>
00052 #include <xsh_drl.h>
00053 #include <math.h>
00054
00055
00056
00057
00058
00059
00066
00067 xsh_shift_tab* xsh_shift_tab_load( cpl_frame *frame, xsh_instrument *instr)
00068 {
00069 cpl_table *table = NULL;
00070 const char* tablename = NULL;
00071 xsh_shift_tab *result = NULL;
00072 XSH_MODE mode;
00073 double shift_cen=0, shift_up=0, shift_down=0;
00074
00075 XSH_ASSURE_NOT_NULL( frame);
00076 check( tablename = cpl_frame_get_filename( frame));
00077 XSH_TABLE_LOAD( table, tablename);
00078
00079
00080 XSH_CALLOC( result, xsh_shift_tab, 1);
00081
00082 check( mode = xsh_instrument_get_mode( instr));
00083
00084 result->is_ifu = ( mode == XSH_MODE_IFU);
00085
00086 if ( result->is_ifu){
00087 check( xsh_get_table_value( table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_DOWN,
00088 CPL_TYPE_DOUBLE, 0, &shift_down));
00089 check( xsh_get_table_value( table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_CEN,
00090 CPL_TYPE_DOUBLE, 0, &shift_cen));
00091 check( xsh_get_table_value( table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_UP,
00092 CPL_TYPE_DOUBLE, 0, &shift_up));
00093
00094 result->shift_y_cen = shift_cen;
00095 result->shift_y_down = shift_down;
00096 result->shift_y_up = shift_up;
00097 }
00098 else{
00099 check( xsh_get_table_value( table, XSH_SHIFT_TABLE_COLNAME_YSHIFT,
00100 CPL_TYPE_DOUBLE, 0, &shift_cen));
00101 result->shift_y = shift_cen;
00102 }
00103 check( result->header = cpl_propertylist_load( tablename, 0));
00104
00105 cleanup:
00106 if ( cpl_error_get_code() != CPL_ERROR_NONE){
00107 xsh_shift_tab_free( &result);
00108 }
00109 XSH_TABLE_FREE( table);
00110 return result;
00111 }
00112
00113
00114
00115
00122
00123 void xsh_shift_tab_free( xsh_shift_tab **tab)
00124 {
00125 if( tab && *tab) {
00126 xsh_free_propertylist(&((*tab)->header));
00127 cpl_free( *tab);
00128 *tab=NULL;
00129 }
00130
00131 }
00132
00133
00134
00135 cpl_frame * xsh_shift_tab_save(xsh_shift_tab *tab, const char * tag,const int clean_tmp )
00136 {
00137 cpl_frame * result = NULL ;
00138 cpl_table *table = NULL;
00139 cpl_propertylist *header = NULL;
00140 char filename[256];
00141
00142 XSH_ASSURE_NOT_NULL( tab ) ;
00143
00144 check( table = cpl_table_new( 1 ));
00145 if ( tab->is_ifu == 0 ) {
00146
00147
00148 XSH_TABLE_NEW_COL(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT,
00149 XSH_SHIFT_TABLE_UNIT_YSHIFT, CPL_TYPE_DOUBLE);
00150
00151 check(cpl_table_set_double(table,XSH_SHIFT_TABLE_COLNAME_YSHIFT,
00152 0, tab->shift_y));
00153 }
00154 else {
00155
00156 XSH_TABLE_NEW_COL(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_DOWN,
00157 XSH_SHIFT_TABLE_UNIT_YSHIFT_DOWN, CPL_TYPE_DOUBLE);
00158 XSH_TABLE_NEW_COL(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_CEN,
00159 XSH_SHIFT_TABLE_UNIT_YSHIFT_CEN, CPL_TYPE_DOUBLE);
00160 XSH_TABLE_NEW_COL(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_UP,
00161 XSH_SHIFT_TABLE_UNIT_YSHIFT_UP, CPL_TYPE_DOUBLE);
00162
00163 check(cpl_table_set_double(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_DOWN,
00164 0, tab->shift_y_down));
00165 check(cpl_table_set_double(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_CEN,
00166 0, tab->shift_y_cen));
00167 check(cpl_table_set_double(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_UP,
00168 0, tab->shift_y_up));
00169 }
00170
00171 header = tab->header;
00172
00173 check( xsh_pfits_set_pcatg( header, tag ) );
00174 sprintf(filename,"%s.fits",tag) ;
00175 check( cpl_table_save(table, header, NULL, filename, CPL_IO_DEFAULT));
00176
00177
00178 check(result=xsh_frame_product(filename,
00179 tag,
00180 CPL_FRAME_TYPE_TABLE,
00181 CPL_FRAME_GROUP_PRODUCT,
00182 CPL_FRAME_LEVEL_TEMPORARY));
00183
00184
00185 if(clean_tmp) {
00186 check (xsh_add_temporary_file( filename));
00187 }
00188 cleanup:
00189 if (cpl_error_get_code() != CPL_ERROR_NONE){
00190 xsh_free_frame(&result);
00191 }
00192
00193 XSH_TABLE_FREE( table);
00194 return result ;
00195
00196 }
00197
00198
00206 xsh_shift_tab * xsh_shift_tab_create( xsh_instrument * instrument )
00207 {
00208 xsh_shift_tab * result = NULL;
00209 XSH_MODE mode;
00210
00211 XSH_ASSURE_NOT_NULL( instrument ) ;
00212
00213 XSH_CALLOC( result, xsh_shift_tab, 1);
00214
00215 check (result->header = cpl_propertylist_new());
00216 check( mode = xsh_instrument_get_mode( instrument));
00217
00218 result->is_ifu = ( mode == XSH_MODE_IFU);
00219
00220 cleanup:
00221 return result ;
00222 }
00223