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
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035 #include <string.h>
00036
00037
00038 #include <cpl.h>
00039
00040
00041 #include <irplib_utils.h>
00042
00043 #include <sinfo_tpl_utils.h>
00044 #include <sinfo_pfits.h>
00045 #include <sinfo_tpl_dfs.h>
00046 #include <sinfo_key_names.h>
00047 #include <sinfo_pro_types.h>
00048 #include <sinfo_functions.h>
00049 #include <sinfo_msg.h>
00050 #include <sinfo_error.h>
00051 #include <sinfo_utils_wrappers.h>
00052
00053
00054
00055
00056
00057 static int sinfo_utl_table_ex_create(cpl_plugin *) ;
00058 static int sinfo_utl_table_ex_exec(cpl_plugin *) ;
00059 static int sinfo_utl_table_ex_destroy(cpl_plugin *) ;
00060 static int sinfo_utl_table_ex(cpl_parameterlist *, cpl_frameset *) ;
00061
00062
00063
00064
00065
00066 static char sinfo_utl_table_ex_description[] =
00067 "This recipe produce a table,\n";
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 static char RECIPE_NAME[] = "sinfoni.sinfo_utl_table_ex";
00078 static char CLMN_NAME_SPECTRUM[] = "spectrum";
00079 static char CLMN_NAME_WAVELENGTH[] = "wavelength";
00080 static char CLMN_NAME_BKG_TOT[] = "bkg_tot";
00081 static char CLMN_NAME_COUNTS_BKG[] = "counts_bkg";
00082
00083
00084
00085
00089
00090
00092
00100
00101 int cpl_plugin_get_info(cpl_pluginlist * list)
00102 {
00103 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00104 cpl_plugin * plugin = &recipe->interface ;
00105
00106 cpl_plugin_init(plugin,
00107 CPL_PLUGIN_API,
00108 SINFONI_BINARY_VERSION,
00109 CPL_PLUGIN_TYPE_RECIPE,
00110 "sinfo_utl_table_ex",
00111 "Test example shows table manipulating utilities",
00112 sinfo_utl_table_ex_description,
00113 "Konstantin Mirny",
00114 "kmirny@eso.org",
00115 sinfo_get_license(),
00116 sinfo_utl_table_ex_create,
00117 sinfo_utl_table_ex_exec,
00118 sinfo_utl_table_ex_destroy) ;
00119
00120 cpl_pluginlist_append(list, plugin) ;
00121
00122 return 0;
00123 }
00124
00125
00134
00135 static int sinfo_utl_table_ex_create(cpl_plugin * plugin)
00136 {
00137 cpl_recipe * recipe ;
00138
00139
00140
00141 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00142 recipe = (cpl_recipe *)plugin ;
00143 else return -1 ;
00144 cpl_error_reset();
00145 irplib_reset();
00146
00147
00148 recipe->parameters = cpl_parameterlist_new() ;
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 return 0;
00167 }
00168
00169
00175
00176 static int sinfo_utl_table_ex_exec(cpl_plugin * plugin)
00177 {
00178 cpl_recipe * recipe ;
00179 int code=0;
00180 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00181
00182
00183 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00184 recipe = (cpl_recipe *)plugin ;
00185 else return -1 ;
00186 cpl_error_reset();
00187 irplib_reset();
00188 code = sinfo_utl_table_ex(recipe->parameters, recipe->frames) ;
00189
00190
00191 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00192
00193
00194 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00195 }
00196
00197 return code ;
00198 }
00199
00200
00206
00207 static int sinfo_utl_table_ex_destroy(cpl_plugin * plugin)
00208 {
00209 cpl_recipe * recipe ;
00210
00211
00212 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00213 recipe = (cpl_recipe *)plugin ;
00214 else return -1 ;
00215
00216 cpl_parameterlist_delete(recipe->parameters) ;
00217 return 0 ;
00218 }
00219
00220
00227
00228 static int
00229 sinfo_utl_table_ex( cpl_parameterlist * parlist,
00230 cpl_frameset * framelist)
00231 {
00232
00233 double range_min = 1.9;
00234 double range_max = 2.;
00236
00237 const char * name_o = NULL ;
00238 const char * sourceTableName = NULL;
00239
00240
00241 cpl_propertylist * plist = NULL ;
00242 cpl_frame * product_frame = NULL;
00243 int nrow = 0;
00244 cpl_table * tblSource = NULL;
00245 cpl_table * tblResult = NULL;
00246 float * pValues = NULL;
00247
00248 sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00249 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00250 ck0(sinfo_dfs_set_groups(framelist),"Cannot indentify RAW and CALIB frames");
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 check(plist=cpl_propertylist_new(),"Cannot create a Property List");
00263
00264
00265
00266
00267
00268 check(product_frame = cpl_frameset_get_first(framelist),"Cannot get product frame");
00269 check(sourceTableName = cpl_frame_get_filename(product_frame),"Cannot get source table name");
00270 check_nomsg(tblSource = cpl_table_load(sourceTableName, 1, 0));
00271
00272
00273 check(tblResult = cpl_table_duplicate(tblSource), "cannot duplicate table");
00274
00275 check_nomsg(nrow = cpl_table_get_nrow(tblResult));
00276 sinfo_msg("%d rows in the source table", nrow);
00277 if (nrow)
00278 {
00279 int i = 0;
00280 int m = 0;
00281 check_nomsg(pValues = cpl_table_get_data_float(tblResult, CLMN_NAME_WAVELENGTH));
00282 sinfo_msg("checking wavelenghts...");
00283 check(cpl_table_unselect_all(tblResult),"cannot unselect all");
00284 for (i = 0; i < nrow; ++i)
00285 {
00286 if ((*(pValues + i) < range_min) || (*(pValues + i) > range_max))
00287 {
00288
00289 check(cpl_table_select_row(tblResult, i), "Cannot select a row in a table");
00290 ++m;
00291 }
00292 }
00293 sinfo_msg("%d row(s) would be removed from the result", m);
00294
00295 check(cpl_table_erase_selected(tblResult),"Cannot delete selected rows from a table");
00296 }
00297
00298
00299 check(cpl_table_duplicate_column(tblResult,CLMN_NAME_SPECTRUM, tblResult, CLMN_NAME_BKG_TOT),"Unable to create new column in the table");
00300 check(cpl_table_add_columns(tblResult, CLMN_NAME_SPECTRUM, CLMN_NAME_COUNTS_BKG), "Error during sum the columns");
00301
00302
00303 name_o = "ima_res.fits" ;
00304
00305
00306 check_nomsg(product_frame = cpl_frame_new());
00307 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00308 check_nomsg(cpl_frame_set_tag(product_frame,"table_example" )) ;
00309 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
00310 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00311 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00312 "Error while initialising the product frame") ;
00313
00314
00315 check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
00316
00317 check(cpl_dfs_setup_product_header(plist,
00318 product_frame,
00319 framelist,
00320 parlist,
00321 "sinfo_utl_table_ex",
00322 "SINFONI",
00323 KEY_VALUE_HPRO_DID,NULL),
00324 "Problem in the product DFS-compliance") ;
00325
00326
00327
00328 cpl_table_dump(tblResult, 0, 3, stdout);
00329 check(cpl_table_save(tblResult,
00330 NULL, NULL,
00331 name_o,
00332 CPL_IO_DEFAULT), "Cannot save table");
00333
00334 sinfo_free_propertylist(&plist) ;
00335
00336 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
00337
00338
00339 cleanup:
00340
00341 sinfo_free_propertylist(&plist) ;
00342 cpl_table_delete(tblSource);
00343 cpl_table_delete(tblResult);
00344
00345
00346
00347
00348
00349 return ((cpl_error_get_code()) ? -1 : 0 );
00350
00351 }