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 #include <cxslist.h>
00033
00034 #include <cpl_recipe.h>
00035 #include <cpl_plugininfo.h>
00036 #include <cpl_parameterlist.h>
00037 #include <cpl_frameset.h>
00038 #include <cpl_msg.h>
00039
00040 #include "gialias.h"
00041 #include "giframe.h"
00042 #include "gifibers.h"
00043 #include "gifiberutils.h"
00044 #include "gislitgeometry.h"
00045 #include "gipsfdata.h"
00046 #include "gibias.h"
00047 #include "gidark.h"
00048 #include "giextract.h"
00049 #include "giflat.h"
00050 #include "gitransmission.h"
00051 #include "girebinning.h"
00052 #include "gireconstruct.h"
00053 #include "gimessages.h"
00054 #include "gierror.h"
00055 #include "giutils.h"
00056
00057
00058 static cxint gistandard(cpl_parameterlist*, cpl_frameset*);
00059
00060
00061
00062
00063
00064
00065
00066 static cxint
00067 gistandard_create(cpl_plugin* plugin)
00068 {
00069
00070 cpl_recipe* recipe = (cpl_recipe*)plugin;
00071
00072
00073 giraffe_error_init();
00074
00075
00076
00077
00078
00079
00080
00081
00082 recipe->parameters = cpl_parameterlist_new();
00083 cx_assert(recipe->parameters != NULL);
00084
00085
00086
00087
00088
00089
00090
00091
00092 giraffe_bias_config_add(recipe->parameters);
00093
00094
00095
00096
00097
00098
00099
00100 giraffe_extract_config_add(recipe->parameters);
00101
00102
00103
00104 giraffe_flat_config_add(recipe->parameters);
00105
00106
00107
00108 giraffe_rebin_config_add(recipe->parameters);
00109
00110
00111
00112 giraffe_reconstruct_config_add(recipe->parameters);
00113
00114 return 0;
00115
00116 }
00117
00118
00119
00120
00121
00122
00123 static cxint
00124 gistandard_exec(cpl_plugin* plugin)
00125 {
00126
00127 cpl_recipe* recipe = (cpl_recipe*)plugin;
00128
00129
00130 cx_assert(recipe->parameters != NULL);
00131 cx_assert(recipe->frames != NULL);
00132
00133 return gistandard(recipe->parameters, recipe->frames);
00134
00135 }
00136
00137
00138 static cxint
00139 gistandard_destroy(cpl_plugin* plugin)
00140 {
00141
00142 cpl_recipe* recipe = (cpl_recipe*)plugin;
00143
00144
00145
00146
00147
00148
00149
00150
00151 cpl_parameterlist_delete(recipe->parameters);
00152
00153 giraffe_error_clear();
00154
00155 return 0;
00156
00157 }
00158
00159
00160
00161
00162
00163
00164 static cxint
00165 gistandard(cpl_parameterlist* config, cpl_frameset* set)
00166 {
00167
00168 const cxchar* const _id = "gistandard";
00169
00170
00171 const cxchar* filename = NULL;
00172
00173 cxint status = 0;
00174
00175 cxlong i;
00176 cxlong nstandard = 0;
00177
00178 cxdouble exptime = 0.;
00179
00180 cx_slist* slist = NULL;
00181
00182 cpl_propertylist* properties = NULL;
00183
00184 cpl_matrix* biasareas = NULL;
00185
00186 cpl_frame* standard_frame = NULL;
00187 cpl_frame* mbias_frame = NULL;
00188 cpl_frame* mdark_frame = NULL;
00189 cpl_frame* bpixel_frame = NULL;
00190 cpl_frame* slight_frame = NULL;
00191 cpl_frame* locy_frame = NULL;
00192 cpl_frame* locw_frame = NULL;
00193 cpl_frame* psfdata_frame = NULL;
00194 cpl_frame* grating_frame = NULL;
00195 cpl_frame* slit_frame = NULL;
00196 cpl_frame* wcal_frame = NULL;
00197 cpl_frame* rstandard_frame = NULL;
00198 cpl_frame* sext_frame = NULL;
00199 cpl_frame* rbin_frame = NULL;
00200
00201 GiImage* mbias = NULL;
00202 GiImage* mdark = NULL;
00203 GiImage* bpixel = NULL;
00204 GiImage* slight = NULL;
00205 GiImage* sstandard = NULL;
00206 GiImage* rstandard = NULL;
00207
00208 GiTable* fibers = NULL;
00209 GiTable* slitgeometry = NULL;
00210 GiTable* grating = NULL;
00211 GiTable* wcalcoeff = NULL;
00212
00213 GiLocalization* localization = NULL;
00214 GiExtraction* extraction = NULL;
00215 GiRebinning* rebinning = NULL;
00216
00217 GiBiasConfig* bias_config = NULL;
00218 GiExtractConfig* extract_config = NULL;
00219 GiFlatConfig* flat_config = NULL;
00220 GiRebinConfig* rebin_config = NULL;
00221
00222 GiInstrumentMode mode;
00223
00224 GiRecipeInfo info = {(cxchar*)_id, 1, NULL};
00225
00226 GiGroupInfo groups[] = {
00227 {GIFRAME_STANDARD, CPL_FRAME_GROUP_RAW},
00228 {GIFRAME_BADPIXEL_MAP, CPL_FRAME_GROUP_CALIB},
00229 {GIFRAME_BIAS_MASTER, CPL_FRAME_GROUP_CALIB},
00230 {GIFRAME_DARK_MASTER, CPL_FRAME_GROUP_CALIB},
00231 {GIFRAME_SCATTERED_LIGHT_MODEL, CPL_FRAME_GROUP_CALIB},
00232 {GIFRAME_LOCALIZATION_CENTROID, CPL_FRAME_GROUP_CALIB},
00233 {GIFRAME_LOCALIZATION_WIDTH, CPL_FRAME_GROUP_CALIB},
00234 {GIFRAME_PSF_CENTROID, CPL_FRAME_GROUP_CALIB},
00235 {GIFRAME_PSF_WIDTH, CPL_FRAME_GROUP_CALIB},
00236 {GIFRAME_PSF_DATA, CPL_FRAME_GROUP_CALIB},
00237 {GIFRAME_WAVELENGTH_SOLUTION, CPL_FRAME_GROUP_CALIB},
00238 {GIFRAME_SLITSETUP, CPL_FRAME_GROUP_CALIB},
00239 {GIFRAME_SLITMASTER, CPL_FRAME_GROUP_CALIB},
00240 {GIFRAME_GRATING, CPL_FRAME_GROUP_CALIB},
00241 {NULL, CPL_FRAME_GROUP_NONE}
00242 };
00243
00244
00245
00246 if (!config) {
00247 cpl_msg_error(_id, "Invalid parameter list! Aborting ...");
00248 return 1;
00249 }
00250
00251 if (!set) {
00252 cpl_msg_error(_id, "Invalid frame set! Aborting ...");
00253 return 1;
00254 }
00255
00256 status = giraffe_frameset_set_groups(set, groups);
00257
00258 if (status != 0) {
00259 cpl_msg_error(_id, "Setting frame group information failed!");
00260 return 1;
00261 }
00262
00263
00264
00265
00266
00267
00268 nstandard = cpl_frameset_count_tags(set, GIFRAME_STANDARD);
00269
00270 if (nstandard < 1) {
00271 cpl_msg_error(_id, "Too few (%ld) raw frames (%s) present in "
00272 "frame set! Aborting ...", nstandard, GIFRAME_STANDARD);
00273 return 1;
00274 }
00275
00276 locy_frame = cpl_frameset_find(set, GIFRAME_PSF_CENTROID);
00277
00278 if (locy_frame == NULL) {
00279
00280 locy_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_CENTROID);
00281
00282 if (locy_frame == NULL) {
00283 cpl_msg_info(_id, "No master localization (centroid position) "
00284 "present in frame set. Aborting ...");
00285 return 1;
00286 }
00287
00288 }
00289
00290 locw_frame = cpl_frameset_find(set, GIFRAME_PSF_WIDTH);
00291
00292 if (locw_frame == NULL) {
00293
00294 locw_frame = cpl_frameset_find(set, GIFRAME_LOCALIZATION_WIDTH);
00295
00296 if (locw_frame == NULL) {
00297 cpl_msg_info(_id, "No master localization (spectrum width) "
00298 "present in frame set. Aborting ...");
00299 return 1;
00300 }
00301
00302 }
00303
00304 grating_frame = cpl_frameset_find(set, GIFRAME_GRATING);
00305
00306 if (!grating_frame) {
00307 cpl_msg_error(_id, "No grating data present in frame set. "
00308 "Aborting ...");
00309 return 1;
00310 }
00311
00312 slit_frame = giraffe_get_slitgeometry(set);
00313
00314 if (!slit_frame) {
00315 cpl_msg_error(_id, "No slit geometry present in frame set. "
00316 "Aborting ...");
00317 return 1;
00318 }
00319
00320 wcal_frame = cpl_frameset_find(set, GIFRAME_WAVELENGTH_SOLUTION);
00321
00322 if (!wcal_frame) {
00323 cpl_msg_error(_id, "No dispersion solution present in frame set. "
00324 "Aborting ...");
00325 return 1;
00326 }
00327
00328 bpixel_frame = cpl_frameset_find(set, GIFRAME_BADPIXEL_MAP);
00329
00330 if (!bpixel_frame) {
00331 cpl_msg_info(_id, "No bad pixel map present in frame set.");
00332 }
00333
00334 mbias_frame = cpl_frameset_find(set, GIFRAME_BIAS_MASTER);
00335
00336 if (!mbias_frame) {
00337 cpl_msg_info(_id, "No master bias present in frame set.");
00338 }
00339
00340 mdark_frame = cpl_frameset_find(set, GIFRAME_DARK_MASTER);
00341
00342 if (!mdark_frame) {
00343 cpl_msg_info(_id, "No master dark present in frame set.");
00344 }
00345
00346 slight_frame = cpl_frameset_find(set, GIFRAME_SCATTERED_LIGHT_MODEL);
00347
00348 if (!slight_frame) {
00349 cpl_msg_info(_id, "No scattered light model present in frame set.");
00350 }
00351
00352 psfdata_frame = cpl_frameset_find(set, GIFRAME_PSF_DATA);
00353
00354 if (!psfdata_frame) {
00355 cpl_msg_info(_id, "No PSF profile parameters present in frame set.");
00356 }
00357
00358
00359
00360
00361
00362
00363 slist = cx_slist_new();
00364
00365 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
00366
00367 for (i = 0; i < nstandard; i++) {
00368
00369 filename = cpl_frame_get_filename(standard_frame);
00370
00371 GiImage* raw = giraffe_image_new(CPL_TYPE_DOUBLE);
00372
00373
00374 status = giraffe_image_load(raw, filename, 0);
00375
00376 if (status) {
00377 cpl_msg_error(_id, "Cannot load raw standard frame from '%s'. "
00378 "Aborting ...", filename);
00379
00380 cx_slist_destroy(slist, (cx_free_func) giraffe_image_delete);
00381
00382 return 1;
00383 }
00384
00385 cx_slist_push_back(slist, raw);
00386
00387 standard_frame = cpl_frameset_find(set, NULL);
00388
00389 }
00390
00391 nstandard = (cxint)cx_slist_size(slist);
00392 sstandard = cx_slist_pop_front(slist);
00393
00394 properties = giraffe_image_get_properties(sstandard);
00395 cx_assert(properties != NULL);
00396
00397 if (nstandard > 1) {
00398
00399
00400
00401
00402
00403
00404 cpl_msg_info(_id, "Averaging standard star observations ...");
00405
00406 exptime = cpl_propertylist_get_double(properties, GIALIAS_EXPTIME);
00407
00408 for (i = 1; i < nstandard; i++) {
00409
00410 cpl_propertylist* _properties;
00411
00412 GiImage* standard = cx_slist_pop_front(slist);
00413
00414
00415 cpl_image_add(giraffe_image_get(sstandard),
00416 giraffe_image_get(standard));
00417
00418 _properties = giraffe_image_get_properties(standard);
00419 cx_assert(_properties != NULL);
00420
00421 exptime += cpl_propertylist_get_double(_properties,
00422 GIALIAS_EXPTIME);
00423
00424 giraffe_image_delete(standard);
00425
00426 }
00427
00428 cpl_image_divide_scalar(giraffe_image_get(sstandard), nstandard);
00429 }
00430
00431 cx_assert(cx_slist_empty(slist));
00432 cx_slist_delete(slist);
00433 slist = NULL;
00434
00435
00436 if (nstandard > 1) {
00437
00438
00439
00440
00441
00442 cpl_msg_info(_id, "Updating stacked standard star image "
00443 "properties ...");
00444
00445 cpl_propertylist_set_double(properties, GIALIAS_EXPTIME, exptime / nstandard);
00446
00447 cpl_propertylist_append_double(properties, GIALIAS_EXPTTOT, exptime);
00448 cpl_propertylist_set_comment(properties, GIALIAS_EXPTTOT, "Total exposure "
00449 "time of all frames combined");
00450
00451 cpl_propertylist_append_int(properties, GIALIAS_DATANCOM, nstandard);
00452 cpl_propertylist_set_comment(properties, GIALIAS_DATANCOM, "Number of "
00453 "frames combined");
00454
00455 cpl_propertylist_erase(properties, GIALIAS_TPLEXPNO);
00456
00457 }
00458
00459
00460
00461
00462
00463
00464 bias_config = giraffe_bias_config_create(config);
00465
00466
00467
00468
00469
00470 if (strcmp(bias_config->areas, "None")) {
00471
00472 cpl_msg_warning(_id, "User defined bias areas are not yet "
00473 "supported. Using image pre- and overscan areas!");
00474
00475 biasareas = NULL;
00476
00477 }
00478
00479
00480 if (bias_config->method == GIBIAS_METHOD_MASTER ||
00481 bias_config->method == GIBIAS_METHOD_ZMASTER) {
00482
00483 if (!mbias_frame) {
00484 cpl_msg_error(_id, "Missing master bias frame! Selected bias "
00485 "removal method requires a master bias frame!");
00486
00487 if (biasareas) {
00488 cpl_matrix_delete(biasareas);
00489 biasareas = NULL;
00490 }
00491
00492 giraffe_bias_config_destroy(bias_config);
00493 giraffe_image_delete(sstandard);
00494
00495 return 1;
00496 }
00497 else {
00498 filename = cpl_frame_get_filename(mbias_frame);
00499
00500
00501 mbias = giraffe_image_new(CPL_TYPE_DOUBLE);
00502 status = giraffe_image_load(mbias, filename, 0);
00503
00504 if (status) {
00505 cpl_msg_error(_id, "Cannot load master bias from '%s'. "
00506 "Aborting ...", filename);
00507
00508 if (biasareas) {
00509 cpl_matrix_delete(biasareas);
00510 biasareas = NULL;
00511 }
00512
00513 giraffe_bias_config_destroy(bias_config);
00514 giraffe_image_delete(sstandard);
00515
00516 return 1;
00517 }
00518 }
00519 }
00520
00521
00522
00523
00524
00525
00526 if (bpixel_frame) {
00527
00528 filename = cpl_frame_get_filename(bpixel_frame);
00529
00530
00531 bpixel = giraffe_image_new(CPL_TYPE_INT);
00532 status = giraffe_image_load(bpixel, filename, 0);
00533
00534 if (status) {
00535 cpl_msg_error(_id, "Cannot load bad pixel map from '%s'. "
00536 "Aborting ...", filename);
00537
00538 giraffe_image_delete(bpixel);
00539 bpixel = NULL;
00540
00541 if (biasareas) {
00542 cpl_matrix_delete(biasareas);
00543 biasareas = NULL;
00544 }
00545
00546 if (mbias != NULL) {
00547 giraffe_image_delete(mbias);
00548 mbias = NULL;
00549 }
00550
00551 giraffe_bias_config_destroy(bias_config);
00552 bias_config = NULL;
00553
00554 giraffe_image_delete(sstandard);
00555 sstandard = NULL;
00556
00557 return 1;
00558 }
00559
00560 }
00561
00562
00563
00564
00565
00566
00567 rstandard = giraffe_image_new(CPL_TYPE_DOUBLE);
00568
00569 status = giraffe_bias_remove(rstandard, sstandard, mbias, bpixel, biasareas,
00570 bias_config);
00571
00572 giraffe_image_delete(sstandard);
00573
00574 if (mbias) {
00575 giraffe_image_delete(mbias);
00576 mbias = NULL;
00577 }
00578
00579 if (biasareas != NULL) {
00580 cpl_matrix_delete(biasareas);
00581 biasareas = NULL;
00582 }
00583
00584 giraffe_bias_config_destroy(bias_config);
00585
00586 if (status) {
00587 cpl_msg_error(_id, "Bias removal failed. Aborting ...");
00588
00589 giraffe_image_delete(rstandard);
00590 rstandard = NULL;
00591
00592 if (bpixel != NULL) {
00593 giraffe_image_delete(bpixel);
00594 bpixel = NULL;
00595 }
00596
00597 return 1;
00598 }
00599
00600
00601
00602
00603
00604
00605
00606 if (mdark_frame) {
00607
00608 GiDarkConfig dark_config = {GIDARK_METHOD_ZMASTER, 0.};
00609
00610
00611 cpl_msg_info(_id, "Correcting for dark current ...");
00612
00613 filename = cpl_frame_get_filename(mdark_frame);
00614
00615 mdark = giraffe_image_new(CPL_TYPE_DOUBLE);
00616 status = giraffe_image_load(mdark, filename, 0);
00617
00618 if (status != 0) {
00619 cpl_msg_error(_id, "Cannot load master dark from '%s'. "
00620 "Aborting ...", filename);
00621
00622 giraffe_image_delete(rstandard);
00623 rstandard = NULL;
00624
00625 if (bpixel != NULL) {
00626 giraffe_image_delete(bpixel);
00627 bpixel = NULL;
00628 }
00629
00630 return 1;
00631 }
00632
00633 status = giraffe_subtract_dark(rstandard, mdark, bpixel, NULL,
00634 &dark_config);
00635
00636 if (status != 0) {
00637 cpl_msg_error(_id, "Dark subtraction failed! Aborting ...");
00638
00639 giraffe_image_delete(mdark);
00640 mdark = NULL;
00641
00642 giraffe_image_delete(rstandard);
00643 rstandard = NULL;
00644
00645 if (bpixel != NULL) {
00646 giraffe_image_delete(bpixel);
00647 bpixel = NULL;
00648 }
00649
00650 return 1;
00651 }
00652
00653 giraffe_image_delete(mdark);
00654 mdark = NULL;
00655
00656 }
00657
00658
00659
00660
00661
00662
00663
00664 cpl_msg_info(_id, "Writing pre-processed standard star image ...");
00665
00666 giraffe_image_add_info(rstandard, &info, set);
00667
00668 rstandard_frame = giraffe_frame_create_image(rstandard,
00669 GIFRAME_STANDARD_REDUCED,
00670 CPL_FRAME_LEVEL_INTERMEDIATE,
00671 TRUE, TRUE);
00672
00673 if (rstandard_frame == NULL) {
00674 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
00675
00676 giraffe_image_delete(rstandard);
00677
00678 return 1;
00679 }
00680
00681 cpl_frameset_insert(set, rstandard_frame);
00682
00683
00684
00685
00686
00687
00688 standard_frame = cpl_frameset_find(set, GIFRAME_STANDARD);
00689
00690 cpl_msg_info(_id, "Building fiber setup for frame '%s'.",
00691 cpl_frame_get_filename(standard_frame));
00692
00693 fibers = giraffe_fibers_setup(standard_frame, locy_frame);
00694
00695 if (!fibers) {
00696 cpl_msg_error(_id, "Cannot create fiber setup for frame '%s'! "
00697 "Aborting ...", cpl_frame_get_filename(standard_frame));
00698
00699 if (bpixel) {
00700 giraffe_image_delete(bpixel);
00701 bpixel = NULL;
00702 }
00703
00704 giraffe_image_delete(rstandard);
00705
00706 return 1;
00707 }
00708
00709 cpl_msg_info(_id, "Fiber reference setup taken from localization "
00710 "frame '%s'.", cpl_frame_get_filename(locy_frame));
00711
00712
00713
00714
00715
00716
00717 localization = giraffe_localization_new();
00718
00719 filename = cpl_frame_get_filename(locy_frame);
00720 status = 0;
00721
00722 localization->locy = giraffe_image_new(CPL_TYPE_DOUBLE);
00723 status = giraffe_image_load(localization->locy, filename, 0);
00724
00725 if (status) {
00726 cpl_msg_error(_id, "Cannot load localization (centroid "
00727 "position) frame from '%s'. Aborting ...",
00728 filename);
00729
00730 giraffe_localization_destroy(localization);
00731
00732 if (bpixel) {
00733 giraffe_image_delete(bpixel);
00734 bpixel = NULL;
00735 }
00736
00737 giraffe_table_delete(fibers);
00738 giraffe_image_delete(rstandard);
00739
00740 return 1;
00741 }
00742
00743
00744 filename = cpl_frame_get_filename(locw_frame);
00745 status = 0;
00746
00747 localization->locw = giraffe_image_new(CPL_TYPE_DOUBLE);
00748 status = giraffe_image_load(localization->locw, filename, 0);
00749
00750 if (status) {
00751 cpl_msg_error(_id, "Cannot load localization (spectrum width) "
00752 "frame from '%s'. Aborting ...", filename);
00753
00754 giraffe_localization_destroy(localization);
00755
00756 if (bpixel) {
00757 giraffe_image_delete(bpixel);
00758 bpixel = NULL;
00759 }
00760
00761 giraffe_table_delete(fibers);
00762 giraffe_image_delete(rstandard);
00763
00764 return 1;
00765 }
00766
00767
00768
00769
00770
00771
00772 if (slight_frame) {
00773
00774 filename = cpl_frame_get_filename(slight_frame);
00775
00776
00777 slight = giraffe_image_new(CPL_TYPE_DOUBLE);
00778 status = giraffe_image_load(slight, filename, 0);
00779
00780 if (status) {
00781 cpl_msg_error(_id, "Cannot load scattered light model from '%s'. "
00782 "Aborting ...", filename);
00783
00784 giraffe_image_delete(slight);
00785
00786 giraffe_localization_destroy(localization);
00787
00788 if (bpixel) {
00789 giraffe_image_delete(bpixel);
00790 bpixel = NULL;
00791 }
00792
00793 giraffe_table_delete(fibers);
00794 giraffe_image_delete(rstandard);
00795
00796 return 1;
00797
00798 }
00799
00800 }
00801
00802
00803 extract_config = giraffe_extract_config_create(config);
00804
00805 if (extract_config->emethod == GIEXTRACT_OPTIMAL) {
00806
00807 if (psfdata_frame == NULL) {
00808
00809 cpl_msg_error(_id, "Optimal spectrum extraction requires PSF "
00810 "profile data. Aborting ...");
00811
00812 giraffe_extract_config_destroy(extract_config);
00813 extract_config = NULL;
00814
00815 if (slight != NULL) {
00816 giraffe_image_delete(slight);
00817 slight = NULL;
00818 }
00819
00820 giraffe_localization_destroy(localization);
00821 localization = NULL;
00822
00823 if (bpixel) {
00824 giraffe_image_delete(bpixel);
00825 bpixel = NULL;
00826 }
00827
00828 giraffe_table_delete(fibers);
00829 fibers = NULL;
00830
00831 giraffe_image_delete(rstandard);
00832 rstandard = NULL;
00833
00834 return 1;
00835
00836 }
00837 else {
00838
00839 filename = cpl_frame_get_filename(psfdata_frame);
00840 status = 0;
00841
00842 localization->psf = giraffe_psfdata_new();
00843 status = giraffe_psfdata_load(localization->psf, filename);
00844
00845 if (status) {
00846 cpl_msg_error(_id, "Cannot load PSF profile data frame from "
00847 "'%s'. Aborting ...", filename);
00848
00849 giraffe_extract_config_destroy(extract_config);
00850 extract_config = NULL;
00851
00852 if (slight != NULL) {
00853 giraffe_image_delete(slight);
00854 slight = NULL;
00855 }
00856
00857 giraffe_localization_destroy(localization);
00858 localization = NULL;
00859
00860 if (bpixel) {
00861 giraffe_image_delete(bpixel);
00862 bpixel = NULL;
00863 }
00864
00865 giraffe_table_delete(fibers);
00866 fibers = NULL;
00867
00868 giraffe_image_delete(rstandard);
00869 rstandard = NULL;
00870
00871 return 1;
00872
00873 }
00874
00875 }
00876
00877 }
00878
00879
00880 extraction = giraffe_extraction_new();
00881
00882 status = giraffe_extract_spectra(extraction, rstandard, fibers,
00883 localization, bpixel, slight,
00884 extract_config);
00885
00886 if (status) {
00887 cpl_msg_error(_id, "Spectrum extraction failed! Aborting ...");
00888
00889 giraffe_extraction_destroy(extraction);
00890 giraffe_extract_config_destroy(extract_config);
00891
00892 giraffe_image_delete(slight);
00893
00894 giraffe_localization_destroy(localization);
00895
00896 if (bpixel) {
00897 giraffe_image_delete(bpixel);
00898 bpixel = NULL;
00899 }
00900
00901 giraffe_table_delete(fibers);
00902 giraffe_image_delete(rstandard);
00903
00904 return 1;
00905 }
00906
00907 giraffe_image_delete(slight);
00908 slight = NULL;
00909
00910 if (bpixel) {
00911 giraffe_image_delete(bpixel);
00912 bpixel = NULL;
00913 }
00914
00915 giraffe_image_delete(rstandard);
00916 rstandard = NULL;
00917
00918 giraffe_extract_config_destroy(extract_config);
00919
00920
00921
00922
00923
00924
00925 flat_config = giraffe_flat_config_create(config);
00926
00927 if (flat_config->load == TRUE) {
00928
00929 cpl_frame* flat_frame = NULL;
00930
00931 GiImage* flat = NULL;
00932
00933
00934 flat_frame = cpl_frameset_find(set, GIFRAME_FIBER_FLAT_EXTSPECTRA);
00935
00936 if (flat_frame == NULL) {
00937 cpl_msg_error(_id, "Missing flat field spectra frame!");
00938
00939 giraffe_flat_config_destroy(flat_config);
00940
00941 giraffe_extraction_destroy(extraction);
00942 giraffe_localization_destroy(localization);
00943
00944 giraffe_table_delete(wcalcoeff);
00945
00946 giraffe_table_delete(grating);
00947 giraffe_table_delete(fibers);
00948
00949 return 1;
00950 }
00951
00952 filename = cpl_frame_get_filename(flat_frame);
00953
00954 flat = giraffe_image_new(CPL_TYPE_DOUBLE);
00955 status = giraffe_image_load(flat, filename, 0);
00956
00957 if (status) {
00958 cpl_msg_error(_id, "Cannot load flat field spectra from '%s'. "
00959 "Aborting ...", filename);
00960
00961 giraffe_image_delete(flat);
00962
00963 giraffe_flat_config_destroy(flat_config);
00964
00965 giraffe_extraction_destroy(extraction);
00966 giraffe_localization_destroy(localization);
00967
00968 giraffe_table_delete(wcalcoeff);
00969
00970 giraffe_table_delete(grating);
00971 giraffe_table_delete(fibers);
00972
00973 return 1;
00974 }
00975
00976 if (flat_config->apply == TRUE) {
00977
00978 cpl_msg_info(_id, "Applying flat field correction ...");
00979
00980 status = giraffe_flat_apply(extraction, fibers, flat, flat_config);
00981
00982 if (status) {
00983 cpl_msg_error(_id, "Flat field correction failed! "
00984 "Aborting ...");
00985
00986 giraffe_image_delete(flat);
00987
00988 giraffe_flat_config_destroy(flat_config);
00989
00990 giraffe_extraction_destroy(extraction);
00991 giraffe_localization_destroy(localization);
00992
00993 giraffe_table_delete(wcalcoeff);
00994
00995 giraffe_table_delete(grating);
00996 giraffe_table_delete(fibers);
00997
00998 return 1;
00999 }
01000
01001 }
01002
01003 if (flat_config->transmission == TRUE) {
01004
01005 const cxchar* _filename = cpl_frame_get_filename(flat_frame);
01006
01007 GiTable* _fibers = NULL;
01008
01009
01010 cpl_msg_info(_id, "Loading fiber setup for frame '%s'.",
01011 _filename);
01012
01013 _fibers = giraffe_fiberlist_load(_filename, 1, "FIBER_SETUP");
01014
01015 if (!_fibers) {
01016 cpl_msg_error(_id, "Cannot create fiber setup for "
01017 "frame '%s'! Aborting ...", _filename);
01018
01019 giraffe_image_delete(flat);
01020
01021 giraffe_flat_config_destroy(flat_config);
01022
01023 giraffe_extraction_destroy(extraction);
01024 giraffe_localization_destroy(localization);
01025
01026 giraffe_table_delete(wcalcoeff);
01027
01028 giraffe_table_delete(grating);
01029 giraffe_table_delete(fibers);
01030
01031 return 1;
01032 }
01033
01034 cpl_msg_info(_id, "Applying relative fiber transmission "
01035 "correction");
01036
01037 status = giraffe_transmission_setup(fibers, _fibers);
01038 giraffe_table_delete(_fibers);
01039
01040 if (status == 0) {
01041 status = giraffe_transmission_apply(extraction, fibers);
01042 }
01043
01044 if (status) {
01045
01046 cpl_msg_error(_id, "Relative transmission correction failed! "
01047 "Aborting ...");
01048
01049 giraffe_image_delete(flat);
01050
01051 giraffe_flat_config_destroy(flat_config);
01052
01053 giraffe_extraction_destroy(extraction);
01054 giraffe_localization_destroy(localization);
01055
01056 giraffe_table_delete(wcalcoeff);
01057
01058 giraffe_table_delete(grating);
01059 giraffe_table_delete(fibers);
01060
01061 return 1;
01062
01063 }
01064
01065 }
01066
01067 giraffe_image_delete(flat);
01068
01069 }
01070
01071 giraffe_flat_config_destroy(flat_config);
01072
01073
01074
01075
01076
01077
01078
01079 cpl_msg_info(_id, "Writing extracted spectra ...");
01080
01081
01082
01083 giraffe_image_add_info(extraction->spectra, &info, set);
01084
01085 sext_frame = giraffe_frame_create_image(extraction->spectra,
01086 GIFRAME_STANDARD_EXTSPECTRA,
01087 CPL_FRAME_LEVEL_FINAL,
01088 TRUE, TRUE);
01089
01090 if (sext_frame == NULL) {
01091 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
01092
01093 giraffe_extraction_destroy(extraction);
01094 giraffe_localization_destroy(localization);
01095
01096 giraffe_table_delete(wcalcoeff);
01097
01098 giraffe_table_delete(grating);
01099 giraffe_table_delete(fibers);
01100
01101 return 1;
01102 }
01103
01104 status = giraffe_fiberlist_attach(sext_frame, fibers);
01105
01106 if (status) {
01107 cpl_msg_error(_id, "Cannot attach fiber setup to local file '%s'! "
01108 "Aborting ...", cpl_frame_get_filename(sext_frame));
01109
01110 cpl_frame_delete(sext_frame);
01111
01112 giraffe_extraction_destroy(extraction);
01113 giraffe_localization_destroy(localization);
01114
01115 giraffe_table_delete(wcalcoeff);
01116
01117 giraffe_table_delete(grating);
01118 giraffe_table_delete(fibers);
01119
01120 return 1;
01121 }
01122
01123 cpl_frameset_insert(set, sext_frame);
01124
01125
01126
01127 giraffe_image_add_info(extraction->error, &info, set);
01128
01129 sext_frame = giraffe_frame_create_image(extraction->error,
01130 GIFRAME_STANDARD_EXTERRORS,
01131 CPL_FRAME_LEVEL_FINAL,
01132 TRUE, TRUE);
01133
01134 if (sext_frame == NULL) {
01135 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
01136
01137 giraffe_extraction_destroy(extraction);
01138 giraffe_localization_destroy(localization);
01139
01140 giraffe_table_delete(wcalcoeff);
01141
01142 giraffe_table_delete(grating);
01143 giraffe_table_delete(fibers);
01144
01145 return 1;
01146 }
01147
01148 status = giraffe_fiberlist_attach(sext_frame, fibers);
01149
01150 if (status) {
01151 cpl_msg_error(_id, "Cannot attach fiber setup to local file '%s'! "
01152 "Aborting ...", cpl_frame_get_filename(sext_frame));
01153
01154 cpl_frame_delete(sext_frame);
01155
01156 giraffe_extraction_destroy(extraction);
01157 giraffe_localization_destroy(localization);
01158
01159 giraffe_table_delete(wcalcoeff);
01160
01161 giraffe_table_delete(grating);
01162 giraffe_table_delete(fibers);
01163
01164 return 1;
01165 }
01166
01167 cpl_frameset_insert(set, sext_frame);
01168
01169
01170
01171 if (extraction->npixels != NULL) {
01172
01173 giraffe_image_add_info(extraction->npixels, &info, set);
01174
01175 sext_frame = giraffe_frame_create_image(extraction->npixels,
01176 GIFRAME_STANDARD_EXTPIXELS,
01177 CPL_FRAME_LEVEL_FINAL,
01178 TRUE, TRUE);
01179
01180 if (sext_frame == NULL) {
01181 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
01182
01183 giraffe_extraction_destroy(extraction);
01184 giraffe_localization_destroy(localization);
01185
01186 giraffe_table_delete(wcalcoeff);
01187
01188 giraffe_table_delete(grating);
01189 giraffe_table_delete(fibers);
01190
01191 return 1;
01192 }
01193
01194 status = giraffe_fiberlist_attach(sext_frame, fibers);
01195
01196 if (status) {
01197 cpl_msg_error(_id, "Cannot attach fiber setup to local file '%s'! "
01198 "Aborting ...", cpl_frame_get_filename(sext_frame));
01199
01200 cpl_frame_delete(sext_frame);
01201
01202 giraffe_extraction_destroy(extraction);
01203 giraffe_localization_destroy(localization);
01204
01205 giraffe_table_delete(wcalcoeff);
01206
01207 giraffe_table_delete(grating);
01208 giraffe_table_delete(fibers);
01209
01210 return 1;
01211 }
01212
01213 cpl_frameset_insert(set, sext_frame);
01214
01215 }
01216
01217
01218
01219 giraffe_image_add_info(extraction->centroid, &info, set);
01220
01221 sext_frame = giraffe_frame_create_image(extraction->centroid,
01222 GIFRAME_STANDARD_EXTTRACE,
01223 CPL_FRAME_LEVEL_FINAL,
01224 TRUE, TRUE);
01225
01226 if (sext_frame == NULL) {
01227 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
01228
01229 giraffe_extraction_destroy(extraction);
01230 giraffe_localization_destroy(localization);
01231
01232 giraffe_table_delete(wcalcoeff);
01233
01234 giraffe_table_delete(grating);
01235 giraffe_table_delete(fibers);
01236
01237 return 1;
01238 }
01239
01240 status = giraffe_fiberlist_attach(sext_frame, fibers);
01241
01242 if (status) {
01243 cpl_msg_error(_id, "Cannot attach fiber setup to local file '%s'! "
01244 "Aborting ...", cpl_frame_get_filename(sext_frame));
01245
01246 cpl_frame_delete(sext_frame);
01247
01248 giraffe_extraction_destroy(extraction);
01249 giraffe_localization_destroy(localization);
01250
01251 giraffe_table_delete(wcalcoeff);
01252
01253 giraffe_table_delete(grating);
01254 giraffe_table_delete(fibers);
01255
01256 return 1;
01257 }
01258
01259 cpl_frameset_insert(set, sext_frame);
01260
01261
01262
01263 if (extraction->model != NULL) {
01264
01265 giraffe_image_add_info(extraction->model, &info, set);
01266
01267 sext_frame = giraffe_frame_create_image(extraction->model,
01268 GIFRAME_FIBER_FLAT_EXTMODEL,
01269 CPL_FRAME_LEVEL_FINAL,
01270 TRUE, TRUE);
01271
01272 if (sext_frame == NULL) {
01273 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
01274
01275 giraffe_extraction_destroy(extraction);
01276 giraffe_localization_destroy(localization);
01277
01278 giraffe_table_delete(wcalcoeff);
01279
01280 giraffe_table_delete(grating);
01281 giraffe_table_delete(fibers);
01282
01283 return 1;
01284 }
01285
01286 status = giraffe_fiberlist_attach(sext_frame, fibers);
01287
01288 if (status != 0) {
01289 cpl_msg_error(_id, "Cannot attach fiber setup to local file '%s'! "
01290 "Aborting ...", cpl_frame_get_filename(sext_frame));
01291
01292 cpl_frame_delete(sext_frame);
01293
01294 giraffe_extraction_destroy(extraction);
01295 giraffe_localization_destroy(localization);
01296
01297 giraffe_table_delete(wcalcoeff);
01298
01299 giraffe_table_delete(grating);
01300 giraffe_table_delete(fibers);
01301
01302 return 1;
01303 }
01304
01305 cpl_frameset_insert(set, sext_frame);
01306
01307 }
01308
01309
01310
01311
01312
01313
01314
01315 filename = (cxchar *)cpl_frame_get_filename(wcal_frame);
01316
01317 wcalcoeff = giraffe_table_new();
01318 status = giraffe_table_load(wcalcoeff, filename, 1, NULL);
01319
01320 if (status) {
01321 cpl_msg_error(_id, "Cannot load dispersion solution from "
01322 "'%s'. Aborting ...", filename);
01323
01324 giraffe_extraction_destroy(extraction);
01325 giraffe_localization_destroy(localization);
01326
01327 giraffe_table_delete(wcalcoeff);
01328
01329 giraffe_table_delete(grating);
01330 giraffe_table_delete(fibers);
01331
01332 return 1;
01333 }
01334
01335
01336
01337
01338
01339
01340 filename = (cxchar *)cpl_frame_get_filename(grating_frame);
01341
01342 status = 0;
01343
01344 grating = giraffe_table_new();
01345 status = giraffe_table_load(grating, filename, 1, NULL);
01346
01347 if (status) {
01348 cpl_msg_error(_id, "Cannot load grating data from '%s'. "
01349 "Aborting ...", filename);
01350
01351 giraffe_extraction_destroy(extraction);
01352 giraffe_localization_destroy(localization);
01353
01354 giraffe_table_delete(wcalcoeff);
01355
01356 giraffe_table_delete(grating);
01357 giraffe_table_delete(fibers);
01358
01359 return 1;
01360 }
01361
01362
01363
01364
01365
01366
01367
01368 filename = (cxchar *)cpl_frame_get_filename(slit_frame);
01369
01370 slitgeometry = giraffe_slitgeometry_load(fibers, filename, 1, NULL);
01371
01372 if (slitgeometry == NULL) {
01373 cpl_msg_error(_id, "Cannot load slit geometry data from '%s'. "
01374 "Aborting ...", filename);
01375
01376 giraffe_table_delete(wcalcoeff);
01377
01378 giraffe_extraction_destroy(extraction);
01379 giraffe_localization_destroy(localization);
01380
01381 giraffe_table_delete(wcalcoeff);
01382
01383 giraffe_table_delete(grating);
01384 giraffe_table_delete(fibers);
01385
01386 return 1;
01387 }
01388 else {
01389
01390
01391
01392
01393
01394
01395
01396 if (giraffe_fiberlist_compare(slitgeometry, fibers) != 1) {
01397 cpl_msg_error(_id, "Slit geometry data from '%s' is not "
01398 "applicable for current fiber setup! "
01399 "Aborting ...", filename);
01400
01401 giraffe_table_delete(slitgeometry);
01402 giraffe_table_delete(wcalcoeff);
01403
01404 giraffe_extraction_destroy(extraction);
01405 giraffe_localization_destroy(localization);
01406
01407 giraffe_table_delete(wcalcoeff);
01408
01409 giraffe_table_delete(grating);
01410 giraffe_table_delete(fibers);
01411
01412 return 1;
01413 }
01414
01415 }
01416
01417
01418
01419
01420
01421
01422
01423 cpl_msg_info(_id, "Spectrum rebinning");
01424
01425 rebin_config = giraffe_rebin_config_create(config);
01426
01427 rebinning = giraffe_rebinning_new();
01428
01429 status = 0;
01430
01431 status = giraffe_rebin_spectra(rebinning, extraction, fibers,
01432 localization, grating, slitgeometry,
01433 wcalcoeff, rebin_config);
01434
01435 if (status) {
01436 cpl_msg_error(_id, "Rebinning of standard spectra failed! "
01437 "Aborting...");
01438
01439 giraffe_rebinning_destroy(rebinning);
01440
01441 giraffe_extraction_destroy(extraction);
01442 giraffe_localization_destroy(localization);
01443
01444 giraffe_table_delete(wcalcoeff);
01445
01446 giraffe_table_delete(slitgeometry);
01447 giraffe_table_delete(grating);
01448 giraffe_table_delete(fibers);
01449
01450 giraffe_rebin_config_destroy(rebin_config);
01451
01452 return 1;
01453
01454 }
01455
01456 giraffe_extraction_destroy(extraction);
01457 extraction = NULL;
01458
01459 giraffe_localization_destroy(localization);
01460 localization = NULL;
01461
01462 giraffe_rebin_config_destroy(rebin_config);
01463 rebin_config = NULL;
01464
01465
01466
01467
01468
01469
01470
01471
01472 giraffe_image_add_info(rebinning->spectra, &info, set);
01473
01474 rbin_frame = giraffe_frame_create_image(rebinning->spectra,
01475 GIFRAME_STANDARD_RBNSPECTRA,
01476 CPL_FRAME_LEVEL_FINAL,
01477 TRUE, TRUE);
01478
01479 if (rbin_frame == NULL) {
01480 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
01481
01482 giraffe_rebinning_destroy(rebinning);
01483
01484 giraffe_table_delete(wcalcoeff);
01485
01486 giraffe_table_delete(slitgeometry);
01487 giraffe_table_delete(grating);
01488 giraffe_table_delete(fibers);
01489
01490 return 1;
01491 }
01492
01493 status = giraffe_fiberlist_attach(rbin_frame, fibers);
01494
01495 if (status) {
01496 cpl_msg_error(_id, "Cannot attach fiber setup to local "
01497 "file '%s'! Aborting ...",
01498 cpl_frame_get_filename(rbin_frame));
01499
01500 giraffe_rebinning_destroy(rebinning);
01501 giraffe_table_delete(wcalcoeff);
01502
01503 giraffe_table_delete(slitgeometry);
01504 giraffe_table_delete(grating);
01505 giraffe_table_delete(fibers);
01506
01507 cpl_frame_delete(rbin_frame);
01508
01509 return 1;
01510 }
01511
01512 cpl_frameset_insert(set, rbin_frame);
01513
01514
01515
01516 giraffe_image_add_info(rebinning->errors, &info, set);
01517
01518 rbin_frame = giraffe_frame_create_image(rebinning->errors,
01519 GIFRAME_STANDARD_RBNERRORS,
01520 CPL_FRAME_LEVEL_FINAL,
01521 TRUE, TRUE);
01522
01523 if (rbin_frame == NULL) {
01524 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
01525
01526 giraffe_rebinning_destroy(rebinning);
01527
01528 giraffe_table_delete(wcalcoeff);
01529
01530 giraffe_table_delete(slitgeometry);
01531 giraffe_table_delete(grating);
01532 giraffe_table_delete(fibers);
01533
01534 return 1;
01535 }
01536
01537 status = giraffe_fiberlist_attach(rbin_frame, fibers);
01538
01539 if (status) {
01540 cpl_msg_error(_id, "Cannot attach fiber setup to local "
01541 "file '%s'! Aborting ...",
01542 cpl_frame_get_filename(rbin_frame));
01543
01544 giraffe_rebinning_destroy(rebinning);
01545
01546 giraffe_table_delete(wcalcoeff);
01547
01548 giraffe_table_delete(slitgeometry);
01549 giraffe_table_delete(grating);
01550 giraffe_table_delete(fibers);
01551
01552 cpl_frame_delete(rbin_frame);
01553
01554 return 1;
01555 }
01556
01557 cpl_frameset_insert(set, rbin_frame);
01558
01559
01560
01561
01562
01563
01564 properties = giraffe_image_get_properties(rebinning->spectra);
01565 mode = giraffe_get_mode(properties);
01566
01567
01568 if (mode == GIMODE_IFU || mode == GIMODE_ARGUS) {
01569
01570 cpl_frame* rimg_frame = NULL;
01571
01572 GiReconstruction* reconstruction = NULL;
01573
01574 GiReconstructConfig* reconstruct_config = NULL;
01575
01576
01577 reconstruct_config = giraffe_reconstruct_config_create(config);
01578
01579 cpl_msg_info(_id, "Reconstructing image and data cube from rebinned "
01580 "spectra ...");
01581
01582 reconstruction = giraffe_reconstruction_new();
01583
01584 status = giraffe_reconstruction_build(reconstruction, rebinning,
01585 fibers, wcalcoeff,
01586 grating, slitgeometry,
01587 reconstruct_config);
01588
01589 if (status) {
01590
01591 if (status == -2) {
01592 cpl_msg_warning(_id, "No reconstructed image was built. "
01593 "Fiber list has no fiber position "
01594 "information.");
01595 }
01596 else {
01597 cpl_msg_error(_id, "Image reconstruction failed! Aborting...");
01598
01599 giraffe_reconstruction_destroy(reconstruction);
01600 giraffe_rebinning_destroy(rebinning);
01601
01602 giraffe_table_delete(wcalcoeff);
01603
01604 giraffe_table_delete(slitgeometry);
01605 giraffe_table_delete(grating);
01606 giraffe_table_delete(fibers);
01607
01608 giraffe_reconstruct_config_destroy(reconstruct_config);
01609
01610 return 1;
01611 }
01612
01613 }
01614
01615 giraffe_reconstruct_config_destroy(reconstruct_config);
01616
01617
01618
01619
01620
01621
01622
01623
01624 giraffe_image_add_info(reconstruction->spectra, &info, set);
01625
01626 rimg_frame = giraffe_frame_create_image(reconstruction->spectra,
01627 GIFRAME_STANDARD_RCSPECTRA,
01628 CPL_FRAME_LEVEL_FINAL,
01629 TRUE, TRUE);
01630
01631 if (rimg_frame == NULL) {
01632 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
01633
01634 giraffe_reconstruction_destroy(reconstruction);
01635 giraffe_rebinning_destroy(rebinning);
01636
01637 giraffe_table_delete(wcalcoeff);
01638
01639 giraffe_table_delete(slitgeometry);
01640 giraffe_table_delete(grating);
01641 giraffe_table_delete(fibers);
01642
01643 return 1;
01644 }
01645
01646 cpl_frameset_insert(set, rimg_frame);
01647
01648
01649
01650 giraffe_image_add_info(reconstruction->errors, &info, set);
01651
01652 rimg_frame = giraffe_frame_create_image(reconstruction->errors,
01653 GIFRAME_STANDARD_RCERRORS,
01654 CPL_FRAME_LEVEL_FINAL,
01655 TRUE, TRUE);
01656
01657 if (rimg_frame == NULL) {
01658 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
01659
01660 giraffe_reconstruction_destroy(reconstruction);
01661 giraffe_rebinning_destroy(rebinning);
01662
01663 giraffe_table_delete(wcalcoeff);
01664
01665 giraffe_table_delete(slitgeometry);
01666 giraffe_table_delete(grating);
01667 giraffe_table_delete(fibers);
01668
01669 return 1;
01670 }
01671
01672 cpl_frameset_insert(set, rimg_frame);
01673
01674
01675
01676 if (reconstruction->cube_spectra != NULL) {
01677
01678 GiFrameCreator creator = (GiFrameCreator) giraffe_cube_save;
01679
01680 properties = giraffe_image_get_properties(rebinning->spectra);
01681
01682 rimg_frame = giraffe_frame_create(GIFRAME_STANDARD_CUBE_SPECTRA,
01683 CPL_FRAME_LEVEL_FINAL,
01684 properties,
01685 reconstruction->cube_spectra,
01686 NULL,
01687 creator);
01688
01689 if (rimg_frame == NULL) {
01690 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
01691
01692 giraffe_reconstruction_destroy(reconstruction);
01693 reconstruction = NULL;
01694
01695 giraffe_rebinning_destroy(rebinning);
01696 rebinning = NULL;
01697
01698 giraffe_table_delete(wcalcoeff);
01699 wcalcoeff = NULL;
01700
01701 giraffe_table_delete(slitgeometry);
01702 slitgeometry = NULL;
01703
01704 giraffe_table_delete(grating);
01705 grating = NULL;
01706
01707 giraffe_table_delete(fibers);
01708 fibers = NULL;
01709
01710 return 1;
01711 }
01712
01713 status = giraffe_fiberlist_attach(rimg_frame, fibers);
01714
01715 if (status != 0) {
01716 cpl_msg_error(_id, "Cannot attach fiber setup to local "
01717 "file '%s'! Aborting ...",
01718 cpl_frame_get_filename(rimg_frame));
01719
01720 cpl_frame_delete(rimg_frame);
01721
01722 giraffe_reconstruction_destroy(reconstruction);
01723 reconstruction = NULL;
01724
01725 giraffe_rebinning_destroy(rebinning);
01726 rebinning = NULL;
01727
01728 giraffe_table_delete(wcalcoeff);
01729 wcalcoeff = NULL;
01730
01731 giraffe_table_delete(slitgeometry);
01732 slitgeometry = NULL;
01733
01734 giraffe_table_delete(grating);
01735 grating = NULL;
01736
01737 giraffe_table_delete(fibers);
01738 fibers = NULL;
01739
01740 return 1;
01741 }
01742
01743 cpl_frameset_insert(set, rimg_frame);
01744
01745 }
01746
01747
01748
01749 if (reconstruction->cube_errors != NULL) {
01750
01751 GiFrameCreator creator = (GiFrameCreator) giraffe_cube_save;
01752
01753 properties = giraffe_image_get_properties(rebinning->errors);
01754
01755 rimg_frame = giraffe_frame_create(GIFRAME_STANDARD_CUBE_ERRORS,
01756 CPL_FRAME_LEVEL_FINAL,
01757 properties,
01758 reconstruction->cube_errors,
01759 NULL,
01760 creator);
01761
01762 if (rimg_frame == NULL) {
01763 cpl_msg_error(_id, "Cannot create local file! Aborting ...");
01764
01765 giraffe_reconstruction_destroy(reconstruction);
01766 reconstruction = NULL;
01767
01768 giraffe_rebinning_destroy(rebinning);
01769 rebinning = NULL;
01770
01771 giraffe_table_delete(wcalcoeff);
01772 wcalcoeff = NULL;
01773
01774 giraffe_table_delete(slitgeometry);
01775 slitgeometry = NULL;
01776
01777 giraffe_table_delete(grating);
01778 grating = NULL;
01779
01780 giraffe_table_delete(fibers);
01781 fibers = NULL;
01782
01783 return 1;
01784 }
01785
01786 status = giraffe_fiberlist_attach(rimg_frame, fibers);
01787
01788 if (status != 0) {
01789 cpl_msg_error(_id, "Cannot attach fiber setup to local "
01790 "file '%s'! Aborting ...",
01791 cpl_frame_get_filename(rimg_frame));
01792
01793 cpl_frame_delete(rimg_frame);
01794
01795 giraffe_reconstruction_destroy(reconstruction);
01796 reconstruction = NULL;
01797
01798 giraffe_rebinning_destroy(rebinning);
01799 rebinning = NULL;
01800
01801 giraffe_table_delete(wcalcoeff);
01802 wcalcoeff = NULL;
01803
01804 giraffe_table_delete(slitgeometry);
01805 slitgeometry = NULL;
01806
01807 giraffe_table_delete(grating);
01808 grating = NULL;
01809
01810 giraffe_table_delete(fibers);
01811 fibers = NULL;
01812
01813 return 1;
01814 }
01815
01816 cpl_frameset_insert(set, rimg_frame);
01817 }
01818
01819 giraffe_reconstruction_destroy(reconstruction);
01820
01821 }
01822
01823
01824
01825
01826
01827
01828
01829 giraffe_table_delete(wcalcoeff);
01830
01831 giraffe_table_delete(slitgeometry);
01832 giraffe_table_delete(grating);
01833 giraffe_table_delete(fibers);
01834
01835 giraffe_rebinning_destroy(rebinning);
01836
01837 return 0;
01838
01839 }
01840
01841
01842
01843
01844
01845
01846
01847 int
01848 cpl_plugin_get_info(cpl_pluginlist* list)
01849 {
01850
01851 cpl_recipe* recipe = cx_calloc(1, sizeof *recipe);
01852 cpl_plugin* plugin = &recipe->interface;
01853
01854
01855 cpl_plugin_init(plugin,
01856 CPL_PLUGIN_API,
01857 GIRAFFE_BINARY_VERSION,
01858 CPL_PLUGIN_TYPE_RECIPE,
01859 "gistandard",
01860 "Process a spectro-photometric standard star "
01861 "observation. The response curve computation is "
01862 "not included!",
01863 "For detailed information please refer to the "
01864 "GIRAFFE pipeline user manual.\nIt is available at "
01865 "http://www.eso.org/pipelines.",
01866 "Giraffe Pipeline",
01867 PACKAGE_BUGREPORT,
01868 giraffe_get_license(),
01869 gistandard_create,
01870 gistandard_exec,
01871 gistandard_destroy);
01872
01873 cpl_pluginlist_append(list, plugin);
01874
01875 return 0;
01876
01877 }