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 #ifdef HAVE_CONFIG_H
00027 #include <config.h>
00028 #endif
00029
00030
00035
00036
00040
00041
00042
00043
00044 #include <math.h>
00045 #include <xsh_dfs.h>
00046 #include <xsh_data_slice_offset.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
00053
00054
00055
00056
00057
00065
00066 xsh_slice_offset* xsh_slice_offset_create(void)
00067 {
00068 xsh_slice_offset* result = NULL;
00069
00070 XSH_CALLOC(result, xsh_slice_offset, 1);
00071
00072 XSH_NEW_PROPERTYLIST(result->header);
00073
00074 cleanup:
00075 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00076 xsh_slice_offset_free( &result);
00077 }
00078 return result;
00079 }
00080
00081
00082
00092
00093 xsh_slice_offset* xsh_slice_offset_load(cpl_frame* frame){
00094 cpl_table *table = NULL;
00095 cpl_propertylist* header = NULL;
00096 const char* tablename = NULL;
00097 xsh_slice_offset *result = NULL;
00098
00099
00100 XSH_ASSURE_NOT_NULL(frame);
00101
00102
00103 check(tablename = cpl_frame_get_filename(frame));
00104
00105 XSH_TABLE_LOAD( table, tablename);
00106
00107 check( header = cpl_propertylist_load(tablename,0));
00108
00109 check(result = xsh_slice_offset_create());
00110
00111 check( cpl_propertylist_append(result->header, header));
00112
00113 check( xsh_get_table_value(table, XSH_SLICE_OFFSET_TABLE_COLNAME_CEN_UP,
00114 CPL_TYPE_DOUBLE, 0, &(result->cen_up)));
00115 check( xsh_get_table_value(table, XSH_SLICE_OFFSET_TABLE_COLNAME_CEN_DOWN,
00116 CPL_TYPE_DOUBLE, 0, &(result->cen_down)));
00117
00118 cleanup:
00119 if (cpl_error_get_code () != CPL_ERROR_NONE) {
00120 xsh_error_msg("can't load frame %s",cpl_frame_get_filename(frame));
00121 xsh_slice_offset_free(&result);
00122 }
00123 xsh_free_propertylist( &header);
00124 XSH_TABLE_FREE( table);
00125 return result;
00126 }
00127
00128
00129
00136
00137 void xsh_slice_offset_free( xsh_slice_offset** list)
00138 {
00139 if (list && *list){
00140 xsh_free_propertylist( &((*list)->header));
00141 cpl_free( *list);
00142 *list = NULL;
00143 }
00144 }
00145
00146
00147
00148
00157
00158 cpl_propertylist* xsh_slice_offset_get_header(xsh_slice_offset *list)
00159 {
00160 cpl_propertylist *res = NULL;
00161
00162 XSH_ASSURE_NOT_NULL( list);
00163 res = list->header;
00164 cleanup:
00165 return res;
00166 }
00167
00168
00169
00181
00182 cpl_frame* xsh_slice_offset_save(xsh_slice_offset *list,
00183 const char* filename, xsh_instrument *instrument)
00184 {
00185 cpl_table *table = NULL;
00186 cpl_frame *result = NULL;
00187 const char *tag = NULL ;
00188
00189
00190 XSH_ASSURE_NOT_NULL( list);
00191 XSH_ASSURE_NOT_NULL( filename);
00192 XSH_ASSURE_NOT_NULL( instrument);
00193
00194
00195 check( table = cpl_table_new( 1));
00196
00197
00198 XSH_TABLE_NEW_COL( table, XSH_SLICE_OFFSET_TABLE_COLNAME_CEN_UP,
00199 XSH_SLICE_OFFSET_TABLE_UNIT_CEN_UP, CPL_TYPE_DOUBLE);
00200 XSH_TABLE_NEW_COL( table, XSH_SLICE_OFFSET_TABLE_COLNAME_CEN_DOWN,
00201 XSH_SLICE_OFFSET_TABLE_UNIT_CEN_DOWN, CPL_TYPE_DOUBLE);
00202
00203 check( cpl_table_set_double( table, XSH_SLICE_OFFSET_TABLE_COLNAME_CEN_UP,
00204 0, list->cen_up));
00205 check( cpl_table_set_double( table, XSH_SLICE_OFFSET_TABLE_COLNAME_CEN_DOWN,
00206 0, list->cen_down));
00207
00208
00209 check( cpl_table_save( table, list->header, NULL, filename,
00210 CPL_IO_DEFAULT));
00211
00212
00213 tag = XSH_GET_TAG_FROM_ARM( XSH_SLICE_OFFSET, instrument);
00214
00215 check( result = xsh_frame_product( filename, tag,
00216 CPL_FRAME_TYPE_TABLE, CPL_FRAME_GROUP_PRODUCT,
00217 CPL_FRAME_LEVEL_TEMPORARY));
00218
00219 cleanup:
00220 XSH_TABLE_FREE(table);
00221 return result ;
00222 }
00223
00224