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 }
00129 *tab=NULL;
00130 }
00131
00132
00133
00134 cpl_frame * xsh_shift_tab_save(xsh_shift_tab *tab, const char * tag )
00135 {
00136 cpl_frame * result = NULL ;
00137 cpl_table *table = NULL;
00138 cpl_propertylist *header = NULL;
00139 char filename[80];
00140
00141 XSH_ASSURE_NOT_NULL( tab ) ;
00142
00143 check( table = cpl_table_new( 1 ));
00144 if ( tab->is_ifu == 0 ) {
00145
00146
00147 XSH_TABLE_NEW_COL(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT,
00148 XSH_SHIFT_TABLE_UNIT_YSHIFT, CPL_TYPE_DOUBLE);
00149
00150 check(cpl_table_set_double(table,XSH_SHIFT_TABLE_COLNAME_YSHIFT,
00151 0, tab->shift_y));
00152 }
00153 else {
00154
00155 XSH_TABLE_NEW_COL(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_DOWN,
00156 XSH_SHIFT_TABLE_UNIT_YSHIFT_DOWN, CPL_TYPE_DOUBLE);
00157 XSH_TABLE_NEW_COL(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_CEN,
00158 XSH_SHIFT_TABLE_UNIT_YSHIFT_CEN, CPL_TYPE_DOUBLE);
00159 XSH_TABLE_NEW_COL(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_UP,
00160 XSH_SHIFT_TABLE_UNIT_YSHIFT_UP, CPL_TYPE_DOUBLE);
00161
00162 check(cpl_table_set_double(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_DOWN,
00163 0, tab->shift_y_down));
00164 check(cpl_table_set_double(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_CEN,
00165 0, tab->shift_y_cen));
00166 check(cpl_table_set_double(table, XSH_SHIFT_TABLE_COLNAME_YSHIFT_UP,
00167 0, tab->shift_y_up));
00168 }
00169
00170 header = tab->header;
00171
00172 check( xsh_pfits_set_pcatg( header, tag ) );
00173 sprintf(filename,"%s.fits",tag) ;
00174 check( cpl_table_save(table, header, NULL, filename, CPL_IO_DEFAULT));
00175
00176
00177 check(result=xsh_frame_product(filename,
00178 tag,
00179 CPL_FRAME_TYPE_TABLE,
00180 CPL_FRAME_GROUP_PRODUCT,
00181 CPL_FRAME_LEVEL_TEMPORARY));
00182
00183
00184 check (xsh_add_temporary_file( filename));
00185
00186 cleanup:
00187 if (cpl_error_get_code() != CPL_ERROR_NONE){
00188 xsh_free_frame(&result);
00189 }
00190
00191 XSH_TABLE_FREE( table);
00192 return result ;
00193
00194 }
00195
00196
00204 xsh_shift_tab * xsh_shift_tab_create( xsh_instrument * instrument )
00205 {
00206 xsh_shift_tab * result = NULL;
00207 XSH_MODE mode;
00208
00209 XSH_ASSURE_NOT_NULL( instrument ) ;
00210
00211 XSH_CALLOC( result, xsh_shift_tab, 1);
00212
00213 check (result->header = cpl_propertylist_new());
00214 check( mode = xsh_instrument_get_mode( instrument));
00215
00216 result->is_ifu = ( mode == XSH_MODE_IFU);
00217
00218 cleanup:
00219 return result ;
00220 }
00221